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