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