Assignment C++ Game
Assignment C++ Game
#include <iostream>
#include <Windows.h>
#include <cstdlib>
#include <ctime>
#include <conio.h>
using namespace std;
int main()
{
char map[25][25];
map[a][b+1] = obstacle;
map[a][b-1] = obstacle;
map[a+1][b-1] = obstacle;
map[a+1][b+1] = obstacle;
map[a-1][b-1] = obstacle;
map[a-1][b+1] = obstacle;
if(a > 20) {
a = 0;
b = rand() % 15 + 2;
}
//displays the map
for(int i=0; i < 20; ++i) {
for(int j=0; j < 20; ++j) {
cout << map[i][j];
if(j >= 19) {
cout << endl;
}
}
}
cout << "
map[y][x-1] = '|';
map[y+1][x-1] = 'o';
map[y+1][x+1] = 'o';
map[y-1][x-1] = 'o';
map[y-1][x+1] = 'o';
}
}
//checks if the car crashed
if(map[y-2][x] == obstacle || map[y-2][x-1] == obstacle || map[y-2][x+1] ==
obstacle) {
lost:
cout << "\n\nYou crashed!\n" << endl;
cin.get();
return 0;
}
//checks if the player picked up cash
if(map[y-2][x] == cash || map[y-2][x-1] == cash || map[y-2][x+1] == cash) {
map[y-2][x] = ' ';
map[y-2][x-1] = ' ';
map[y-2][x+1] = ' ';
++cashpickedup;
q = 0;
p = rand() % 15 + 2;
}
//generates the cash
else if(q > 20) {
q = 0;
p = rand() % 15 + 2;
}
//does so the cash doesnt appear next to the obstacle
if(a > 8) {
++cashcheck;
}
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
Position.X = 0;
Position.Y = 0;
SetConsoleCursorPosition(hOut, Position);