2017-09-06 18:16:43 +02:00
|
|
|
|
/*
|
2020-05-25 16:20:17 +02:00
|
|
|
|
Memory Blocks for KolibriOS v1.2
|
2017-09-06 18:16:43 +02:00
|
|
|
|
Leency&Veliant Edition
|
2020-05-25 16:20:17 +02:00
|
|
|
|
2008-2020
|
2017-09-06 18:16:43 +02:00
|
|
|
|
*/
|
|
|
|
|
|
2020-05-25 16:20:17 +02:00
|
|
|
|
#define MEMSIZE 1024 * 20
|
2020-05-25 17:20:10 +02:00
|
|
|
|
#define ENTRY_POINT #main
|
|
|
|
|
|
2017-09-06 18:16:43 +02:00
|
|
|
|
#include "..\lib\gui.h"
|
|
|
|
|
#include "..\lib\random.h"
|
|
|
|
|
|
2020-05-25 16:20:17 +02:00
|
|
|
|
#define BTN_CLOSED 0
|
|
|
|
|
#define BTN_PRESSED 1
|
|
|
|
|
#define BTN_OPEN 2
|
|
|
|
|
|
2017-09-06 18:16:43 +02:00
|
|
|
|
#define CELL_SIZE 43
|
|
|
|
|
#define PANEL_Y CELL_SIZE+4*6 + 4
|
|
|
|
|
#define PANEL_H 36
|
2020-05-25 16:20:17 +02:00
|
|
|
|
#define WIN_W CELL_SIZE+4*10 + 4
|
|
|
|
|
#define WIN_H PANEL_Y+PANEL_H
|
2017-09-06 18:16:43 +02:00
|
|
|
|
|
2020-05-25 16:20:17 +02:00
|
|
|
|
#define ROWS 6
|
|
|
|
|
#define COLS 10
|
|
|
|
|
#define COUNT ROWS*COLS
|
2017-09-06 18:16:43 +02:00
|
|
|
|
|
|
|
|
|
#ifdef LANG_RUS
|
2020-05-25 16:20:17 +02:00
|
|
|
|
#define LABEL_NEW_GAME "<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>";
|
2018-04-04 01:38:46 +02:00
|
|
|
|
#else
|
2020-05-25 16:20:17 +02:00
|
|
|
|
#define LABEL_NEW_GAME " New game";
|
2017-09-06 18:16:43 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2020-05-25 16:20:17 +02:00
|
|
|
|
int bitstat[COUNT], bitpict[COUNT];
|
|
|
|
|
dword butonsx[COUNT], butonsy[COUNT];
|
2017-09-06 18:16:43 +02:00
|
|
|
|
dword firstbit, secondbit;
|
2019-03-16 22:06:09 +01:00
|
|
|
|
int count;
|
2017-09-06 18:16:43 +02:00
|
|
|
|
|
|
|
|
|
void main()
|
|
|
|
|
{
|
|
|
|
|
dword id;
|
|
|
|
|
|
2021-12-18 16:21:21 +01:00
|
|
|
|
mem_init();
|
2017-09-06 18:16:43 +02:00
|
|
|
|
NewGame();
|
|
|
|
|
|
2020-05-25 16:20:17 +02:00
|
|
|
|
loop() switch(@WaitEvent())
|
2017-09-06 18:16:43 +02:00
|
|
|
|
{
|
|
|
|
|
case evKey:
|
2020-05-28 02:55:16 +02:00
|
|
|
|
//if (@GetKeyScancode()==SCAN_CODE_F2) NewGame();
|
2020-05-25 16:20:17 +02:00
|
|
|
|
break;
|
|
|
|
|
|
2017-09-06 18:16:43 +02:00
|
|
|
|
case evButton:
|
2020-05-25 16:20:17 +02:00
|
|
|
|
id = @GetButtonID();
|
|
|
|
|
if (id==1) @ExitProcess();
|
2019-03-16 22:06:09 +01:00
|
|
|
|
else if (id==5) NewGame();
|
|
|
|
|
else {
|
2020-05-25 16:20:17 +02:00
|
|
|
|
id -= 100;
|
|
|
|
|
if (bitstat[id] == BTN_CLOSED)
|
2019-03-16 22:06:09 +01:00
|
|
|
|
{
|
2020-05-25 16:20:17 +02:00
|
|
|
|
if (firstbit != 0x0BAD)
|
2017-09-06 18:16:43 +02:00
|
|
|
|
{
|
2020-05-25 16:20:17 +02:00
|
|
|
|
if (secondbit != 0x0BAD)
|
2017-09-06 18:16:43 +02:00
|
|
|
|
{
|
2020-05-25 16:20:17 +02:00
|
|
|
|
if (bitpict[firstbit] == bitpict[secondbit])
|
|
|
|
|
bitstat[firstbit] = bitstat[secondbit] = BTN_OPEN;
|
2019-03-16 22:06:09 +01:00
|
|
|
|
else
|
2020-05-25 16:20:17 +02:00
|
|
|
|
bitstat[firstbit] = bitstat[secondbit] = BTN_CLOSED;
|
|
|
|
|
ReDraw_Game_Button(firstbit);
|
|
|
|
|
ReDraw_Game_Button(secondbit);
|
2019-03-16 22:06:09 +01:00
|
|
|
|
secondbit = 0x0BAD;
|
|
|
|
|
firstbit = id;
|
|
|
|
|
count++;
|
2020-05-28 02:55:16 +02:00
|
|
|
|
} else if (firstbit != id) {
|
2019-03-16 22:06:09 +01:00
|
|
|
|
secondbit = id;
|
2017-09-06 18:16:43 +02:00
|
|
|
|
count++;
|
|
|
|
|
}
|
2020-05-28 02:55:16 +02:00
|
|
|
|
} else {
|
2019-03-16 22:06:09 +01:00
|
|
|
|
firstbit = id;
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-28 02:55:16 +02:00
|
|
|
|
bitstat[id] = BTN_PRESSED;
|
|
|
|
|
ReDraw_Game_Button(id);
|
2019-03-16 22:06:09 +01:00
|
|
|
|
Draw_Count();
|
|
|
|
|
}
|
|
|
|
|
break;
|
2017-09-06 18:16:43 +02:00
|
|
|
|
|
|
|
|
|
case evReDraw:
|
2020-04-18 01:52:24 +02:00
|
|
|
|
sc.get();
|
2020-05-25 17:20:10 +02:00
|
|
|
|
DefineAndDrawWindow(215,100,WIN_W + 9,WIN_H+4+GetSkinHeight(),
|
2019-03-16 22:06:09 +01:00
|
|
|
|
0x34,0xC0C0C0,"Memory Blocks",0);
|
2017-09-06 18:16:43 +02:00
|
|
|
|
Draw_Panel();
|
|
|
|
|
Draw_Game_Pole();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NewGame()
|
|
|
|
|
{
|
|
|
|
|
int off;
|
2019-03-16 22:06:09 +01:00
|
|
|
|
int i;
|
2017-09-06 18:16:43 +02:00
|
|
|
|
|
2020-05-25 16:20:17 +02:00
|
|
|
|
FOR (i = 0; i < COUNT; i++)
|
2017-09-06 18:16:43 +02:00
|
|
|
|
{
|
2019-03-16 22:06:09 +01:00
|
|
|
|
bitstat[i] = 0;
|
2017-09-06 18:16:43 +02:00
|
|
|
|
bitpict[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
|
firstbit = secondbit = 0x0BAD;
|
2020-05-25 16:20:17 +02:00
|
|
|
|
FOR (i = 0; i < COUNT/2; i++)
|
2017-09-06 18:16:43 +02:00
|
|
|
|
{
|
2020-05-25 16:20:17 +02:00
|
|
|
|
do off = random(COUNT); while (bitpict[off] != 0);
|
2017-09-06 18:16:43 +02:00
|
|
|
|
bitpict[off] = i;
|
2020-05-25 16:20:17 +02:00
|
|
|
|
do off = random(COUNT); while (bitpict[off] != 0);
|
2017-09-06 18:16:43 +02:00
|
|
|
|
bitpict[off] = i;
|
|
|
|
|
}
|
2019-03-16 22:06:09 +01:00
|
|
|
|
Draw_Game_Pole();
|
|
|
|
|
Draw_Panel();
|
2017-09-06 18:16:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Draw_Game_Pole()
|
|
|
|
|
{
|
2019-03-16 22:06:09 +01:00
|
|
|
|
int i;
|
2017-09-06 18:16:43 +02:00
|
|
|
|
byte j;
|
2020-05-25 16:20:17 +02:00
|
|
|
|
for (j = 0; j < COLS; j++) for (i = 0; i < ROWS; i++)
|
2017-09-06 18:16:43 +02:00
|
|
|
|
{
|
2020-05-25 16:20:17 +02:00
|
|
|
|
butonsx[j*ROWS+i] = CELL_SIZE+4 * j + 4; //save coordinates to avoid
|
|
|
|
|
butonsy[j*ROWS+i] = CELL_SIZE+4 * i + 4; //their recalculation after
|
|
|
|
|
ReDraw_Game_Button(j*ROWS + i);
|
2017-09-06 18:16:43 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-25 16:20:17 +02:00
|
|
|
|
void ReDraw_Game_Button(int id)
|
2017-09-06 18:16:43 +02:00
|
|
|
|
{
|
2020-05-25 16:20:17 +02:00
|
|
|
|
dword xx, yy;
|
|
|
|
|
xx = butonsx[id];
|
|
|
|
|
yy = butonsy[id];
|
|
|
|
|
DefineButton(xx, yy, CELL_SIZE, CELL_SIZE, 100 + BT_HIDE + id, 0);
|
|
|
|
|
DrawRectangle3D(xx, yy, CELL_SIZE, CELL_SIZE, 0x94AECE, 0x94AECE);//border
|
|
|
|
|
switch (bitstat[id])
|
|
|
|
|
{
|
|
|
|
|
case BTN_CLOSED:
|
|
|
|
|
DrawRectangle3D(xx + 1, yy + 1, CELL_SIZE-2, CELL_SIZE-2, 0xFFFFFF, 0xDEDEDE);//bump
|
|
|
|
|
DrawBar(xx + 2, yy + 2, CELL_SIZE-3, CELL_SIZE-3, 0xBDC7D6);//background
|
2020-05-28 02:55:16 +02:00
|
|
|
|
return;
|
2020-05-25 16:20:17 +02:00
|
|
|
|
case BTN_PRESSED:
|
|
|
|
|
DrawWideRectangle(xx + 1, yy + 1, CELL_SIZE-1, CELL_SIZE-1, 2, 0x94DB00);//border green
|
|
|
|
|
DrawBar(xx + 3, yy + 3, CELL_SIZE-5, CELL_SIZE-5, 0xFFFfff);//background
|
|
|
|
|
BREAK;
|
|
|
|
|
case BTN_OPEN:
|
|
|
|
|
DrawBar(xx+1, yy+1, CELL_SIZE-1, CELL_SIZE-1, 0xFFFfff);//background
|
|
|
|
|
}
|
2021-12-18 16:21:21 +01:00
|
|
|
|
draw_icon_32(xx+6, yy+6, 0xffFFFfff, bitpict[id]+51); //skip first 51 icons as they are boring for game
|
2017-09-06 18:16:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Draw_Panel()
|
|
|
|
|
{
|
2020-05-25 16:20:17 +02:00
|
|
|
|
DrawBar(0, PANEL_Y, WIN_W, 1, sc.work_dark);
|
|
|
|
|
DrawBar(0, PANEL_Y+1, WIN_W, 1, sc.work_light);
|
|
|
|
|
DrawBar(0, PANEL_Y+2, WIN_W, PANEL_H-2, sc.work);
|
|
|
|
|
DefineButton(9, PANEL_Y+5, 102, 26, 5, sc.button);
|
|
|
|
|
WriteText(20, PANEL_Y+11, 0x90, sc.button_text, LABEL_NEW_GAME);
|
2017-09-06 18:16:43 +02:00
|
|
|
|
Draw_Count();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Draw_Count()
|
|
|
|
|
{
|
2020-05-25 16:20:17 +02:00
|
|
|
|
EDI = sc.work; //writing a number with bg
|
|
|
|
|
WriteNumber(WIN_W-32, PANEL_Y + 12, 0xD0, sc.work_text, 3, count);
|
2017-09-06 18:16:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stop:
|