My Snake Game

This is my snake game. I made it about three months ago.

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
 #include<iostream>
#include<Windows.h>
#include<string>
#include<conio.h>
#include<fstream>
#include<ctime>
using namespace std;
int main()
{
	for (int i = 10; i > -1; i--)
	{
		cout << "Controls" << endl;
		cout << "w for up" << endl;
		cout << "s for down" << endl;
		cout << "a for left" << endl;
		cout << "d for right" << endl;
		cout << "Game starts in " << i << " seconds";
		Sleep(1000);
		system("cls");
	}
	srand(time(0));
	ifstream in;
	ofstream out;
	out.open("increase.txt");
	out << "";
	out.close();
	int score = 0;
	int fy, fx;
	int size = 7;
	int xc[10000], yc[10000];
	out.open("x.txt");
	for (int i = 36; i > 29; i--)
	{
		out << i << endl;
	}
	out.close();
	out.open("y.txt");
	for (int j = 0; j < size; j++)
	{
		out << "7" << endl;
	}
	out.close();
	in.open("x.txt");
	for (int i = 0; i < size; i++)
	{
		in >> xc[i];
	}
	in.close();
	in.open("y.txt");
	for (int i = 0; i < size; i++)
	{
		in >> yc[i];
	}
	in.close();
	char key, key2;
	key = 68;
	string x[15][70];
	for (int i = 0; i < 15; i++)
	{
		for (int j = 0; j < 70; j++)
		{
			x[i][j] = " ";
		}
	}
	for (int i = 0; i < size; i++)
	{
		x[yc[i]][xc[i]] = "o";
	}

	for (int i = 0; i < 15; i++)
	{
		for (int j = 0; j < 70; j++)
		{
			x[0][j] =  "*" ;
			x[i][0] =  "*" ;
			x[14][j] =  "*" ;
			x[i][69] =  "*" ;
		}
	}
	do
	{
		fy = rand() % 15;
		fx = rand() % 70;
	} while (x[fy][fx] == "*" || x[fy][fx] == "o");
	x[fy][fx] = "#";
	for (int i = 0; i < 15; i++)
	{
		for (int j = 0; j < 70; j++)
		{
			cout << x[i][j];
		}
		cout << endl;
	}
	cout << "SCORE:" << score;
	int p, q, r, s;
	r = -1;
	for (int lala = 0; lala >-1; lala++)
	{
		if (size != (score / 10) + 7)
		{
			p = size - 6;
			in.open("increase.txt");
			for (int i = 0; i < p; i++)
			{
				in >> r;
			}
			in.close();
		}
		//97 and 65 for a,115 and 83 for s,100 and 68 for d,119 and 87 for w
		if (_kbhit())
		{
			key2 = _getch();
			if (key2 == 97 || key2 == 65 || key2 == 115 || key2 == 83 || key2 == 100 || key2 == 68 || key2 == 119 || key2 == 87)
			{
				if (key2 == 97 || key2 == 65)
				{
					if (key != 100 && key != 68)
					{
						key = key2;
					}
				}
				if (key2 == 115 || key2 == 83)
				{
					if (key != 119 && key != 87)
					{
						key = key2;
					}
				}
				if (key2 == 100 || key2 == 68)
				{
					if (key != 97 && key != 65)
					{
						key = key2;
					}
				}
				if (key2 == 119 || key2 == 87)
				{
					if (key != 115 && key != 83)
					{
						key = key2;
					}
				}

			}
		}
		//97 and 65 for a,115 and 83 for s,100 and 68 for d,119 and 87 for w
		if (key == 68 || key == 100)
		{
			xc[0] = xc[0] + 1;
		}
		if (key == 97 || key == 65)
		{
			xc[0] = xc[0] - 1;
		}
		if (key == 115 || key == 83)
		{
			yc[0] = yc[0] + 1;
		}
		if (key == 119 || key == 87)
		{
			yc[0] = yc[0] - 1;
		}
		in.open("x.txt");
		for (int i = 1; i < size + 1; i++)
		{
			in >> xc[i];
		}
		in.close();
		in.open("y.txt");
		for (int i = 1; i < size + 1; i++)
		{
			in >> yc[i];
		}
		in.close();
		out.open("x.txt");
		for (int i = 0; i < size; i++)
		{
			out << xc[i] << endl;
		}
		out.close();
		out.open("y.txt");
		for (int i = 0; i < size; i++)
		{
			out << yc[i] << endl;
		}
		out.close();
		if (x[yc[0]][xc[0]] == "o" || x[yc[0]][xc[0]] == "*")
		{
			cout << "GAME OVER";
			break;
		}
		x[yc[0]][xc[0]] = "o";
		if (lala == r)
		{
			x[yc[size]][xc[size]] = "o";
			out.open("y.txt", ios::app);
			out << yc[size] << endl;
			out.close();
			out.open("x.txt", ios::app);
			out << xc[size] << endl;
			out.close();
			size = size + 1;
		}
		else
		{
			x[yc[size]][xc[size]] = " ";
		}

		if (x[fy][fx] == "o")
		{
			do
			{
				fy = rand() % 15;
				fx = rand() % 70;
			} while (x[fy][fx] == "*" || x[fy][fx] == "o");
			x[fy][fx] = "#";
			out.open("increase.txt", ios::app);
			out << lala + size << endl;
			out.close();
			score = score + 10;
		}
		system("cls");
		for (int i = 0; i < 15; i++)
		{
			for (int j = 0; j < 70; j++)
			{
				cout << x[i][j];
			}
			cout << endl;
		}
		cout << "SCORE:" << score << endl;
	}
	system("pause");
}
Good one but a bit hard on the eyes because of those flashing ;). BTW, this should be in the Lounge.
Topic archived. No new replies allowed.