Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
773 gluk 1
/*
2
   Memory Blocks for KolibriOS v1.01
3
             L&V Edition
4
 
5
	Идея и дизайн: Leency
6
	Реализовано: Veliant и Leency
7
          Compile with C--
8
		       2008
9
*/
10
 
11
#pragma option J0
12
#pragma option LST
13
#pragma option OC
14
#pragma option 4
15
#pragma option A
16
#include "kolibri.h--"
17
#include "random.h--"
18
#include "mbgraph.h--"
19
 
20
#define strok 6		//количество блоков по вертикали
21
#define stolbcov 10	//количество блоков по горизонтали
22
 
23
#define header "Memory Blocks L&V Edition"
24
 
25
char button_r 	= "Ќ®ў п ЁЈа (F2)"; //Новая игра
26
char tcount_r 	= " ‘зҐв:"; //Счёт
27
char lg_r			= "RU";
28
 
29
char button_e = "New  game (F2)";
30
char tcount_e = "Count:";
31
char lg_e			= "EN";
32
 
33
#define button	"Ќ®ў п ЁЈа (F2)"
34
#define tcount	" ‘зҐв:"
35
 
36
 
37
int lang = 0;
38
 
39
byte bitstat[60] = 0;
40
byte bitpict[60] = 0;
41
dword butonsx[60] = 0;
42
dword butonsy[60] = 0;
43
dword i, k, x, id, count = 0;
44
dword firstbit, secondbit;
45
 
46
void main()
47
{
48
	int z=1;
49
	int off;
50
	FOR (i = 0; i < 30; i++)
51
	{
52
		do
53
			off = random(60);
54
		while (bitpict[off] != 0);
55
		bitpict[off] = z;
56
		do
57
			off = random(60);
58
		while (bitpict[off] != 0);
59
		bitpict[off] = z;
60
		z++;
61
	}
62
	skin_width = GetSkinWidth();
63
	firstbit = secondbit = 0x0BAD;
64
	Draw_Window();
65
	loop()
66
	{
67
		switch (WaitEvent())
68
		{
69
			CASE evButton:
70
				id = GetButtonID();
71
				switch (id)
72
				{
73
					CASE 1:
74
						ExitProcess();
75
						break;
76
					CASE 5:
77
						init();
78
						break;
79
					CASE 6:
80
						SWITCH (lang)
81
						{
82
							CASE 0:
83
								copystr(#button_e, button);
84
								copystr(#tcount_e, tcount);
85
								lang = 1;
86
								break;
87
							CASE 1:
88
								copystr(#button_r, button);
89
								copystr(#tcount_r, tcount);
90
								lang = 0;
91
								break;
92
						}
93
						Draw_Panel();
94
						break;
95
					default:
96
						if (bitstat[id-100] == 0)
97
						{
98
							if (firstbit <> 0x0BAD)
99
							{
100
								if (secondbit <> 0x0BAD)
101
								{
102
									IF (bitpict[firstbit-100] == bitpict[secondbit-100])
103
									{
104
										bitstat[firstbit-100] = 2;
105
										bitstat[secondbit-100] = 2;
106
									}
107
									ELSE
108
									{
109
										bitstat[firstbit-100] = 0;
110
										bitstat[secondbit-100] = 0;
111
									}
112
									ReDraw_Game_Button(firstbit - 100);
113
									ReDraw_Game_Button(secondbit - 100);
114
									secondbit = 0x0BAD;
115
									firstbit = id;
116
									bitstat[id-100] = 1;
117
									ReDraw_Game_Button(id - 100);
118
									count++;
119
								}
120
								ELSE
121
								{
122
									IF (firstbit<>id)
123
									{
124
										secondbit = id;
125
										bitstat[id-100] = 1;
126
										ReDraw_Game_Button(id - 100);
127
										count++;
128
									}
129
								}
130
							}
131
							ELSE
132
							{
133
								firstbit = id;
134
								bitstat[id-100] = 1;
135
								ReDraw_Game_Button(id - 100);
136
								count++;
137
							}
138
						}
139
						Draw_Count();
140
						break;
141
				}
142
				break;
143
			case evKey:
144
				SWITCH (GetKey())
145
				{
146
					CASE 51:
147
						init();		//Нажата F2
148
						break;
149
				}
150
				break;
151
			case evReDraw:
152
				Draw_Window();
153
				break;
154
		}
155
	}
156
	ExitProcess();
157
}
158
 
159
void Draw_Window()
160
{
161
	begin_paint();
162
	DefineAndDrawWindow(100, 100, 434, 290 + skin_width + 1, 0x04, 0x00C0C0C0, 0, 0, 0);
163
	DrawTitle(header);
164
	Draw_Panel();
165
	Draw_Game_Pole();
166
 
167
	end_paint();
168
}
169
 
170
void init()
171
{
172
	int off, z;
173
	z=1;
174
	$mov	edi, #bitstat
175
	$mov	ecx, 60
176
	$xor	al, al
177
	$rep	$stosb			//стираем старые данные о нажатых кнопках
178
 
179
	$mov	edi, #bitpict
180
	$mov	ecx, 60
181
	$xor	al, al
182
	$rep	$stosb			//стираем старые данные о картинках
183
 
184
	count = 0;
185
	firstbit = secondbit = 0x0BAD;
186
	FOR (i = 0; i < 30; i++)
187
	{
188
		do
189
			off = random(60);
190
		while (bitpict[off] != 0);
191
		bitpict[off] = z;
192
		do
193
			off = random(60);
194
		while (bitpict[off] != 0);
195
		bitpict[off] = z;
196
		z++;
197
	}
198
	Draw_Game_Pole();
199
	Draw_Panel();
200
}
201
 
202
void ReDraw_Game_Button(int id)
203
{
204
	int off;
205
	DefineButton(0, 0, 0, 0, 100 + id + BT_DEL, 0);									//удаляем старую
206
	DefineButton(butonsx[id], butonsy[id], 38, 38, 100 + id + BT_HIDE, 0xEFEBEF);	//делаем новую
207
	switch (bitstat[id])
208
	{
209
		CASE 0:
210
			Draw_Block(butonsx[id], butonsy[id]);
211
			break;
212
		CASE 1:
213
			Draw_Pressed_Block(butonsx[id], butonsy[id]);
214
			PutImage(bitpict[id]-1*32*32*3+#data,32,32,butonsx[id]+3,butonsy[id]+3);
215
			break;
216
		case 2:
217
			Draw_Open_Block(butonsx[id], butonsy[id]);
218
			PutImage(bitpict[id]-1*32*32*3+#data,32,32,butonsx[id]+3,butonsy[id]+3);
219
			break;
220
	}
221
	//WriteText(butonsx[id] + 10, butonsy[id] + 10, 0x80, 0x000000, IntToStr(bitpict[id]), 0);
222
}
223
 
224
void Draw_Game_Pole()
225
{
226
	FOR (k = 0; k < stolbcov; k++)
227
	{
228
		FOR (i = 0; i < strok; i++)
229
		{
230
			butonsx[k*strok+i] = k * 42 + 4 + 5;		//сохраняем координаты чтоб не считать в дальнейшем
231
			butonsy[k*strok+i] = i * 42 + 4;
232
			ReDraw_Game_Button(k*strok + i);		//рисуем поле
233
		}
234
	}
235
}
236
 
237
void Draw_Block(dword x, y)
238
{
239
	DrawRegion(x, y, 38, 38, 0x0094AECE);//рамка
240
	DrawLine(x + 1*65536 + x + 37, y + skin_width + 1*65536 + y + skin_width + 1, 0x00FFFFFF);//белые линии
241
	DrawLine(x + 1*65536 + x + 1, y + skin_width + 1*65536 + y + skin_width + 36, 0x00FFFFFF);
242
	DrawLine(x + 1*65536 + x + 37, y + skin_width + 37*65536 + y + skin_width + 37, 0x00DEDEDE);//серые линии
243
	DrawLine(x + 37*65536 + x + 37, y + skin_width + 2*65536 + y + skin_width + 36, 0x00DEDEDE);
244
	DrawBar(x + 2, y + 2, 35, 35, 0x00BDC7D6);//фон
245
}
246
 
247
void Draw_Open_Block(dword x, y)
248
{
249
	DrawRegion(x,   y,   38, 38, 0x0094AECE);//рамка
250
	DrawBar(x + 1, y + 1, 37, 37, 0x00EFEBEF);//фон
251
}
252
 
253
void Draw_Pressed_Block(dword x, y)
254
{
255
	DrawRegion(x,   y,   38, 38, 0x0094AECE);//рамка
256
	DrawRegion(x + 1, y + 1, 36, 36, 0x0094DB00);//рамка зеленая
257
	DrawRegion(x + 2, y + 2, 34, 34, 0x0094DB00);//рамка зеленая
258
	DrawBar(x + 3, y + 3, 33, 33, 0x00EFEBEF);//фон
259
}
260
 
261
void Draw_Panel()
262
{
263
	DrawBar(5, 255, 425, 32, 0x00EBE7DB);//фон панели
264
	DrawLine(5*65536 + 429, 255 + skin_width*65536 + 255 + skin_width, 0x0094AECE);//линии
265
	DrawLine(5*65536 + 429, 256 + skin_width*65536 + 256 + skin_width, 0x00FFFFFF);//линии
266
 
267
	//Кнопка
268
	DrawFlatButton(4 + 5, 260, 107, 23, 5, 0x00EFEBEF);//новая игра
269
	DrawFlatButton(210 + 5, 260, 23, 23, 6, 0x00EFEBEF);//язык
270
	//надпись на кнопке
271
	WriteText(22, 268, 0x80, 0x000000, button, 0);
272
	//надпись "Счет"
273
	WriteText(150, 268, 0x80, 0x000000, tcount, 0);
274
	IF (lang==0)
275
		WriteText(221, 268, 0x80, 0x000000, #lg_e, 0);
276
	ELSE
277
		WriteText(221, 268, 0x80, 0x000000, #lg_r, 0);
278
	Draw_Count();
279
 
280
	//прямоугольники справа
281
	DrawBar(395 + 10, 260 + 5, 2, 2, 0x00BDCBDE);
282
	DrawBar(393 + 10, 265 + 5, 6, 6, 0x00BDCBDE);
283
	DrawBar(401 + 10, 270 + 5, 6, 6, 0x00BDCBDE);
284
	DrawBar(402 + 10, 257 + 5, 9, 8, 0x00D6D7CE);
285
}
286
 
287
void Draw_Count()
288
{
289
	EDI = 0x00EBE7DB;  //цвет панели
290
	WriteText(190, 268, 0xC0, 0x000000, IntToStr(count), 0);
291
}
292
 
293
stop: