Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4556 Albom 1
 
2
3
 
4
{
5
int i, x, y, z;
6
int x1, y1;
7
8
 
9
	for (y = 0; y < 8; y++)
10
		for (z = 0; z < 4; z++)
11
			board[x][y][z] = 0;
12
13
 
14
	board[rand()%8][rand()%8][LAY_HIDDEN] = 1;
15
16
 
17
for (x = 0; x < 8; x++)
18
	for (y = 0; y < 8; y++)
19
		if (board[x][y][LAY_HIDDEN] == 1)
20
			foxN++;
21
22
 
23
	{
24
	init_board();
25
	return;
26
	}
27
28
 
29
for (x = 0; x < 8; x++)
30
	for (y = 0; y < 8; y++)
31
		{
32
33
 
34
			if (board[x1][y][LAY_HIDDEN] == 1)
35
				board[x][y][LAY_NUM]++;
36
37
 
38
 
39
			if (board[x][y1][LAY_HIDDEN] == 1)
40
				board[x][y][LAY_NUM]++;
41
42
 
43
 
44
			x1 = x-y;
45
		else
46
			x1 = 0;
47
48
 
49
			y1 = y-x;
50
		else
51
			y1 = 0;
52
53
 
54
			{
55
			if (board[x1][y1][LAY_HIDDEN] == 1)
56
				board[x][y][LAY_NUM]++;
57
			x1++;
58
			y1++;
59
			} while ((x1<8)&&(y1<8));
60
61
 
62
 
63
			x1 = x+y-7;
64
		else
65
			x1 = 0;
66
67
 
68
			y1 = x+y;
69
		else
70
			y1 = 7;
71
72
 
73
			{
74
			if (board[x1][y1][LAY_HIDDEN] == 1)
75
				board[x][y][LAY_NUM]++;
76
			x1++;
77
			y1--;
78
			} while ((x1<8)&&(y1>-1));
79
80
 
81
 
82
			board[x][y][LAY_NUM] -= 3;
83
84
 
85
86
 
87
moves = 0;
88
result = 0;
89
90
 
91
92
 
93
{
94
size = 20;
95
x_start = 5;
96
y_start = 30;
97
window_width = 2*x_start + 8*size + 9;
98
window_height = y_start + x_start + 8*size + kol_skin_height() + 9 + 14;
99
}
100
101
 
102
{
103
104
 
105
int x, y;
106
int x1, y1;
107
char tmp[64];
108
char tmp2[64];
109
110
 
111
112
 
113
114
 
115
kol_paint_string(x_start+20-12, x_start+5, "New", 0x902222ff);
116
117
 
118
itoa(foxLeft, tmp2);
119
strcat(tmp, tmp2);
120
strcat(tmp, "/4");
121
kol_paint_string(x_start+55, x_start+5, tmp, 0x902222ff);
122
123
 
124
itoa(moves, tmp2);
125
strcat(tmp, tmp2);
126
kol_paint_string(x_start+110, x_start+5, tmp, 0x902222ff);
127
128
 
129
	{
130
	kol_paint_line(x_start+i*size, y_start, x_start+i*size, y_start+8*size, 0x33); // vertical
131
	kol_paint_line(x_start, y_start+i*size, x_start+8*size, y_start+i*size, 0x33); // horizontal
132
	}
133
134
 
135
for (x1 = 0; x1 < 8; x1++)
136
	for (y1 = 0; y1 < 8; y1++)
137
		{
138
		if (board[x1][y1][LAY_FOUND]==1)
139
			{
140
			grid_to_pos(x1, y1, &x, &y);
141
			kol_paint_string(x+size/2-4, y+size/2-4, "F", 0x90227722);
142
			}
143
		}
144
145
 
146
for (x1 = 0; x1 < 8; x1++)
147
	for (y1 = 0; y1 < 8; y1++)
148
	{
149
	if (board[x1][y1][LAY_OPENED] == 1)
150
		{
151
		itoa(board[x1][y1][LAY_NUM], tmp);
152
		grid_to_pos(x1, y1, &x, &y);
153
		kol_paint_string(x+size/2-4, y+size/2-4, tmp, 0x902222ff);
154
		}
155
	}
156
157
 
158
	{
159
	char victory[]={"V I C T O R Y !"};
160
	kol_paint_string(window_width/2-7*8+4, window_height-14-kol_skin_height()-4, victory, 0x90227722);
161
	kol_paint_string(window_width/2-7*8+4-1, window_height-14-kol_skin_height()-4, victory, 0x90227722);
162
	kol_paint_string(window_width/2-7*8+4+1, window_height-14-kol_skin_height()-4, victory, 0x90227722);
163
	}
164
165
 
166
	{
167
168
 
169
	for (x1 = 0; x1 < 8; x1++)
170
		for (y1 = 0; y1 < 8; y1++)
171
			{
172
			if (board[x1][y1][LAY_HIDDEN]==1)
173
				{
174
				grid_to_pos(x1, y1, &x, &y);
175
				kol_paint_string(x+size/2-2, y+size/2-2, "F", 0x90ff2222);
176
				}
177
			}
178
179
 
180
	kol_paint_string(window_width/2-9*8+4, window_height-14-kol_skin_height()-4, game_over, 0x90ff2222);
181
	kol_paint_string(window_width/2-9*8+4-1, window_height-14-kol_skin_height()-4, game_over, 0x90ff2222);
182
	kol_paint_string(window_width/2-9*8+4+1, window_height-14-kol_skin_height()-4, game_over, 0x90ff2222);
183
	}
184
185
 
186
187
 
188
 
189
 
190
191
 
192
 
193
{
194
int x, y;
195
for (x = 0; x < 8; x++)
196
	for (y = 0; y < 8; y++)
197
		if (board[x][y][LAY_HIDDEN] != board[x][y][LAY_FOUND])
198
			return -1;
199
return 1;
200
}
201
202
 
203
 
204
{
205
*x = gx*size + x_start;
206
*y = gy*size + y_start;
207
}
208
209
 
210
 
211
{
212
213
 
214
*gy = (y - y_start)/size;
215
216
 
217
	return -1;
218
else
219
	return 1;
220
}
221
222
 
223
 
224
225
 
226
{
227
228
 
229
unsigned key;
230
unsigned btn;
231
unsigned pos, x, y;
232
int gx, gy;
233
234
 
235
 
236
237
 
238
init_grid_sizes();
239
init_board();
240
wnd_draw();
241
242
 
243
 
244
	{
245
	event = kol_event_wait();
246
247
 
248
		{
249
		case 1:
250
			wnd_draw();
251
			break;
252
253
 
254
			key = (kol_key_get() & 0xff00)>>8;
255
			break;
256
257
 
258
			switch ((kol_btn_get() & 0xff00)>>8)
259
				{
260
				case 1: // close button
261
					kol_exit();
262
				case 2: // 'new' button
263
					init_board();
264
					wnd_draw();
265
					break;
266
				}
267
			break;
268
269
 
270
			btn = kol_mouse_btn(); // read mouse button
271
			pos = kol_mouse_posw(); // read mouse position
272
			x = pos / 65536;
273
			y = pos % 65536;
274
			if (x > window_width)
275
				x=0;
276
			if (y > window_height)
277
				y=0;
278
279
 
280
				{
281
				switch (btn & 3)
282
					{
283
					case 1: // left button
284
						if (result == 0) // are we in game?
285
							{
286
							if (board[gx][gy][LAY_FOUND] == 0)
287
								{
288
								if ( board[gx][gy][LAY_OPENED] == 0 )
289
									board[gx][gy][LAY_OPENED] = 1;
290
								else
291
									board[gx][gy][LAY_OPENED] = 0;
292
								moves++;
293
								wnd_draw();
294
								}
295
							}
296
						break;
297
					case 2: // right button
298
						if (result == 0) // are we in game?
299
							{
300
							if (board[gx][gy][LAY_FOUND] == 0)
301
								{
302
								if ( board[gx][gy][LAY_OPENED] == 0 )
303
									{
304
									board[gx][gy][LAY_FOUND] = 1;
305
									foxLeft--;
306
									moves++;
307
									}
308
								}
309
							else
310
								{
311
								board[gx][gy][LAY_FOUND] = 0;
312
								foxLeft++;
313
								moves++;
314
								}
315
316
 
317
								result = check();
318
319
 
320
							}
321
						break;
322
					}
323
				}
324
				break;
325
		}
326
327
 
328
 
329
330
 
331
}
332
333
 
334
>