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