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