Subversion Repositories Kolibri OS

Rev

Rev 7981 | Rev 7995 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7981 Rev 7982
1
/*
1
/*
2
   Memory Blocks for KolibriOS v1.2
2
   Memory Blocks for KolibriOS v1.2
3
        Leency&Veliant Edition
3
        Leency&Veliant Edition
4
              2008-2020
4
              2008-2020
5
*/
5
*/
6
 
6
 
7
#define MEMSIZE 1024 * 20
7
#define MEMSIZE 1024 * 20
-
 
8
#define ENTRY_POINT #main
-
 
9
 
8
#include "..\lib\gui.h"
10
#include "..\lib\gui.h"
9
#include "..\lib\random.h"
11
#include "..\lib\random.h"
10
 
12
 
11
#include "..\lib\obj\libio.h"
13
#include "..\lib\obj\libio.h"
12
#include "..\lib\obj\libimg.h"
14
#include "..\lib\obj\libimg.h"
13
 
15
 
14
#ifndef AUTOBUILD
16
#ifndef AUTOBUILD
15
#include "lang.h--"
17
#include "lang.h--"
16
#endif
18
#endif
17
 
19
 
18
#define BTN_CLOSED 0
20
#define BTN_CLOSED 0
19
#define BTN_PRESSED 1
21
#define BTN_PRESSED 1
20
#define BTN_OPEN 2
22
#define BTN_OPEN 2
21
 
23
 
22
#define CELL_SIZE 43
24
#define CELL_SIZE 43
23
#define PANEL_Y CELL_SIZE+4*6 + 4
25
#define PANEL_Y CELL_SIZE+4*6 + 4
24
#define PANEL_H 36
26
#define PANEL_H 36
25
#define WIN_W CELL_SIZE+4*10 + 4
27
#define WIN_W CELL_SIZE+4*10 + 4
26
#define WIN_H PANEL_Y+PANEL_H
28
#define WIN_H PANEL_Y+PANEL_H
27
 
29
 
28
#define ROWS 6
30
#define ROWS 6
29
#define COLS 10
31
#define COLS 10
30
#define COUNT ROWS*COLS
32
#define COUNT ROWS*COLS
31
 
33
 
32
#ifdef LANG_RUS
34
#ifdef LANG_RUS
33
	#define LABEL_NEW_GAME "®¢ ï ¨£à ";
35
	#define LABEL_NEW_GAME "®¢ ï ¨£à ";
34
#else
36
#else
35
	#define LABEL_NEW_GAME " New game";
37
	#define LABEL_NEW_GAME " New game";
36
#endif
38
#endif
37
 
39
 
38
int bitstat[COUNT], bitpict[COUNT];
40
int bitstat[COUNT], bitpict[COUNT];
39
dword butonsx[COUNT], butonsy[COUNT];
41
dword butonsx[COUNT], butonsy[COUNT];
40
dword firstbit, secondbit;
42
dword firstbit, secondbit;
41
int count;
43
int count;
42
 
44
 
43
 
45
 
44
void main()
46
void main()
45
{   
47
{   
46
	dword id;
48
	dword id;
47
	load_dll(libio,  #libio_init,1);
49
	load_dll(libio,  #libio_init,1);
48
	load_dll(libimg, #libimg_init,1);
50
	load_dll(libimg, #libimg_init,1);
49
 
51
 
50
	skin.load("/sys/icons32.png");
52
	skin.load("/sys/icons32.png");
51
	skin.replace_color(0x00000000, 0xFFFfff);
53
	skin.replace_color(0x00000000, 0xFFFfff);
52
 
54
 
53
	NewGame();
55
	NewGame();
54
 
56
 
55
	loop() switch(@WaitEvent())
57
	loop() switch(@WaitEvent())
56
	{
58
	{
57
		case evKey:
59
		case evKey:
58
			if (@GetKeyScancode()==SCAN_CODE_F2) NewGame();
60
			if (@GetKeyScancode()==SCAN_CODE_F2) NewGame();
59
			break;
61
			break;
60
			
62
			
61
		case evButton:
63
		case evButton:
62
			id = @GetButtonID();
64
			id = @GetButtonID();
63
			if (id==1) @ExitProcess();
65
			if (id==1) @ExitProcess();
64
			else if (id==5) NewGame();
66
			else if (id==5) NewGame();
65
			else {
67
			else {
66
					id -= 100;
68
					id -= 100;
67
					if (bitstat[id] == BTN_CLOSED)
69
					if (bitstat[id] == BTN_CLOSED)
68
					{
70
					{
69
						if (firstbit != 0x0BAD)
71
						if (firstbit != 0x0BAD)
70
						{
72
						{
71
							if (secondbit != 0x0BAD)
73
							if (secondbit != 0x0BAD)
72
							{
74
							{
73
								if (bitpict[firstbit] == bitpict[secondbit])
75
								if (bitpict[firstbit] == bitpict[secondbit])
74
									bitstat[firstbit] = bitstat[secondbit] = BTN_OPEN;
76
									bitstat[firstbit] = bitstat[secondbit] = BTN_OPEN;
75
								else
77
								else
76
									bitstat[firstbit] = bitstat[secondbit] = BTN_CLOSED;
78
									bitstat[firstbit] = bitstat[secondbit] = BTN_CLOSED;
77
								ReDraw_Game_Button(firstbit);
79
								ReDraw_Game_Button(firstbit);
78
								ReDraw_Game_Button(secondbit);
80
								ReDraw_Game_Button(secondbit);
79
								secondbit = 0x0BAD;
81
								secondbit = 0x0BAD;
80
								firstbit = id;
82
								firstbit = id;
81
								bitstat[id] = BTN_PRESSED;
83
								bitstat[id] = BTN_PRESSED;
82
								ReDraw_Game_Button(id);
84
								ReDraw_Game_Button(id);
83
								count++;
85
								count++;
84
							}
86
							}
85
							else if (firstbit != id)
87
							else if (firstbit != id)
86
							{
88
							{
87
								secondbit = id;
89
								secondbit = id;
88
								bitstat[id] = BTN_PRESSED;
90
								bitstat[id] = BTN_PRESSED;
89
								ReDraw_Game_Button(id);
91
								ReDraw_Game_Button(id);
90
								count++;
92
								count++;
91
							}
93
							}
92
						}
94
						}
93
						else
95
						else
94
						{
96
						{
95
							firstbit = id;
97
							firstbit = id;
96
							bitstat[id] = BTN_PRESSED;
98
							bitstat[id] = BTN_PRESSED;
97
							ReDraw_Game_Button(id);
99
							ReDraw_Game_Button(id);
98
							count++;
100
							count++;
99
						}
101
						}
100
					}
102
					}
101
					Draw_Count();
103
					Draw_Count();
102
			}
104
			}
103
			break;
105
			break;
104
 
106
 
105
		case evReDraw:
107
		case evReDraw:
106
			sc.get();
108
			sc.get();
107
			DefineAndDrawWindow(215,100,WIN_W + 9,WIN_H+4+skin_height,
109
			DefineAndDrawWindow(215,100,WIN_W + 9,WIN_H+4+GetSkinHeight(),
108
				0x34,0xC0C0C0,"Memory Blocks",0);
110
				0x34,0xC0C0C0,"Memory Blocks",0);
109
			Draw_Panel();
111
			Draw_Panel();
110
			Draw_Game_Pole();
112
			Draw_Game_Pole();
111
	}
113
	}
112
}
114
}
113
 
115
 
114
void NewGame()
116
void NewGame()
115
{
117
{
116
	int off;
118
	int off;
117
	int i;
119
	int i;
118
 
120
 
119
	FOR (i = 0; i < COUNT; i++)
121
	FOR (i = 0; i < COUNT; i++)
120
	{
122
	{
121
		bitstat[i] = 0;
123
		bitstat[i] = 0;
122
		bitpict[i] = 0;
124
		bitpict[i] = 0;
123
	}
125
	}
124
 
126
 
125
	count = 0;
127
	count = 0;
126
	firstbit = secondbit = 0x0BAD;
128
	firstbit = secondbit = 0x0BAD;
127
	FOR (i = 0; i < COUNT/2; i++)
129
	FOR (i = 0; i < COUNT/2; i++)
128
	{
130
	{
129
		do off = random(COUNT); while (bitpict[off] != 0);
131
		do off = random(COUNT); while (bitpict[off] != 0);
130
		bitpict[off] = i;
132
		bitpict[off] = i;
131
		do off = random(COUNT); while (bitpict[off] != 0);
133
		do off = random(COUNT); while (bitpict[off] != 0);
132
		bitpict[off] = i;
134
		bitpict[off] = i;
133
	}
135
	}
134
	Draw_Game_Pole();
136
	Draw_Game_Pole();
135
	Draw_Panel();
137
	Draw_Panel();
136
}
138
}
137
 
139
 
138
void Draw_Game_Pole()
140
void Draw_Game_Pole()
139
{
141
{
140
	int i;
142
	int i;
141
	byte j;
143
	byte j;
142
	for (j = 0; j < COLS; j++)	for (i = 0; i < ROWS; i++)
144
	for (j = 0; j < COLS; j++)	for (i = 0; i < ROWS; i++)
143
	{
145
	{
144
			butonsx[j*ROWS+i] = CELL_SIZE+4 * j + 4; //save coordinates to avoid 
146
			butonsx[j*ROWS+i] = CELL_SIZE+4 * j + 4; //save coordinates to avoid 
145
			butonsy[j*ROWS+i] = CELL_SIZE+4 * i + 4; //their recalculation after
147
			butonsy[j*ROWS+i] = CELL_SIZE+4 * i + 4; //their recalculation after
146
			ReDraw_Game_Button(j*ROWS + i);
148
			ReDraw_Game_Button(j*ROWS + i);
147
	}
149
	}
148
}
150
}
149
 
151
 
150
void ReDraw_Game_Button(int id)
152
void ReDraw_Game_Button(int id)
151
{
153
{
152
	dword xx, yy;
154
	dword xx, yy;
153
	xx = butonsx[id];
155
	xx = butonsx[id];
154
	yy = butonsy[id];
156
	yy = butonsy[id];
155
	DefineButton(xx, yy, CELL_SIZE, CELL_SIZE, 100 + BT_HIDE + id, 0);
157
	DefineButton(xx, yy, CELL_SIZE, CELL_SIZE, 100 + BT_HIDE + id, 0);
156
	DrawRectangle3D(xx, yy, CELL_SIZE, CELL_SIZE, 0x94AECE, 0x94AECE);//border
158
	DrawRectangle3D(xx, yy, CELL_SIZE, CELL_SIZE, 0x94AECE, 0x94AECE);//border
157
	switch (bitstat[id])
159
	switch (bitstat[id])
158
	{
160
	{
159
		case BTN_CLOSED:
161
		case BTN_CLOSED:
160
			DrawRectangle3D(xx + 1, yy + 1, CELL_SIZE-2, CELL_SIZE-2, 0xFFFFFF, 0xDEDEDE);//bump
162
			DrawRectangle3D(xx + 1, yy + 1, CELL_SIZE-2, CELL_SIZE-2, 0xFFFFFF, 0xDEDEDE);//bump
161
			DrawBar(xx + 2, yy + 2, CELL_SIZE-3, CELL_SIZE-3, 0xBDC7D6);//background
163
			DrawBar(xx + 2, yy + 2, CELL_SIZE-3, CELL_SIZE-3, 0xBDC7D6);//background
162
			break;
164
			break;
163
		case BTN_PRESSED:
165
		case BTN_PRESSED:
164
			DrawWideRectangle(xx + 1, yy + 1, CELL_SIZE-1, CELL_SIZE-1, 2, 0x94DB00);//border green
166
			DrawWideRectangle(xx + 1, yy + 1, CELL_SIZE-1, CELL_SIZE-1, 2, 0x94DB00);//border green
165
			DrawBar(xx + 3, yy + 3, CELL_SIZE-5, CELL_SIZE-5, 0xFFFfff);//background
167
			DrawBar(xx + 3, yy + 3, CELL_SIZE-5, CELL_SIZE-5, 0xFFFfff);//background
166
			img_draw stdcall(skin.image, xx+6, yy+6, 32, 32, 0, bitpict[id]*32);
168
			img_draw stdcall(skin.image, xx+6, yy+6, 32, 32, 0, bitpict[id]*32);
167
			BREAK;
169
			BREAK;
168
		case BTN_OPEN:
170
		case BTN_OPEN:
169
			DrawBar(xx+1, yy+1, CELL_SIZE-1, CELL_SIZE-1, 0xFFFfff);//background
171
			DrawBar(xx+1, yy+1, CELL_SIZE-1, CELL_SIZE-1, 0xFFFfff);//background
170
			img_draw stdcall(skin.image, xx+6, yy+6, 32, 32, 0, bitpict[id]*32);
172
			img_draw stdcall(skin.image, xx+6, yy+6, 32, 32, 0, bitpict[id]*32);
171
	}
173
	}
172
}
174
}
173
 
175
 
174
void Draw_Panel()
176
void Draw_Panel()
175
{
177
{
176
	DrawBar(0, PANEL_Y, WIN_W, 1, sc.work_dark);
178
	DrawBar(0, PANEL_Y, WIN_W, 1, sc.work_dark);
177
	DrawBar(0, PANEL_Y+1, WIN_W, 1, sc.work_light);
179
	DrawBar(0, PANEL_Y+1, WIN_W, 1, sc.work_light);
178
	DrawBar(0, PANEL_Y+2, WIN_W, PANEL_H-2, sc.work);
180
	DrawBar(0, PANEL_Y+2, WIN_W, PANEL_H-2, sc.work);
179
	DefineButton(9, PANEL_Y+5, 102, 26, 5, sc.button);
181
	DefineButton(9, PANEL_Y+5, 102, 26, 5, sc.button);
180
	WriteText(20, PANEL_Y+11, 0x90, sc.button_text, LABEL_NEW_GAME);
182
	WriteText(20, PANEL_Y+11, 0x90, sc.button_text, LABEL_NEW_GAME);
181
	Draw_Count();
183
	Draw_Count();
182
}
184
}
183
 
185
 
184
void Draw_Count()
186
void Draw_Count()
185
{
187
{
186
	EDI = sc.work; //writing a number with bg
188
	EDI = sc.work; //writing a number with bg
187
	WriteNumber(WIN_W-32, PANEL_Y + 12, 0xD0, sc.work_text, 3, count);
189
	WriteNumber(WIN_W-32, PANEL_Y + 12, 0xD0, sc.work_text, 3, count);
188
}
190
}
189
 
191
 
190
 
192
 
191
 
193
 
192
 
194
 
193
stop:
195
stop: