#include<iostream>
#include<string>
#include<conio.h>
#include<Windows.h>
#include<cstdlib>
#include<ctime>
usingnamespace std;
//declarations
constint ROWS = 23;
constint COLUMNS = 80;
constchar playerStart = '#';
constchar compStart = '%';
int userxCoord = 0;
int useryCoord = 0;
int compxCoord = 0;
int compyCoord = 0;
char board[ROWS][COLUMNS];
//Functions
void instructions();
void beginningMap(void);
void drawMap(char board[0][80]);
void instructions()
{
cout << " Welcome to Tron Light Cycles" << endl;
cout << " Tron is a game based from a 80's movie with the same name " << endl;
cout << " The object is to drive your 'Light Cycle' and block your oppenent " << endl;
cout << " Use the i' j' k' l' for your up, down, left and right movements " << endl;
cout << " Enjoy the game. " << endl;
}
void beginningMap(char board[][80])
{
for (int i = 0; i < 23; i++)
{
for (int j = 0; j < 80; j++)
{
if (i==0 || i==23 || j==0 || j == 80)
{
board[i][j] = 'X';
}
else
{
board[i][j] = 'Q';
}
}
}
board [40][10] = playerStart;
board [40][70] = compStart;
}
int userMove()
{
if (_kbhit())
{
if (GetAsyncKeyState(0x49))
{
userxCoord++; useryCoord;
}
if (GetAsyncKeyState(0x4B))
{
userxCoord--; useryCoord;
}
if (GetAsyncKeyState(0x4A))
{
userxCoord; useryCoord--;
}
if (GetAsyncKeyState(0x4C))
{
userxCoord; useryCoord++;
}
}
}
bool crashTest()
{
if(board[userxCoord][useryCoord]!=' ')
{
cout << " Game over. You have crashed. ";
returntrue;
}
if(board[compxCoord][compyCoord]!=' ')
{
cout << " Game over. The PC has crashed. ";
returntrue;
}
else
{
returnfalse;
}
}
void gameMap()
{
board[userxCoord][useryCoord] = 'X';
board[compxCoord][compyCoord] = 'Q';
cout << board[userxCoord][useryCoord]<< board[compxCoord][compyCoord];
return;
}
class Location
{
public:
int playerLoc(int userxCoord,int useryCoord);
int pcLoc(int compxCoord,int compyCoord);
friend gameMap();
};
main()
{
srand(static_cast<unsignedint>(time(0)));
instructions();
beginningMap(board[][80]);
do
{
void drawMap();
int playerMove();
int pcMove();
void gameMap();
bool crashTest();
}
while
(crashTest() == 'false');
}
I figure I can use the class and friend feature to pass to my game map the updated locations for my characters but I am having trouble with it. I figure from reading the book if I return the user and pc x/y coord back to the game map it can then draw them through every iteration but so far it's not been successful. Ideas or thoughts?
Thanks I also fixed a few other compiling errors but now when I run it I get my instructions then goes right away to tell me I have crashed :( No map drawings and I don't get to move and I crash. :(
I changed a few things including removing the void and ints from the do while loop but it's not even drawing the map for me. This is the part that I am not understanding at all. I am pretty sure that I am supposed to return values for the functions so the program knows how to draw them but I can't figure out how.