Rev 109 | Rev 963 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 109 | Rev 126 | ||
---|---|---|---|
1 | /******************************************************************************* |
1 | /******************************************************************************* |
2 | 2 | ||
3 | MenuetOS MineSweeper |
3 | MenuetOS MineSweeper |
4 | Copyright (C) 2003 Ivan Poddubny |
4 | Copyright (C) 2003, 2004 Ivan Poddubny |
5 | 5 | ||
6 | This program is free software; you can redistribute it and/or modify |
6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by |
7 | it under the terms of the GNU General Public License as published by |
8 | the Free Software Foundation; either version 2 of the License, or |
8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. |
9 | (at your option) any later version. |
10 | 10 | ||
11 | This program is distributed in the hope that it will be useful, |
11 | This program is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | GNU General Public License for more details. |
14 | GNU General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU General Public License |
16 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software |
17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | 19 | ||
20 | *******************************************************************************/ |
20 | *******************************************************************************/ |
21 | 21 | ||
22 | //? pragma option LST // generate ASM listing file - ñîçäàòü àññåìáëåðíûé ëèñòèíã |
22 | ? pragma option LST // generate ASM listing file - ñîçäàòü àññåìáëåðíûé ëèñòèíã |
23 | //? warning TRUE // âêëþ÷èòü ðåæèì âûâîäà ïðåäóïðåæäåíèé |
- | |
24 | ? pragma option meos |
23 | ? warning TRUE // âêëþ÷èòü ðåæèì âûâîäà ïðåäóïðåæäåíèé |
25 | ? jumptomain NONE |
24 | ? jumptomain NONE |
- | 25 | ? include "msys.h--" // MenuetOS system functions - ñèñòåìíûå ôóíêöèè MenuetOS |
|
26 | ? include "msys.h--" // MenuetOS system functions - ñèñòåìíûå ôóíêöèè MenuetOS |
26 | //? define DEBUG 1 |
27 | 27 | ||
28 | ? print "\nÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿" |
28 | ? print "\nÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿" |
29 | ? print "\n³ MeOS MineSweeper v0.3 ³" |
29 | ? print "\n³ MenuetOS MineSweeper v0.4 ³" |
30 | ? print "\n³ (C) Ivan Poddubny (ivan-yar@bk.ru) 2003 ³" |
30 | ? print "\n³ (C) Ivan Poddubny (ivan-yar@bk.ru) 2003,2004 ³" |
31 | ? print "\nÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ\n\n" |
31 | ? print "\nÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ\n\n" |
32 | 32 | ||
33 | /************************************** DATA **************************************/ |
33 | /************************************** DATA **************************************/ |
34 | 34 | ||
35 | ? define XPX 16 // X pixels by square - ðàçìåð êëåòêè â ïèêñåëÿõ |
35 | ? define XPX 16 // X pixels by square - ðàçìåð êëåòêè â ïèêñåëÿõ |
36 | ? define YPX 16 // Y pixels by square |
36 | ? define YPX 16 // Y pixels by square |
37 | ? define MINE 255 // çíà÷åíèå äëÿ ìèíû â ïîëå value |
37 | ? define MINE 255 // â êëåòêå ìèíà, åñëè value = MINE |
38 | 38 | ||
39 | struct |
39 | struct |
40 | { |
40 | { |
41 | byte value; // number of mines - êîëè÷åñòâî ìèí â îêðóæàþùèõ êëåòêàõ |
41 | byte value; // number of mines - êîëè÷åñòâî ìèí â îêðóæàþùèõ êëåòêàõ |
42 | byte open; // square is open - êëåòêà îòêðûòà |
42 | byte open; // square is open - êëåòêà îòêðûòà |
43 | byte press; // reserved - çàðåçåðâèðîâàíî |
43 | byte press; // reserved - çàðåçåðâèðîâàíî |
44 | byte mark; // square is marked - êëåòêà ïîìå÷åíà |
44 | byte mark; // square is marked - êëåòêà ïîìå÷åíà |
45 | } massiv[30*30]; |
45 | } massiv[30*30]; |
46 | 46 | ||
47 | struct |
47 | struct |
48 | { |
48 | { |
49 | byte a_inc; |
49 | byte a_inc; |
50 | byte b_inc; |
50 | byte b_inc; |
51 | } matrix[8] = {-1,-1,1,0,1,0,0,1,-2,0,0,1,1,0,1,0}; |
51 | } matrix[8] = {-1,-1,1,0,1,0,0,1,-2,0,0,1,1,0,1,0}; |
52 | 52 | ||
53 | struct |
53 | struct |
54 | { |
54 | { |
55 | byte x_size; |
55 | byte x_size; |
56 | byte y_size; |
56 | byte y_size; |
57 | byte nmines; |
57 | byte nmines; |
58 | } stdmodes[3] = {9,9,10, 16,16,40, 30,16,99}; // {x,y,m} |
58 | } stdmodes[3] = {9,9,10, 16,16,40, 30,16,99}; // {x,y,m} |
59 | 59 | ||
60 | int XST, // offset of first pixel X - ñìåùåíèå ïîëÿ îò ãðàíèöû îêíà |
60 | int XST, // offset of first pixel X - ñìåùåíèå ïîëÿ îò ãðàíèöû îêíà |
61 | YST, |
61 | YST, |
62 | ncx, // number of squares in X - ðàçìåð ïîë |
62 | ncx, // number of squares in X - ðàçìåð ïîëÿ |
63 | ncy, |
63 | ncy, |
64 | cmines, // mines discovered - êîëè÷åñòâî íåîòêðûòûõ ìèí |
64 | cmines, // mines discovered - êîëè÷åñòâî íåîòêðûòûõ ìèí |
65 | initmines, // number of initial mines - èçíà÷àëüíîå êîëè÷åñòâî ìèí |
65 | initmines, // number of initial mines - èçíà÷àëüíîå êîëè÷åñòâî ìèí |
66 | sqclosed; // squares still closed - êîëè÷åñòâî çàêðûòûõ êëåòîê |
66 | sqclosed; // squares still closed - êîëè÷åñòâî çàêðûòûõ êëåòîê |
67 | 67 | ||
68 | dword xpos = 100, // window coordinates - êîîðäèíàòû îêíà |
68 | dword xpos = 100, // window coordinates - êîîðäèíàòû îêíà |
69 | ypos = 100, |
69 | ypos = 100, |
70 | xsize, // window size |
70 | xsize, // window size |
71 | ysize; |
71 | ysize; |
72 | 72 | ||
73 | byte stop_game = FALSE, // game stopped - ïðèçíàê êîíöà èãðû |
73 | byte stop_game = FALSE, // game stopped - ïðèçíàê êîíöà èãðû |
74 | mouse_en = TRUE, // mouse enabled - ìûøü |
74 | mouse_en = TRUE, // mouse enabled - ìûøü |
75 | mode = 3, // ðåæèì èãðû 1-íîâè÷îê 2-ëþáèòåëü 3-ýêñïåðò (0 îñîáûé) |
75 | mode = 3, // ðåæèì èãðû 1-íîâè÷îê 2-ëþáèòåëü 3-ýêñïåðò (0 îñîáûé) |
76 | mouse_status, |
76 | mouse_status, |
77 | firstmine; |
77 | firstmine; |
78 | 78 | ||
79 | ProcessInfo procinfo; |
79 | ProcessInfo procinfo; |
80 | SystemColors colors; |
80 | SystemColors colors; |
81 | 81 | ||
82 | /************************************** CODE **************************************/ |
82 | /************************************** CODE **************************************/ |
83 | 83 | ||
84 | inline void fastcall mouse_enable() |
84 | inline void fastcall mouse_enable() |
85 | { |
85 | { |
86 | $mov eax,40 |
86 | $mov eax,40 |
87 | $mov ebx,100111b |
87 | $mov ebx,100111b |
88 | $int 0x40 |
88 | $int 0x40 |
89 | } |
89 | } |
- | 90 | ||
90 | 91 | ||
91 | inline void fastcall mouse_disable() |
92 | inline void fastcall mouse_disable() |
92 | { |
93 | { |
93 | $mov eax,40 |
94 | $mov eax,40 |
94 | $mov ebx,000111b |
95 | $mov ebx,000111b |
95 | $int 0x40 |
96 | $int 0x40 |
96 | } |
97 | } |
- | 98 | ||
97 | 99 | ||
98 | ? include "timer.h--" // timer functions |
100 | ? include "timer.h--" // timer functions |
99 | ? include "draw.h--" // drawing functions |
101 | ? include "draw.h--" // drawing functions |
100 | ? include "access.h--" // get & set functions |
102 | ? include "access.h--" // get & set functions |
101 | ? include "random.h--" // random number generator |
103 | ? include "random.h--" // random number generator |
102 | //? include "uf.h--" // user field window |
104 | //? include "uf.h--" // user field window |
- | 105 | ||
103 | 106 | ||
104 | void init() |
107 | void init() |
105 | // Èíèöèàëèçàöè |
108 | // Èíèöèàëèçàöèÿ |
106 | { |
109 | { |
107 | XST = 10; YST = 52; // FIELD POSITION IN WINDOW |
110 | XST = 10; YST = 52; // FIELD POSITION IN WINDOW |
108 | 111 | ||
109 | ECX = mode; |
112 | ECX = mode; |
110 | IF (ECX != 0) |
113 | IF (ECX != 0) |
111 | { |
114 | { |
112 | //ncx = stdmodes[ECX-1].x_size; |
115 | //ncx = stdmodes[ECX-1].x_size; |
113 | //ncy = stdmodes[ECX-1].y_size; |
116 | //ncy = stdmodes[ECX-1].y_size; |
114 | //cmines = initmines = stdmodes[ECX-1].nmines; |
117 | //cmines = initmines = stdmodes[ECX-1].nmines; |
115 | 118 | ||
116 | EBX = #stdmodes; |
119 | EBX = #stdmodes; |
117 | ECX--; ECX *= 3; |
120 | ECX--; ECX *= 3; |
118 | EBX += ECX; |
121 | EBX += ECX; |
119 | 122 | ||
120 | ncx = DSBYTE[EBX]; EBX++; |
123 | ncx = DSBYTE[EBX]; EBX++; |
121 | ncy = DSBYTE[EBX]; EBX++; |
124 | ncy = DSBYTE[EBX]; EBX++; |
122 | cmines = initmines = DSBYTE[EBX]; |
125 | cmines = initmines = DSBYTE[EBX]; |
123 | } |
126 | } |
124 | 127 | ||
125 | xsize = ncx * XPX + XST + XST; |
128 | xsize = ncx * XPX + XST + XST; |
126 | ysize = ncy * YPX + YST + XST; |
129 | ysize = ncy * YPX + YST + XST; |
127 | } // init |
130 | } // init |
- | 131 | ||
128 | 132 | ||
129 | void clear_all() |
133 | void clear_all() |
130 | // Î÷èñòèòü ïîëå |
134 | // Î÷èñòèòü ïîëå |
131 | { |
135 | { |
132 | EAX = 0; |
136 | EAX = 0; |
133 | EDI = #massiv; |
137 | EDI = #massiv; |
134 | ECX = ncx * ncy; |
138 | ECX = ncx * ncy; |
135 | $REP $STOSD |
139 | $REP $STOSD |
136 | } // clear_all |
140 | } // clear_all |
- | 141 | ||
137 | 142 | ||
138 | void new_game() |
143 | void new_game() |
139 | // Íîâàÿ èãðà |
144 | // Íîâàÿ èãðà |
140 | { |
145 | { |
141 | init(); // èíèöèàëèçàöè |
146 | init(); // èíèöèàëèçàöèÿ |
142 | randomize(); // ãåíåðàòîð ñëó÷àéíûõ ÷èñåë |
147 | randomize(); // ãåíåðàòîð ñëó÷àéíûõ ÷èñåë |
143 | clear_all(); // î÷èñòèòü ïîëå |
148 | clear_all(); // î÷èñòèòü ïîëå |
144 | 149 | ||
145 | firstmine = TRUE; // èãðà íå íà÷àòà |
150 | firstmine = TRUE; // èãðà íå íà÷àòà |
146 | mouse_en = TRUE; // ìûøü ðàçðåøåíà |
151 | mouse_en = TRUE; // ìûøü ðàçðåøåíà |
147 | stop_game = FALSE; // èãðà íå çàêîí÷åíà |
152 | stop_game = FALSE; // èãðà íå çàêîí÷åíà |
148 | stop_timer(); |
153 | stop_timer(); |
149 | time = 0; // âðåìÿ = 0 |
154 | time = 0; // âðåìÿ = 0 |
150 | } // new_game |
155 | } // new_game |
- | 156 | ||
151 | 157 | ||
152 | void set_mines(int nminas, no_x, no_y) |
158 | void set_mines(int nminas, no_x, no_y) |
153 | // Ðàññòàâèòü ìèíû |
159 | // Ðàññòàâèòü ìèíû |
154 | { |
160 | { |
155 | int i, x, y, a, b; |
161 | int i, x, y, a, b; |
- | 162 | ||
- | 163 | #ifdef DEBUG |
|
- | 164 | sys_debug_write_string("MINE: set_mines called\n"); |
|
- | 165 | #endif |
|
156 | 166 | ||
157 | sqclosed = ncx * ncy - nminas; // êîëè÷åñòâî ÍÅîòêðûòûõ êëåòîê = ïëîùàäü ïîëÿ - êîë-âî ìèí |
167 | sqclosed = ncx * ncy - nminas; // êîëè÷åñòâî ÍÅîòêðûòûõ êëåòîê = ïëîùàäü ïîëÿ - êîë-âî ìèí |
158 | 168 | ||
159 | FOR (i = nminas; i > 0; i--) // ðàññòàâèòü ìèíû |
169 | FOR (i = nminas; i > 0; i--) // ðàññòàâèòü ìèíû |
160 | { |
170 | { |
- | 171 | x = random(ncx); |
|
161 | x = random(ncx); y = random(ncy); |
172 | y = random(ncy); |
162 | WHILE ((get_value(x, y) == MINE) || ((x == no_x) && (y == no_y))) |
173 | WHILE ((get_value(x, y) == MINE) || ((x == no_x) && (y == no_y))) |
163 | { |
174 | { |
164 | x = random(ncx); |
175 | x = random(ncx); |
165 | y = random(ncy); |
176 | y = random(ncy); |
166 | } |
177 | } |
167 | set_value(x, y, MINE); |
178 | set_value(x, y, MINE); |
168 | } |
179 | } |
169 | 180 | ||
170 | for (x = ncx-1; x >= 0; x--) // ðàññòàâèòü öèôðû |
181 | for (x = ncx-1; x >= 0; x--) // ðàññòàâèòü öèôðû |
171 | { |
182 | { |
172 | for (y = ncy-1; y >= 0; y--) |
183 | for (y = ncy-1; y >= 0; y--) |
173 | { |
184 | { |
174 | IF (get_value(x, y) == MINE) |
185 | IF (get_value(x, y) == MINE) |
175 | continue; |
186 | continue; |
176 | EDX = x * ncy + y*4 + #massiv; |
187 | EDX = x * ncy + y*4 + #massiv; |
177 | a = x; b = y; |
188 | a = x; b = y; |
178 | FOR (i = 0; i < 8; i++) |
189 | FOR (i = 0; i < 8; i++) |
179 | { |
190 | { |
180 | AL = matrix[i].a_inc; |
191 | AL = matrix[i].a_inc; |
181 | $movsx eax,al |
192 | $movsx eax,al |
182 | a += EAX; |
193 | a += EAX; |
183 | AL = matrix[i].b_inc; |
194 | AL = matrix[i].b_inc; |
184 | $movsx eax,al |
195 | $movsx eax,al |
185 | b += EAX; |
196 | b += EAX; |
186 | IF ((a >= 0) && (b >= 0) && (a < ncx) && (b < ncy) && (get_value(a, b) == MINE)) |
197 | IF ((a >= 0) && (b >= 0) && (a < ncx) && (b < ncy) && (get_value(a, b) == MINE)) |
187 | DSBYTE[EDX]++; |
198 | DSBYTE[EDX]++; |
188 | } |
199 | } |
189 | } |
200 | } |
190 | } |
201 | } |
191 | } // set_mines |
202 | } // set_mines |
- | 203 | ||
192 | 204 | ||
193 | inline void do_mouse(void) |
205 | inline void do_mouse(void) |
194 | // Îáðàáîò÷èê ìûøè |
206 | // Îáðàáîò÷èê ìûøè |
195 | { |
207 | { |
196 | int x,y; |
208 | int x,y; |
197 | 209 | ||
198 | EAX = sys_read_mouse(2); // ìûøü íå íàæàòà -> âûõîä |
210 | EAX = sys_read_mouse(2); // ìûøü íå íàæàòà -> âûõîä |
199 | IF (EAX == 0) return; |
211 | IF (EAX == 0) |
- | 212 | { |
|
- | 213 | // sys_debug_write_string("Strange\n"); |
|
- | 214 | return; |
|
- | 215 | } |
|
200 | 216 | ||
201 | mouse_status = AL; |
217 | mouse_status = AL; |
202 | 218 | ||
203 | EAX = sys_read_mouse(1); // ìûøü âíå ïîëÿ -> âûõîä |
219 | EAX = sys_read_mouse(1); // ìûøü âíå ïîëÿ -> âûõîä |
204 | EBX = EAX; EAX >>= 16; EBX &= 0xffff; |
220 | EBX = EAX; EAX >>= 16; EBX &= 0xffff; |
205 | ECX = ncx * XPX + XST - 1; |
221 | ECX = ncx * XPX + XST - 1; |
206 | EDX = ncy * YPX + YST - 1; |
222 | EDX = ncy * YPX + YST - 1; |
207 | IF ((EAX < XST) || (EBX < YST) || (EAX > ECX) || (EBX > EDX)) return; |
223 | IF ((EAX < XST) || (EBX < YST) || (EAX > ECX) || (EBX > EDX)) return; |
208 | 224 | ||
209 | EAX -= XST; EAX /= XPX; x = EAX; // âû÷èñëèòü x è y |
225 | EAX -= XST; EAX /= XPX; x = EAX; // âû÷èñëèòü x è y |
210 | EBX -= YST; EBX /= YPX; y = EBX; |
226 | EBX -= YST; EBX /= YPX; y = EBX; |
211 | 227 | ||
212 | IF ((mouse_status == 1) && (!get_open(x, y)) && (get_mark(x, y) != 1)) |
228 | IF ((mouse_status == 1) && (!get_open(x, y)) && (get_mark(x, y) != 1)) |
213 | { |
229 | { |
214 | // íà íåîòêðûòîé êëåòêå áåç ôëàæêà íàæàòà ëåâàÿ êíîïêà ìûøè |
230 | // íà íåîòêðûòîé êëåòêå áåç ôëàæêà íàæàòà ëåâàÿ êíîïêà ìûøè |
215 | // left mouse button is pressed |
231 | // left mouse button is pressed |
216 | IF (firstmine == TRUE) |
232 | IF (firstmine == TRUE) |
217 | { |
233 | { |
218 | firstmine = FALSE; |
234 | firstmine = FALSE; |
219 | set_mines(cmines, x, y); |
235 | set_mines(initmines, x, y); |
220 | start_timer(); |
236 | start_timer(); |
- | 237 | time = 1; |
|
- | 238 | draw_time(); |
|
221 | } |
239 | } |
222 | IF (get_value(x, y) == MINE) |
240 | IF (get_value(x, y) == MINE) |
223 | { |
241 | { |
224 | end_game(); |
242 | end_game(); |
225 | return; |
243 | return; |
226 | } |
244 | } |
227 | open_square(x, y); |
245 | open_square(x, y); |
228 | } |
246 | } |
229 | else IF ((mouse_status == 2) && (!get_open(x, y))) |
247 | else IF ((mouse_status == 2) && (!get_open(x, y))) |
230 | { |
248 | { |
231 | // íà íåîòêðûòîé êëåòêå íàæàòà ïðàâàÿ êíîïêà ìûøè |
249 | // íà íåîòêðûòîé êëåòêå íàæàòà ïðàâàÿ êíîïêà ìûøè |
232 | // right mouse button is pressed |
250 | // right mouse button is pressed |
233 | EBX = get_mark(x, y); EBX++; |
251 | EBX = get_mark(x, y); EBX++; |
234 | EBX = EBX%3; |
252 | EBX = EBX%3; |
235 | SWITCH (EBX) |
253 | SWITCH (EBX) |
236 | { |
254 | { |
237 | CASE 2: cmines++; BREAK; |
255 | CASE 2: cmines++; BREAK; |
238 | CASE 1: cmines--; |
256 | CASE 1: cmines--; |
239 | } |
257 | } |
240 | 258 | ||
241 | set_mark(x, y, EBX); |
259 | set_mark(x, y, EBX); |
242 | 260 | ||
243 | draw_minesi(); |
261 | draw_minesi(); |
244 | draw_square(x, y); |
262 | draw_square(x, y); |
245 | return; |
263 | return; |
246 | } |
264 | } |
247 | ELSE IF ((mouse_status == 3) && (get_open(x, y))) |
265 | ELSE IF ((mouse_status == 3) && (get_open(x, y))) |
248 | { |
266 | { |
249 | // íà îòêðûòîé êëåòêå íàæàòû îáå êíîïêè ìûøè |
267 | // íà îòêðûòîé êëåòêå íàæàòû îáå êíîïêè ìûøè |
250 | // both mouse buttons are pressed |
268 | // both mouse buttons are pressed |
251 | IF (open_near_squares(x, y) == TRUE) |
269 | IF (open_near_squares(x, y) == TRUE) |
252 | end_game(); |
270 | end_game(); |
253 | } |
271 | } |
254 | 272 | ||
- | 273 | IF (sqclosed == 0) |
|
255 | if (sqclosed == 0) |
274 | { |
256 | // îòêðûòû âñå êëåòêè |
275 | // îòêðûòû âñå êëåòêè |
257 | // all squares are opened |
- | |
258 | { |
276 | // all squares are opened |
259 | mouse_en = FALSE; // çàïðåòèòü ìûøü |
277 | mouse_en = FALSE; // çàïðåòèòü ìûøü |
260 | stop_timer(); |
278 | stop_timer(); |
261 | stop_game = TRUE; // èãðà çàâåðøåíà |
279 | stop_game = TRUE; // èãðà çàâåðøåíà |
262 | 280 | ||
263 | // ïîñòàâèòü íåðàññòàâëåííûå ìèíû |
281 | // ïîñòàâèòü íåðàññòàâëåííûå ìèíû |
264 | FOR (x = 0; x < ncx; x++) |
282 | FOR (x = 0; x < ncx; x++) |
265 | FOR (y = 0; y < ncy; y++) |
283 | FOR (y = 0; y < ncy; y++) |
266 | IF ((get_value(x, y) == MINE) && (get_mark(x, y) != 1)) |
284 | IF ((get_value(x, y) == MINE) && (get_mark(x, y) != 1)) |
267 | { |
285 | { |
268 | set_mark(x, y, 1); |
286 | set_mark(x, y, 1); |
269 | cmines--; |
287 | cmines--; |
270 | draw_square(x, y); |
288 | draw_square(x, y); |
271 | } |
289 | } |
272 | draw_minesi(); |
290 | draw_minesi(); |
273 | } |
291 | } |
274 | } // do_mouse |
292 | } // do_mouse |
- | 293 | ||
275 | 294 | ||
276 | void open_square(int x, y) |
295 | void open_square(int x, y) |
277 | // Îòêðûòü êëåòêó |
296 | // Îòêðûòü êëåòêó |
278 | { |
297 | { |
279 | int a, b, i; |
298 | int a, b, i; |
- | 299 | ||
- | 300 | #ifdef DEBUG |
|
- | 301 | sys_debug_write_string("MINE: open_square called\n"); |
|
- | 302 | #endif |
|
280 | 303 | ||
281 | set_open(x, y, TRUE); |
304 | set_open(x, y, TRUE); |
282 | sqclosed--; |
305 | sqclosed--; |
283 | 306 | ||
284 | IF (get_value(x, y) != 0) |
307 | IF (get_value(x, y) != 0) |
285 | { |
308 | { |
286 | draw_square(x, y); |
309 | draw_square(x, y); |
287 | } |
310 | } |
288 | else |
311 | else |
289 | { |
312 | { |
290 | draw_square(x, y); |
313 | draw_square(x, y); |
291 | a = x; b = y; |
314 | a = x; b = y; |
292 | FOR (i = 0; i < 8; i++) |
315 | FOR (i = 0; i < 8; i++) |
293 | { |
316 | { |
294 | //a += matrix[i].a_inc; |
317 | //a += matrix[i].a_inc; |
295 | //b += matrix[i].b_inc; |
318 | //b += matrix[i].b_inc; |
296 | AL = matrix[i].a_inc; |
319 | AL = matrix[i].a_inc; |
297 | $movsx eax,al |
320 | $movsx eax,al |
298 | a += EAX; |
321 | a += EAX; |
299 | AL = matrix[i].b_inc; |
322 | AL = matrix[i].b_inc; |
300 | $movsx eax,al |
323 | $movsx eax,al |
301 | b += EAX; |
324 | b += EAX; |
302 | IF ((a >= 0) && (b >= 0) && (a < ncx) && (b < ncy) && (!get_open(a, b)) && (get_mark(a, b) != 1)) |
325 | IF ((a >= 0) && (b >= 0) && (a < ncx) && (b < ncy) && (!get_open(a, b)) && (get_mark(a, b) != 1)) |
303 | open_square(a, b); |
326 | open_square(a, b); |
304 | } |
327 | } |
305 | } |
328 | } |
306 | } // open_square |
329 | } // open_square |
- | 330 | ||
307 | 331 | ||
308 | int open_near_squares(int x, y) |
332 | int open_near_squares(int x, y) |
309 | // Îòêðûòü áëèçëåæàùèå êëåòêè (îáå êíîïêè ìûøè âìåñòå) |
333 | // Îòêðûòü áëèçëåæàùèå êëåòêè (îáå êíîïêè ìûøè âìåñòå) |
310 | { |
334 | { |
311 | int a, b, i; |
335 | int a, b, i; |
312 | dword suma = 0; |
336 | dword suma = 0; |
- | 337 | ||
- | 338 | #ifdef DEBUG |
|
- | 339 | sys_debug_write_string("MINE: open_near_squares called\n"); |
|
- | 340 | #endif |
|
313 | 341 | ||
314 | a = x; |
342 | a = x; |
315 | b = y; |
343 | b = y; |
316 | FOR (i = 0; i < 8; i++) |
344 | FOR (i = 0; i < 8; i++) |
317 | { |
345 | { |
318 | //a+=matrix[i].a_inc; |
346 | //a+=matrix[i].a_inc; |
319 | //b+=matrix[i].b_inc; |
347 | //b+=matrix[i].b_inc; |
320 | AL = matrix[i].a_inc; |
348 | AL = matrix[i].a_inc; |
321 | $movsx eax,al |
349 | $movsx eax,al |
322 | a += EAX; |
350 | a += EAX; |
323 | AL = matrix[i].b_inc; |
351 | AL = matrix[i].b_inc; |
324 | $movsx eax,al |
352 | $movsx eax,al |
325 | b += EAX; |
353 | b += EAX; |
326 | IF ((a >= 0) && (b >= 0) && (a < ncx) && (b < ncy) && (get_mark(a, b) == 1)) |
354 | IF ((a >= 0) && (b >= 0) && (a < ncx) && (b < ncy) && (get_mark(a, b) == 1)) |
327 | suma++; |
355 | suma++; |
328 | } |
356 | } |
329 | 357 | ||
330 | if (suma == get_value(x, y)) |
358 | if (suma == get_value(x, y)) |
331 | { |
359 | { |
332 | suma = 0; |
360 | suma = 0; |
333 | a = x; |
361 | a = x; |
334 | b = y; |
362 | b = y; |
335 | for (i = 0; i < 8; i++) |
363 | for (i = 0; i < 8; i++) |
336 | { |
364 | { |
337 | //a+=matrix[i].a_inc; |
365 | //a+=matrix[i].a_inc; |
338 | //b+=matrix[i].b_inc; |
366 | //b+=matrix[i].b_inc; |
339 | AL = matrix[i].a_inc; |
367 | AL = matrix[i].a_inc; |
340 | $movsx eax,al |
368 | $movsx eax,al |
341 | a += EAX; |
369 | a += EAX; |
342 | AL = matrix[i].b_inc; |
370 | AL = matrix[i].b_inc; |
343 | $movsx eax,al |
371 | $movsx eax,al |
344 | b += EAX; |
372 | b += EAX; |
345 | IF ((a >= 0) && (b >= 0) && (a < ncx) && (b < ncy) && (!get_open(a, b)) && (get_mark(a, b) != 1)) |
373 | IF ((a >= 0) && (b >= 0) && (a < ncx) && (b < ncy) && (!get_open(a, b)) && (get_mark(a, b) != 1)) |
346 | { |
374 | { |
347 | IF (get_value(a, b) == MINE) |
375 | IF (get_value(a, b) == MINE) |
348 | suma = 1; |
376 | suma = 1; |
349 | open_square(a, b); |
377 | open_square(a, b); |
350 | } |
378 | } |
351 | } |
379 | } |
352 | RETURN suma; |
380 | return suma; |
353 | } |
381 | } |
354 | ELSE |
382 | ELSE |
355 | RETURN 0; |
383 | return 0; |
356 | } // open_near_squares |
384 | } // open_near_squares |
- | 385 | ||
357 | 386 | ||
358 | void end_game() |
387 | void end_game() |
359 | { |
388 | { |
360 | int x,y; |
389 | int x,y; |
- | 390 | ||
- | 391 | #ifdef DEBUG |
|
- | 392 | sys_debug_write_string("MINE: end_game called\n"); |
|
- | 393 | #endif |
|
361 | 394 | ||
362 | stop_game = TRUE; |
395 | stop_game = TRUE; |
363 | stop_timer(); |
396 | stop_timer(); |
364 | for (x=0; x |
397 | for (x=0; x |
365 | { |
398 | { |
366 | for (y=0; y |
399 | for (y=0; y |
367 | { |
400 | { |
368 | IF (get_value(x, y) == MINE) |
401 | IF (get_value(x, y) == MINE) |
369 | { |
402 | { |
370 | set_mark(x, y, FALSE); // ñíÿòü ôëàã |
403 | set_mark(x, y, FALSE); // ñíÿòü ôëàã |
371 | open_square(x, y); |
404 | open_square(x, y); |
372 | } |
405 | } |
373 | ELSE IF (get_mark(x, y) == 1) // åñëè ìèíû íåò, à ôëàæîê åñòü |
406 | ELSE IF (get_mark(x, y) == 1) // åñëè ìèíû íåò, à ôëàæîê åñòü |
374 | { |
407 | { |
375 | EBX = XPX * x + XST; // x left |
408 | EBX = XPX * x + XST; // x left |
376 | ECX = EBX + XPX - 1; // x right |
409 | ECX = EBX + XPX - 1; // x right |
377 | EBX <<= 16; EBX += ECX; |
410 | EBX <<= 16; EBX += ECX; |
378 | $PUSH EBX |
411 | $PUSH EBX |
379 | 412 | ||
380 | ECX = YPX * y + YST; // y top |
413 | ECX = YPX * y + YST; // y top |
381 | $PUSH ECX |
414 | $PUSH ECX |
382 | EDX = ECX + YPX - 1; // y bottom |
415 | EDX = ECX + YPX - 1; // y bottom |
383 | ECX <<= 16; ECX += EDX; |
416 | ECX <<= 16; ECX += EDX; |
384 | sys_draw_line(EBX, ECX, clBlack); |
417 | sys_draw_line(EBX, ECX, clBlack); |
385 | 418 | ||
386 | $POP EDX |
419 | $POP EDX |
387 | ECX = EDX + YPX - 1; |
420 | ECX = EDX + YPX - 1; |
388 | ECX <<= 16; ECX += EDX; |
421 | ECX <<= 16; ECX += EDX; |
389 | $POP EBX |
422 | $POP EBX |
390 | sys_draw_line(EBX, ECX, clBlack); |
423 | sys_draw_line(EBX, ECX, clBlack); |
391 | CONTINUE; |
424 | CONTINUE; |
392 | } |
425 | } |
393 | } |
426 | } |
394 | } |
427 | } |
395 | } // end_game |
428 | } // end_game |
396 | 429 | ||
397 | 430 | ||
398 | void main() |
431 | void main() |
399 | { |
432 | { |
400 | sys_delay(5); // for old kernel only! |
433 | //sys_delay(5); // for old kernel only! |
401 | new_game(); |
434 | new_game(); |
402 | draw_window(); |
435 | draw_window(); |
403 | 436 | ||
404 | mouse_enable(); |
437 | mouse_enable(); |
405 | while() |
438 | while() |
406 | { |
439 | { |
407 | switch (sys_wait_event_timeout(100)) // wait for 1 second |
440 | switch (sys_wait_event_timeout(100)) // wait for 1 second |
408 | { |
441 | { |
409 | CASE evReDraw: |
442 | case evReDraw: |
410 | draw_window(); |
443 | draw_window(); |
411 | continue; |
444 | continue; |
412 | 445 | ||
413 | CASE evKey: |
446 | case evKey: |
414 | IF (sys_get_key() == 27) |
447 | IF (sys_get_key() == 27) |
415 | sys_exit_process(); |
448 | sys_exit_process(); |
416 | continue; |
449 | continue; |
417 | 450 | ||
418 | CASE evButton: |
451 | case evButton: |
419 | EAX = sys_get_button_id(); |
452 | EAX = sys_get_button_id(); |
420 | IF (EAX == 911) // new game |
453 | IF (EAX == 911) // new game |
421 | { |
454 | { |
422 | new_game(); |
455 | new_game(); |
423 | draw_squares(); |
456 | draw_squares(); |
424 | draw_time(); |
457 | draw_time(); |
425 | draw_minesi(); |
458 | draw_minesi(); |
426 | } |
459 | } |
427 | ELSE IF (EAX == 1001) // change mode |
460 | ELSE IF (EAX == 1001) // change mode |
428 | { |
461 | { |
429 | // mode++; mode%=3; mode++; |
462 | // mode++; mode%=3; mode++; |
430 | EAX = mode; EAX++; EAX = EAX%3; EAX++; mode = AL; |
463 | EAX = mode; EAX++; EAX = EAX%3; EAX++; mode = AL; |
431 | 464 | ||
432 | // get window position - ïîëó÷èòü êîîðäèíàòû îêíà |
465 | new_game(); |
433 | sys_process_info(#procinfo, -1); |
466 | EBX = ECX = -1; |
434 | xpos = procinfo.xstart; |
467 | EDX = xsize; |
435 | ypos = procinfo.ystart; |
- | |
436 | 468 | ESI = ysize; |
|
437 | // start a new process and terminate this one |
469 | EAX = 67; |
438 | sys_create_thread(#main, ESP); |
470 | $int 0x40 |
439 | sys_exit_process(); |
471 | continue; |
440 | } |
472 | } |
441 | //ELSE IF (EAX == 1002) |
473 | // ELSE IF (EAX == 1002) |
442 | //{ |
474 | // { |
443 | // start_uf(); |
475 | // start_uf(); |
444 | //} |
476 | // } |
445 | ELSE IF (EAX == 1) // close window |
477 | ELSE IF (EAX == 1) // close window |
446 | sys_exit_process(); |
478 | sys_exit_process(); |
447 | CONTINUE; |
479 | continue; |
448 | 480 | ||
449 | case evMouse: |
481 | case evMouse: |
450 | IF (!mouse_en) // is mouse enabled ? |
482 | IF (!mouse_en) // is mouse enabled ? |
451 | CONTINUE; |
483 | continue; |
452 | do_mouse(); |
484 | do_mouse(); |
453 | // wait for mouse release - æäàòü îòïóñêàíèÿ êíîïêè |
485 | // wait for mouse release - æäàòü îòïóñêàíèÿ êíîïêè |
454 | WHILE (sys_read_mouse(2) == mouse_status) |
486 | WHILE (sys_read_mouse(2) == mouse_status) |
455 | { |
487 | { |
456 | check_timer(); |
488 | check_timer(); |
457 | sys_delay(6); |
489 | sys_delay(3); |
458 | CONTINUE; |
490 | CONTINUE; |
459 | } |
491 | } |
460 | check_timer(); |
492 | check_timer(); |
461 | IF (stop_game) // disable mouse if game is stopped |
493 | IF (stop_game) // disable mouse if game is stopped |
462 | mouse_en = FALSE; |
494 | mouse_en = FALSE; |
463 | CONTINUE; |
495 | CONTINUE; |
464 | } |
496 | } |
465 | check_timer(); |
497 | check_timer(); |
466 | sys_delay(2); |
498 | sys_delay(2); |
467 | } |
499 | } |
468 | } // main=><=>=><=>=><=>>>>>>>>>>>>>>>>> |
500 | } // main=><=>=><=>=><=>>>>>>>>>>>>>>>>> |