Subversion Repositories Kolibri OS

Rev

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

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