Rev 9439 | 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 | |||
7981 | leency | 13 | #define BTN_CLOSED 0 |
14 | #define BTN_PRESSED 1 |
||
15 | #define BTN_OPEN 2 |
||
16 | |||
6954 | leency | 17 | #define CELL_SIZE 43 |
18 | #define PANEL_Y CELL_SIZE+4*6 + 4 |
||
19 | #define PANEL_H 36 |
||
7981 | leency | 20 | #define WIN_W CELL_SIZE+4*10 + 4 |
21 | #define WIN_H PANEL_Y+PANEL_H |
||
6954 | leency | 22 | |
7981 | leency | 23 | #define ROWS 6 |
24 | #define COLS 10 |
||
25 | #define COUNT ROWS*COLS |
||
6954 | leency | 26 | |
27 | #ifdef LANG_RUS |
||
7981 | leency | 28 | #define LABEL_NEW_GAME "Новая игра"; |
7221 | leency | 29 | #else |
7981 | leency | 30 | #define LABEL_NEW_GAME " New game"; |
6954 | leency | 31 | #endif |
32 | |||
7981 | leency | 33 | int bitstat[COUNT], bitpict[COUNT]; |
34 | dword butonsx[COUNT], butonsy[COUNT]; |
||
6954 | leency | 35 | dword firstbit, secondbit; |
7613 | leency | 36 | int count; |
6954 | leency | 37 | |
38 | void main() |
||
39 | { |
||
40 | dword id; |
||
41 | |||
9439 | leency | 42 | mem_init(); |
6954 | leency | 43 | NewGame(); |
44 | |||
7981 | leency | 45 | loop() switch(@WaitEvent()) |
6954 | leency | 46 | { |
47 | case evKey: |
||
7995 | leency | 48 | //if (@GetKeyScancode()==SCAN_CODE_F2) NewGame(); |
7981 | leency | 49 | break; |
50 | |||
6954 | leency | 51 | case evButton: |
7981 | leency | 52 | id = @GetButtonID(); |
53 | if (id==1) @ExitProcess(); |
||
7613 | leency | 54 | else if (id==5) NewGame(); |
55 | else { |
||
7981 | leency | 56 | id -= 100; |
57 | if (bitstat[id] == BTN_CLOSED) |
||
7613 | leency | 58 | { |
7981 | leency | 59 | if (firstbit != 0x0BAD) |
6954 | leency | 60 | { |
7981 | leency | 61 | if (secondbit != 0x0BAD) |
6954 | leency | 62 | { |
7981 | leency | 63 | if (bitpict[firstbit] == bitpict[secondbit]) |
64 | bitstat[firstbit] = bitstat[secondbit] = BTN_OPEN; |
||
7613 | leency | 65 | else |
7981 | leency | 66 | bitstat[firstbit] = bitstat[secondbit] = BTN_CLOSED; |
67 | ReDraw_Game_Button(firstbit); |
||
68 | ReDraw_Game_Button(secondbit); |
||
7613 | leency | 69 | secondbit = 0x0BAD; |
70 | firstbit = id; |
||
71 | count++; |
||
7995 | leency | 72 | } else if (firstbit != id) { |
7613 | leency | 73 | secondbit = id; |
6954 | leency | 74 | count++; |
75 | } |
||
7995 | leency | 76 | } else { |
7613 | leency | 77 | firstbit = id; |
78 | count++; |
||
79 | } |
||
80 | } |
||
7995 | leency | 81 | bitstat[id] = BTN_PRESSED; |
82 | ReDraw_Game_Button(id); |
||
7613 | leency | 83 | Draw_Count(); |
84 | } |
||
85 | break; |
||
6954 | leency | 86 | |
87 | case evReDraw: |
||
7806 | leency | 88 | sc.get(); |
7982 | leency | 89 | DefineAndDrawWindow(215,100,WIN_W + 9,WIN_H+4+GetSkinHeight(), |
7613 | leency | 90 | 0x34,0xC0C0C0,"Memory Blocks",0); |
6954 | leency | 91 | Draw_Panel(); |
92 | Draw_Game_Pole(); |
||
93 | } |
||
94 | } |
||
95 | |||
96 | void NewGame() |
||
97 | { |
||
98 | int off; |
||
7613 | leency | 99 | int i; |
6954 | leency | 100 | |
7981 | leency | 101 | FOR (i = 0; i < COUNT; i++) |
6954 | leency | 102 | { |
7613 | leency | 103 | bitstat[i] = 0; |
6954 | leency | 104 | bitpict[i] = 0; |
105 | } |
||
106 | |||
107 | count = 0; |
||
108 | firstbit = secondbit = 0x0BAD; |
||
7981 | leency | 109 | FOR (i = 0; i < COUNT/2; i++) |
6954 | leency | 110 | { |
7981 | leency | 111 | do off = random(COUNT); while (bitpict[off] != 0); |
6954 | leency | 112 | bitpict[off] = i; |
7981 | leency | 113 | do off = random(COUNT); while (bitpict[off] != 0); |
6954 | leency | 114 | bitpict[off] = i; |
115 | } |
||
7613 | leency | 116 | Draw_Game_Pole(); |
117 | Draw_Panel(); |
||
6954 | leency | 118 | } |
119 | |||
120 | void Draw_Game_Pole() |
||
121 | { |
||
7613 | leency | 122 | int i; |
6954 | leency | 123 | byte j; |
7981 | leency | 124 | for (j = 0; j < COLS; j++) for (i = 0; i < ROWS; i++) |
6954 | leency | 125 | { |
7981 | leency | 126 | butonsx[j*ROWS+i] = CELL_SIZE+4 * j + 4; //save coordinates to avoid |
127 | butonsy[j*ROWS+i] = CELL_SIZE+4 * i + 4; //their recalculation after |
||
128 | ReDraw_Game_Button(j*ROWS + i); |
||
6954 | leency | 129 | } |
130 | } |
||
131 | |||
7981 | leency | 132 | void ReDraw_Game_Button(int id) |
6954 | leency | 133 | { |
7981 | leency | 134 | dword xx, yy; |
135 | xx = butonsx[id]; |
||
136 | yy = butonsy[id]; |
||
137 | DefineButton(xx, yy, CELL_SIZE, CELL_SIZE, 100 + BT_HIDE + id, 0); |
||
138 | DrawRectangle3D(xx, yy, CELL_SIZE, CELL_SIZE, 0x94AECE, 0x94AECE);//border |
||
139 | switch (bitstat[id]) |
||
140 | { |
||
141 | case BTN_CLOSED: |
||
142 | DrawRectangle3D(xx + 1, yy + 1, CELL_SIZE-2, CELL_SIZE-2, 0xFFFFFF, 0xDEDEDE);//bump |
||
143 | DrawBar(xx + 2, yy + 2, CELL_SIZE-3, CELL_SIZE-3, 0xBDC7D6);//background |
||
7995 | leency | 144 | return; |
7981 | leency | 145 | case BTN_PRESSED: |
146 | DrawWideRectangle(xx + 1, yy + 1, CELL_SIZE-1, CELL_SIZE-1, 2, 0x94DB00);//border green |
||
147 | DrawBar(xx + 3, yy + 3, CELL_SIZE-5, CELL_SIZE-5, 0xFFFfff);//background |
||
148 | BREAK; |
||
149 | case BTN_OPEN: |
||
150 | DrawBar(xx+1, yy+1, CELL_SIZE-1, CELL_SIZE-1, 0xFFFfff);//background |
||
151 | } |
||
9439 | leency | 152 | draw_icon_32(xx+6, yy+6, 0xffFFFfff, bitpict[id]+51); //skip first 51 icons as they are boring for game |
6954 | leency | 153 | } |
154 | |||
155 | void Draw_Panel() |
||
156 | { |
||
9602 | leency | 157 | DrawBar(0, PANEL_Y, WIN_W, 1, sc.dark); |
158 | DrawBar(0, PANEL_Y+1, WIN_W, 1, sc.light); |
||
7981 | leency | 159 | DrawBar(0, PANEL_Y+2, WIN_W, PANEL_H-2, sc.work); |
160 | DefineButton(9, PANEL_Y+5, 102, 26, 5, sc.button); |
||
161 | WriteText(20, PANEL_Y+11, 0x90, sc.button_text, LABEL_NEW_GAME); |
||
6954 | leency | 162 | Draw_Count(); |
163 | } |
||
164 | |||
165 | void Draw_Count() |
||
166 | { |
||
7981 | leency | 167 | EDI = sc.work; //writing a number with bg |
168 | WriteNumber(WIN_W-32, PANEL_Y + 12, 0xD0, sc.work_text, 3, count); |
||
6954 | leency | 169 | } |
170 | |||
171 | |||
172 | |||
173 | |||
174 | stop:>>>> |