SOSOS I can not find out what is wrong with my program!!!!!!

I can not for the life of me figure out what is wrong with this program.

This is meant to be an endless runner game modeled after the google T-Rex game.

When ever it I go to play it, it only runs void setup. I have no idea why.

Please Please tell me what is wrong and how to fix it!!

Thanks in advance!


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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#include <iostream>
#include <stdio.h>
#include <time.h>
#include <windows.h>
#include <conio.h>

using namespace std;



void gotoxy(int x, int y) {

	COORD point;
	point.X = x;
	point.Y = y;

	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), point);
}


void setup() {

	

	gotoxy(10, 2); // this places anything under it at the x and y value on the grid

	cout << "Press the a key to leave game. Press the space bar to jump." << endl;

	gotoxy(60, 5);

	cout << "SCORE: " << endl;

	gotoxy(1, 25);

	for (int x = 0; x < 79; x++);

	cout << "#" << endl;
}

int t;
int speed = 50;

void runner(int jump = 0) {

	static int v = 1;

	if (jump == 0) {
		t = 0;
	}

	else if (jump == 2) {
		t--;
	}

	else {
		t++;
	}

	gotoxy(3, 16 - t);

	cout << R"(                 )" << endl;

	gotoxy(3, 17 - t);

	cout << R"(    0000000      )" << endl;

	gotoxy(3, 18 - t);

	cout << R"(    0000000      )" << endl;

	gotoxy(3, 19 - t);

	cout << R"(    000000      )" << endl;

	gotoxy(3, 20 - t);

	cout << R"(    0000000      )" << endl;

	gotoxy(3, 21 - t);

	cout << R"(   00000000     )" << endl;  // lines 75-111 is the body of the runner

	gotoxy(3, 22 - t);

	cout << R"(   00000000     )" << endl;

	gotoxy(3, 23 - t);

	cout << R"(   000000000     )" << endl;

	gotoxy(3, 24 - t);

	cout << R"(   000000000     )" << endl;

	gotoxy(3, 25 - t);

	cout << R"(   00000000     )" << endl;

	if (jump == 1 || jump == 2) {

		cout << R"(    00 00       )" << endl; // this is what the legs will do while jumping

		gotoxy(3, 25 - t);

		cout << R"(    00   00      )" << endl;
	}

	else if (v == 1) {

		cout << R"(    0000  0000    )" << endl;

		gotoxy(3, 25 - t);

		cout << R"(      00         )" << endl;

		v = 2;
	}


	else if (v == 2) {

		cout << R"(     00 00      )" << endl; // this is what the legs will do when not jumping

		gotoxy(2, 24 - t);

		cout << R"(          00     )" << endl;

		v = 1;
	}

	gotoxy(3, 26 - t);

	if (jump != 0) {

		cout << R"(                 )" << endl;
	}

	else {

		cout << R"( ################################################################################################################### )" << endl; // this is the floor
	}

	
}


void box() {

	static int x = 0;
	static int score = 0;

	if (x == 56 && t < 4) {

		score = 0;

		speed = 50;

		gotoxy(36, 8);

		cout << "SORRY GAME OVER" << endl;

		_getch();

		gotoxy(36, 8);

		cout << "                 " << endl;
	}

	gotoxy(75 - x, 22);

	cout << " 000000 " << endl;

	gotoxy(75 - x, 23);

	cout << " 000000 " << endl; // lines 185-197 is the box

	gotoxy(75 - x, 24);

	cout << " 000000 " << endl;

	gotoxy(75 - x, 25);

	cout << " 000000 " << endl;

	x++;

	if (x == 73) {

		x = 0;

		score++;

		gotoxy(70, 2);

		cout << "                 " << endl;

		gotoxy(70, 2);

		cout << score << endl;

		if (speed > 20) {
			speed--;
		}
	}
}

int main() {

	char ch;

	int i;

	setup();

	while (true) {

		while (!_getch()) {

			runner();
			box();
		}

		ch = _getch();

		if (ch == '   ') {

			for (i = 0; i < 10; i++) {

				runner(1);
				box();
			}

			for (i = 0; i < 10; i++) {

				runner(2);
				box();
			}

		}

		else (ch == 'x');

	}


	return(0);

}
Line 225 if (ch == ' ') is wrong. ch should be an int and you can compare it only with a single char like ' '.
Topic archived. No new replies allowed.