Rev 6954 | Rev 7221 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6954 | leency | 1 | /* |
2 | Memory Blocks for KolibriOS v1.1 |
||
3 | Leency&Veliant Edition |
||
4 | 2008-2017 |
||
5 | */ |
||
6 | |||
7 | #define MEMSIZE 4096 * 12 |
||
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 | #include "..\lib\patterns\libimg_load_skin.h" |
14 | |||
15 | proc_info Form; |
||
16 | |||
17 | #ifndef AUTOBUILD |
||
18 | #include "lang.h--" |
||
19 | #endif |
||
20 | |||
21 | #define COLOR_CELL_BG 0xFFFfff |
||
22 | #define COLOR_CELL_BORDER 0x94AECE |
||
23 | #define CELL_SIZE 43 |
||
24 | #define PANEL_Y CELL_SIZE+4*6 + 4 |
||
25 | #define PANEL_H 36 |
||
26 | |||
27 | #define strok 6 //cell count x |
||
28 | #define stolbcov 10 //cell count y |
||
29 | |||
30 | #ifdef LANG_RUS |
||
31 | #define LABEL_NEW_GAME "New game (F2)"; |
||
32 | #else |
||
33 | #define LABEL_NEW_GAME "Новая игра (F2)"; |
||
34 | #endif |
||
35 | |||
36 | int bitstat[60], bitpict[60]; |
||
37 | dword butonsx[60], butonsy[60]; |
||
38 | dword firstbit, secondbit; |
||
39 | int i, count, lang; |
||
40 | |||
41 | |||
42 | void main() |
||
43 | { |
||
44 | dword id; |
||
45 | load_dll(libio, #libio_init,1); |
||
46 | load_dll(libimg, #libimg_init,1); |
||
47 | |||
48 | Libimg_LoadImage(#skin, "/sys/icons32.png"); |
||
49 | Libimg_FillTransparent(skin.image, skin.w, skin.h, COLOR_CELL_BG); |
||
50 | |||
51 | NewGame(); |
||
52 | |||
53 | loop() switch(WaitEvent()) |
||
54 | { |
||
55 | case evKey: |
||
56 | GetKeys(); |
||
57 | if (key_scancode==60) NewGame(); |
||
58 | break; |
||
59 | |||
60 | case evButton: |
||
61 | id = GetButtonID(); |
||
62 | if (id==1) ExitProcess(); |
||
63 | else if (id==5) NewGame(); |
||
64 | else { |
||
65 | if (bitstat[id-100] == 0) |
||
66 | { |
||
67 | if (firstbit <> 0x0BAD) |
||
68 | { |
||
69 | if (secondbit <> 0x0BAD) |
||
70 | { |
||
71 | if (bitpict[firstbit-100] == bitpict[secondbit-100]) |
||
72 | bitstat[firstbit-100] = bitstat[secondbit-100] = 2; |
||
73 | else |
||
74 | bitstat[firstbit-100] = bitstat[secondbit-100] = 0; |
||
75 | ReDraw_Game_Button(firstbit - 100); |
||
76 | ReDraw_Game_Button(secondbit - 100); |
||
77 | secondbit = 0x0BAD; |
||
78 | firstbit = id; |
||
79 | bitstat[id-100] = 1; |
||
80 | ReDraw_Game_Button(id - 100); |
||
81 | count++; |
||
82 | } |
||
83 | else if (firstbit<>id) |
||
84 | { |
||
85 | secondbit = id; |
||
86 | bitstat[id-100] = 1; |
||
87 | ReDraw_Game_Button(id - 100); |
||
88 | count++; |
||
89 | } |
||
90 | } |
||
91 | else |
||
92 | { |
||
93 | firstbit = id; |
||
94 | bitstat[id-100] = 1; |
||
95 | ReDraw_Game_Button(id - 100); |
||
96 | count++; |
||
97 | } |
||
98 | } |
||
99 | Draw_Count(); |
||
100 | } |
||
101 | break; |
||
102 | |||
103 | case evReDraw: |
||
104 | system.color.get(); |
||
105 | DefineAndDrawWindow(215,100,CELL_SIZE+4*10 + 4 + 9,PANEL_Y + 4 + PANEL_H +skin_height,0x34,0xC0C0C0,"Memory Blocks",0); |
||
106 | GetProcessInfo(#Form, SelfInfo); |
||
107 | Draw_Panel(); |
||
108 | Draw_Game_Pole(); |
||
109 | break; |
||
110 | } |
||
111 | } |
||
112 | |||
113 | void NewGame() |
||
114 | { |
||
115 | int off; |
||
116 | |||
117 | FOR (i = 0; i < 60; i++) |
||
118 | { |
||
119 | bitpict[i] = 0; |
||
120 | bitpict[i] = 0; |
||
121 | } |
||
122 | |||
123 | count = 0; |
||
124 | firstbit = secondbit = 0x0BAD; |
||
125 | FOR (i = 0; i < 30; i++) |
||
126 | { |
||
127 | do off = random(60); while (bitpict[off] != 0); |
||
128 | bitpict[off] = i; |
||
129 | do off = random(60); while (bitpict[off] != 0); |
||
130 | bitpict[off] = i; |
||
131 | } |
||
132 | } |
||
133 | |||
134 | void ReDraw_Game_Button(int id) |
||
135 | { |
||
136 | DefineButton(butonsx[id], butonsy[id], CELL_SIZE, CELL_SIZE, 100 + id + BT_HIDE, 0); |
||
137 | switch (bitstat[id]) |
||
138 | { |
||
139 | case 0: |
||
140 | Draw_Block(butonsx[id], butonsy[id]); |
||
141 | break; |
||
142 | case 1: |
||
143 | Draw_Pressed_Block(butonsx[id], butonsy[id]); |
||
144 | img_draw stdcall(skin.image, butonsx[id]+6, butonsy[id]+6, 32, 32, 0, bitpict[id]*32); |
||
145 | BREAK; |
||
146 | case 2: |
||
147 | Draw_Open_Block(butonsx[id], butonsy[id]); |
||
148 | img_draw stdcall(skin.image, butonsx[id]+6, butonsy[id]+6, 32, 32, 0, bitpict[id]*32); |
||
149 | BREAK; |
||
150 | } |
||
151 | } |
||
152 | |||
153 | void Draw_Game_Pole() |
||
154 | { |
||
155 | byte j; |
||
156 | for (j = 0; j < stolbcov; j++) for (i = 0; i < strok; i++) |
||
157 | { |
||
158 | butonsx[j*strok+i] = CELL_SIZE+4 * j + 4; //save coordinates to avoid their recalculation after |
||
159 | butonsy[j*strok+i] = CELL_SIZE+4 * i + 4; |
||
160 | ReDraw_Game_Button(j*strok + i); |
||
161 | } |
||
162 | } |
||
163 | |||
164 | void Draw_Block(dword x, y) |
||
165 | { |
||
166 | DrawRectangle(x, y, CELL_SIZE, CELL_SIZE, COLOR_CELL_BORDER);//border |
||
167 | DrawRectangle3D(x + 1, y + 1, CELL_SIZE-2, CELL_SIZE-2, 0xFFFFFF, 0xDEDEDE);//bump |
||
168 | DrawBar(x + 2, y + 2, CELL_SIZE-3, CELL_SIZE-3, 0xBDC7D6);//background |
||
169 | } |
||
170 | |||
171 | void Draw_Open_Block(dword x, y) |
||
172 | { |
||
173 | DrawRectangle(x, y, CELL_SIZE, CELL_SIZE, COLOR_CELL_BORDER);//border |
||
174 | DrawBar(x + 1, y + 1, CELL_SIZE-1, CELL_SIZE-1, COLOR_CELL_BG);//background |
||
175 | } |
||
176 | |||
177 | void Draw_Pressed_Block(dword x, y) |
||
178 | { |
||
179 | DrawRectangle(x, y, CELL_SIZE, CELL_SIZE, COLOR_CELL_BORDER);//border |
||
180 | DrawWideRectangle(x + 1, y + 1, CELL_SIZE-1, CELL_SIZE-1, 2, 0x94DB00);//border green |
||
181 | DrawBar(x + 3, y + 3, CELL_SIZE-5, CELL_SIZE-5, COLOR_CELL_BG);//background |
||
182 | } |
||
183 | |||
184 | void Draw_Panel() |
||
185 | { |
||
186 | DrawBar(0, PANEL_Y, Form.cwidth, 1, system.color.work_dark); |
||
187 | DrawBar(0, PANEL_Y+1, Form.cwidth, 1, system.color.work_light); |
||
188 | DrawBar(0, PANEL_Y+2, Form.cwidth, PANEL_H-2, system.color.work); |
||
189 | DrawStandartCaptButton(9, PANEL_Y+5, 5, LABEL_NEW_GAME); |
||
190 | Draw_Count(); |
||
191 | } |
||
192 | |||
193 | void Draw_Count() |
||
194 | { |
||
195 | DrawBar(Form.cwidth-32,PANEL_Y + 12,30,12,system.color.work); |
||
196 | WriteNumber(Form.cwidth-32, PANEL_Y + 12, 0x90, system.color.work_text, 3, count); |
||
197 | } |
||
198 | |||
199 | |||
200 | |||
201 | |||
202 | stop:>>>>>>> |