Subversion Repositories Kolibri OS

Rev

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