Subversion Repositories Kolibri OS

Rev

Rev 7806 | Rev 7977 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6954 leency 1
/*
7613 leency 2
   Memory Blocks for KolibriOS v1.11
6954 leency 3
        Leency&Veliant Edition
7613 leency 4
              2008-2019
6954 leency 5
*/
6
 
7229 leency 7
#define MEMSIZE 4096 * 15
6954 leency 8
#include "..\lib\gui.h"
9
#include "..\lib\random.h"
10
 
7049 leency 11
#include "..\lib\obj\libio.h"
12
#include "..\lib\obj\libimg.h"
6954 leency 13
 
14
proc_info Form;
15
 
16
#ifndef AUTOBUILD
17
#include "lang.h--"
18
#endif
19
 
20
#define COLOR_CELL_BG 0xFFFfff
21
#define COLOR_CELL_BORDER 0x94AECE
22
#define CELL_SIZE 43
23
#define PANEL_Y CELL_SIZE+4*6 + 4
24
#define PANEL_H 36
25
 
26
#define strok 6      //cell count x
27
#define stolbcov 10  //cell count y
28
 
29
#ifdef LANG_RUS
7221 leency 30
	#define LABEL_NEW_GAME "Новая игра (F2)";
31
#else
6954 leency 32
	#define LABEL_NEW_GAME "New game (F2)";
33
#endif
34
 
35
int bitstat[60], bitpict[60];
36
dword butonsx[60], butonsy[60];
37
dword firstbit, secondbit;
7613 leency 38
int count;
6954 leency 39
 
40
 
41
void main()
42
{
43
	dword id;
44
	load_dll(libio,  #libio_init,1);
45
	load_dll(libimg, #libimg_init,1);
46
 
47
	Libimg_LoadImage(#skin, "/sys/icons32.png");
48
	Libimg_FillTransparent(skin.image, skin.w, skin.h, COLOR_CELL_BG);
49
 
50
	NewGame();
51
 
52
	loop() switch(WaitEvent())
53
	{
54
		case evKey:
55
			GetKeys();
56
		 	if (key_scancode==60) NewGame();
57
		 	break;
58
 
59
		case evButton:
7613 leency 60
			id = GetButtonID();
61
			if (id==1) ExitProcess();
62
			else if (id==5) NewGame();
63
			else {
64
					if (bitstat[id-100] == 0)
65
					{
66
						if (firstbit <> 0x0BAD)
6954 leency 67
						{
7613 leency 68
							if (secondbit <> 0x0BAD)
6954 leency 69
							{
7613 leency 70
								if (bitpict[firstbit-100] == bitpict[secondbit-100])
71
									bitstat[firstbit-100] = bitstat[secondbit-100] = 2;
72
								else
73
									bitstat[firstbit-100] = bitstat[secondbit-100] = 0;
74
								ReDraw_Game_Button(firstbit - 100);
75
								ReDraw_Game_Button(secondbit - 100);
76
								secondbit = 0x0BAD;
77
								firstbit = id;
78
								bitstat[id-100] = 1;
79
								ReDraw_Game_Button(id - 100);
80
								count++;
6954 leency 81
							}
7613 leency 82
							else if (firstbit<>id)
6954 leency 83
							{
7613 leency 84
								secondbit = id;
6954 leency 85
								bitstat[id-100] = 1;
86
								ReDraw_Game_Button(id - 100);
87
								count++;
88
							}
89
						}
7613 leency 90
						else
91
						{
92
							firstbit = id;
93
							bitstat[id-100] = 1;
94
							ReDraw_Game_Button(id - 100);
95
							count++;
96
						}
97
					}
98
					Draw_Count();
99
			}
100
			break;
6954 leency 101
 
102
		case evReDraw:
7806 leency 103
			sc.get();
7613 leency 104
			DefineAndDrawWindow(215,100,CELL_SIZE+4*10 + 4 + 9,PANEL_Y+4+PANEL_H+skin_height,
105
				0x34,0xC0C0C0,"Memory Blocks",0);
6954 leency 106
			GetProcessInfo(#Form, SelfInfo);
107
			Draw_Panel();
108
			Draw_Game_Pole();
109
			break;
110
	}
111
}
112
 
113
void NewGame()
114
{
115
	int off;
7613 leency 116
	int i;
6954 leency 117
 
118
	FOR (i = 0; i < 60; i++)
119
	{
7613 leency 120
		bitstat[i] = 0;
6954 leency 121
		bitpict[i] = 0;
122
	}
123
 
124
	count = 0;
125
	firstbit = secondbit = 0x0BAD;
126
	FOR (i = 0; i < 30; i++)
127
	{
128
		do off = random(60); while (bitpict[off] != 0);
129
		bitpict[off] = i;
130
		do off = random(60); while (bitpict[off] != 0);
131
		bitpict[off] = i;
132
	}
7613 leency 133
	Draw_Game_Pole();
134
	Draw_Panel();
6954 leency 135
}
136
 
137
void ReDraw_Game_Button(int id)
138
{
139
	DefineButton(butonsx[id], butonsy[id], CELL_SIZE, CELL_SIZE, 100 + id + BT_HIDE, 0);
140
	switch (bitstat[id])
141
	{
142
		case 0:
143
			Draw_Block(butonsx[id], butonsy[id]);
144
			break;
145
		case 1:
146
			Draw_Pressed_Block(butonsx[id], butonsy[id]);
147
			img_draw stdcall(skin.image, butonsx[id]+6, butonsy[id]+6, 32, 32, 0, bitpict[id]*32);
148
			BREAK;
149
		case 2:
150
			Draw_Open_Block(butonsx[id], butonsy[id]);
151
			img_draw stdcall(skin.image, butonsx[id]+6, butonsy[id]+6, 32, 32, 0, bitpict[id]*32);
152
			BREAK;
153
	}
154
}
155
 
156
void Draw_Game_Pole()
157
{
7613 leency 158
	int i;
6954 leency 159
	byte j;
160
	for (j = 0; j < stolbcov; j++)	for (i = 0; i < strok; i++)
161
	{
7613 leency 162
			butonsx[j*strok+i] = CELL_SIZE+4 * j + 4; //save coordinates to avoid
163
			butonsy[j*strok+i] = CELL_SIZE+4 * i + 4; //their recalculation after
6954 leency 164
			ReDraw_Game_Button(j*strok + i);
165
	}
166
}
167
 
168
void Draw_Block(dword x, y)
169
{
170
	DrawRectangle(x, y, CELL_SIZE, CELL_SIZE, COLOR_CELL_BORDER);//border
171
	DrawRectangle3D(x + 1, y + 1, CELL_SIZE-2, CELL_SIZE-2, 0xFFFFFF, 0xDEDEDE);//bump
172
	DrawBar(x + 2, y + 2, CELL_SIZE-3, CELL_SIZE-3, 0xBDC7D6);//background
173
}
174
 
175
void Draw_Open_Block(dword x, y)
176
{
177
	DrawRectangle(x, y, CELL_SIZE, CELL_SIZE, COLOR_CELL_BORDER);//border
178
	DrawBar(x + 1, y + 1, CELL_SIZE-1, CELL_SIZE-1, COLOR_CELL_BG);//background
179
}
180
 
181
void Draw_Pressed_Block(dword x, y)
182
{
183
	DrawRectangle(x, y, CELL_SIZE, CELL_SIZE, COLOR_CELL_BORDER);//border
184
	DrawWideRectangle(x + 1, y + 1, CELL_SIZE-1, CELL_SIZE-1, 2, 0x94DB00);//border green
185
	DrawBar(x + 3, y + 3, CELL_SIZE-5, CELL_SIZE-5, COLOR_CELL_BG);//background
186
}
187
 
188
void Draw_Panel()
189
{
7806 leency 190
	DrawBar(0, PANEL_Y, Form.cwidth, 1, sc.work_dark);
191
	DrawBar(0, PANEL_Y+1, Form.cwidth, 1, sc.work_light);
192
	DrawBar(0, PANEL_Y+2, Form.cwidth, PANEL_H-2, sc.work);
6954 leency 193
	DrawStandartCaptButton(9, PANEL_Y+5, 5, LABEL_NEW_GAME);
194
	Draw_Count();
195
}
196
 
197
void Draw_Count()
198
{
7806 leency 199
	DrawBar(Form.cwidth-32,PANEL_Y + 12,30,12,sc.work);
200
	WriteNumber(Form.cwidth-32, PANEL_Y + 12, 0x90, sc.work_text, 3, count);
6954 leency 201
}
202
 
203
 
204
 
205
 
206
stop: