Rev 7981 | Rev 7995 | 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 | |||
46 | void main() |
||
47 | { |
||
48 | dword id; |
||
49 | load_dll(libio, #libio_init,1); |
||
50 | load_dll(libimg, #libimg_init,1); |
||
51 | |||
7977 | leency | 52 | skin.load("/sys/icons32.png"); |
7981 | leency | 53 | skin.replace_color(0x00000000, 0xFFFfff); |
6954 | leency | 54 | |
55 | NewGame(); |
||
56 | |||
7981 | leency | 57 | loop() switch(@WaitEvent()) |
6954 | leency | 58 | { |
59 | case evKey: |
||
7981 | leency | 60 | if (@GetKeyScancode()==SCAN_CODE_F2) NewGame(); |
61 | break; |
||
62 | |||
6954 | leency | 63 | case evButton: |
7981 | leency | 64 | id = @GetButtonID(); |
65 | if (id==1) @ExitProcess(); |
||
7613 | leency | 66 | else if (id==5) NewGame(); |
67 | else { |
||
7981 | leency | 68 | id -= 100; |
69 | if (bitstat[id] == BTN_CLOSED) |
||
7613 | leency | 70 | { |
7981 | leency | 71 | if (firstbit != 0x0BAD) |
6954 | leency | 72 | { |
7981 | leency | 73 | if (secondbit != 0x0BAD) |
6954 | leency | 74 | { |
7981 | leency | 75 | if (bitpict[firstbit] == bitpict[secondbit]) |
76 | bitstat[firstbit] = bitstat[secondbit] = BTN_OPEN; |
||
7613 | leency | 77 | else |
7981 | leency | 78 | bitstat[firstbit] = bitstat[secondbit] = BTN_CLOSED; |
79 | ReDraw_Game_Button(firstbit); |
||
80 | ReDraw_Game_Button(secondbit); |
||
7613 | leency | 81 | secondbit = 0x0BAD; |
82 | firstbit = id; |
||
7981 | leency | 83 | bitstat[id] = BTN_PRESSED; |
84 | ReDraw_Game_Button(id); |
||
7613 | leency | 85 | count++; |
6954 | leency | 86 | } |
7981 | leency | 87 | else if (firstbit != id) |
6954 | leency | 88 | { |
7613 | leency | 89 | secondbit = id; |
7981 | leency | 90 | bitstat[id] = BTN_PRESSED; |
91 | ReDraw_Game_Button(id); |
||
6954 | leency | 92 | count++; |
93 | } |
||
94 | } |
||
7613 | leency | 95 | else |
96 | { |
||
97 | firstbit = id; |
||
7981 | leency | 98 | bitstat[id] = BTN_PRESSED; |
99 | ReDraw_Game_Button(id); |
||
7613 | leency | 100 | count++; |
101 | } |
||
102 | } |
||
103 | Draw_Count(); |
||
104 | } |
||
105 | break; |
||
6954 | leency | 106 | |
107 | case evReDraw: |
||
7806 | leency | 108 | sc.get(); |
7982 | leency | 109 | DefineAndDrawWindow(215,100,WIN_W + 9,WIN_H+4+GetSkinHeight(), |
7613 | leency | 110 | 0x34,0xC0C0C0,"Memory Blocks",0); |
6954 | leency | 111 | Draw_Panel(); |
112 | Draw_Game_Pole(); |
||
113 | } |
||
114 | } |
||
115 | |||
116 | void NewGame() |
||
117 | { |
||
118 | int off; |
||
7613 | leency | 119 | int i; |
6954 | leency | 120 | |
7981 | leency | 121 | FOR (i = 0; i < COUNT; i++) |
6954 | leency | 122 | { |
7613 | leency | 123 | bitstat[i] = 0; |
6954 | leency | 124 | bitpict[i] = 0; |
125 | } |
||
126 | |||
127 | count = 0; |
||
128 | firstbit = secondbit = 0x0BAD; |
||
7981 | leency | 129 | FOR (i = 0; i < COUNT/2; i++) |
6954 | leency | 130 | { |
7981 | leency | 131 | do off = random(COUNT); while (bitpict[off] != 0); |
6954 | leency | 132 | bitpict[off] = i; |
7981 | leency | 133 | do off = random(COUNT); while (bitpict[off] != 0); |
6954 | leency | 134 | bitpict[off] = i; |
135 | } |
||
7613 | leency | 136 | Draw_Game_Pole(); |
137 | Draw_Panel(); |
||
6954 | leency | 138 | } |
139 | |||
140 | void Draw_Game_Pole() |
||
141 | { |
||
7613 | leency | 142 | int i; |
6954 | leency | 143 | byte j; |
7981 | leency | 144 | for (j = 0; j < COLS; j++) for (i = 0; i < ROWS; i++) |
6954 | leency | 145 | { |
7981 | leency | 146 | butonsx[j*ROWS+i] = CELL_SIZE+4 * j + 4; //save coordinates to avoid |
147 | butonsy[j*ROWS+i] = CELL_SIZE+4 * i + 4; //their recalculation after |
||
148 | ReDraw_Game_Button(j*ROWS + i); |
||
6954 | leency | 149 | } |
150 | } |
||
151 | |||
7981 | leency | 152 | void ReDraw_Game_Button(int id) |
6954 | leency | 153 | { |
7981 | leency | 154 | dword xx, yy; |
155 | xx = butonsx[id]; |
||
156 | yy = butonsy[id]; |
||
157 | DefineButton(xx, yy, CELL_SIZE, CELL_SIZE, 100 + BT_HIDE + id, 0); |
||
158 | DrawRectangle3D(xx, yy, CELL_SIZE, CELL_SIZE, 0x94AECE, 0x94AECE);//border |
||
159 | switch (bitstat[id]) |
||
160 | { |
||
161 | case BTN_CLOSED: |
||
162 | DrawRectangle3D(xx + 1, yy + 1, CELL_SIZE-2, CELL_SIZE-2, 0xFFFFFF, 0xDEDEDE);//bump |
||
163 | DrawBar(xx + 2, yy + 2, CELL_SIZE-3, CELL_SIZE-3, 0xBDC7D6);//background |
||
164 | break; |
||
165 | case BTN_PRESSED: |
||
166 | DrawWideRectangle(xx + 1, yy + 1, CELL_SIZE-1, CELL_SIZE-1, 2, 0x94DB00);//border green |
||
167 | DrawBar(xx + 3, yy + 3, CELL_SIZE-5, CELL_SIZE-5, 0xFFFfff);//background |
||
168 | img_draw stdcall(skin.image, xx+6, yy+6, 32, 32, 0, bitpict[id]*32); |
||
169 | BREAK; |
||
170 | case BTN_OPEN: |
||
171 | DrawBar(xx+1, yy+1, CELL_SIZE-1, CELL_SIZE-1, 0xFFFfff);//background |
||
172 | img_draw stdcall(skin.image, xx+6, yy+6, 32, 32, 0, bitpict[id]*32); |
||
173 | } |
||
6954 | leency | 174 | } |
175 | |||
176 | void Draw_Panel() |
||
177 | { |
||
7981 | leency | 178 | DrawBar(0, PANEL_Y, WIN_W, 1, sc.work_dark); |
179 | DrawBar(0, PANEL_Y+1, WIN_W, 1, sc.work_light); |
||
180 | DrawBar(0, PANEL_Y+2, WIN_W, PANEL_H-2, sc.work); |
||
181 | DefineButton(9, PANEL_Y+5, 102, 26, 5, sc.button); |
||
182 | WriteText(20, PANEL_Y+11, 0x90, sc.button_text, LABEL_NEW_GAME); |
||
6954 | leency | 183 | Draw_Count(); |
184 | } |
||
185 | |||
186 | void Draw_Count() |
||
187 | { |
||
7981 | leency | 188 | EDI = sc.work; //writing a number with bg |
189 | WriteNumber(WIN_W-32, PANEL_Y + 12, 0xD0, sc.work_text, 3, count); |
||
6954 | leency | 190 | } |
191 | |||
192 | |||
193 | |||
194 | |||
195 | stop:>>>> |