Tron help

Write your question here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
  #include<iostream>
#include<string>
#include<conio.h>
#include<Windows.h>
#include<cstdlib>
#include<ctime>

using namespace std;

//declarations

const int ROWS = 23;
const int COLUMNS = 80;
const char playerStart = '#';
const char 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. ";
		return true;
	}
	
	if(board[compxCoord][compyCoord]!=' ')
	{
		cout << " Game over.  The PC has crashed. ";
		return true;
	}
	else
	{
		return false;
	}
}

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<unsigned int>(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?
1
2
3
4
5
6
7
8
do
{
	drawMap();
	playerMove();
	pcMove();
	gameMap();

} while  (!crashTest());
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. :(

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include<iostream>
#include<string>
#include<conio.h>
#include<Windows.h>
#include<cstdlib>
#include<ctime>

using namespace std;

//declarations

const int ROWS = 23;
const int COLUMNS = 80;
const char playerStart = '#';
const char 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. ";
		return true;
	}
	
	if(board[compxCoord][compyCoord]!=' ')
	{
		cout << " Game over.  The PC has crashed. ";
		return true;
	}
	else
	{
		return false;
	}
}

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 int gameMap(int playerLoc, int pcLoc);
		
};

main()
{

srand(static_cast<unsigned int>(time(0)));

instructions();
void beginningMap(char board[][80]);

do
	{
			void drawMap();
			int playerMove();
			int pcMove();
			void gameMap();
			
	}
while 
		(!crashTest());
	
}
you were supposed to remove void and ints in the last do-while loop..
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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145

#include<iostream>
#include<string>
#include<conio.h>
#include<Windows.h>
#include<cstdlib>
#include<ctime>

using namespace std;

//declarations

const int ROWS = 23;
const int COLUMNS = 80;
char playerStart = '#';
char 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. ";
		return true;
	}
	
	if(board[compxCoord][compyCoord]!=' ')
	{
		cout << " Game over.  The PC has crashed. ";
		return true;
	}
	else
	{
		return false;
	}
}

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 int gameMap(int playerLoc, int pcLoc);
		
};

main()
{

srand(static_cast<unsigned int>(time(0)));

instructions();
void beginningMap(char board[][80]);

do
	{
			
			gameMap();
			userMove();
			
			
			
	}
while 
		(!crashTest());
	
}
Topic archived. No new replies allowed.