Rev 6166 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6166 | Rev 7661 | ||
---|---|---|---|
1 | /******************************************************************************* |
1 | /******************************************************************************* |
2 | 2 | ||
3 | MenuetOS MineSweeper |
3 | MenuetOS MineSweeper |
4 | Copyright (C) 2003, 2004 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 | ?define HEADER_Y 4 |
|
- | 22 | ?define BTNSIZE 19 |
|
- | 23 | char game_mode[] = "1/3"; |
|
21 | 24 | ||
22 | void draw_window() // Ïðîöåäóðà îòðèñîâêè îêíà |
25 | void draw_window() // Ïðîöåäóðà îòðèñîâêè îêíà |
23 | { |
26 | { |
24 | sys_get_colors(#colors, 40); |
27 | sys_get_colors(#colors, 40); |
25 | 28 | ||
26 | // WINDOW |
29 | // WINDOW |
27 | sys_window_redraw(1); |
30 | sys_window_redraw(1); |
28 | EBX = xpos << 16 + xsize; |
31 | EBX = xpos << 16 + xsize + 9; |
29 | ECX = ypos << 16 + ysize; |
32 | ECX = ypos << 16 + ysize; |
30 | sys_draw_window(EBX, ECX, 0x14CCCCCC, colors.w_work | 0x80000000, "MineSweeper"); |
33 | sys_draw_window(EBX, ECX, 0x34CCCCCC, colors.w_work | 0x80000000, "MineSweeper"); |
31 | sys_window_redraw(2); |
34 | sys_window_redraw(2); |
32 | 35 | ||
33 | // Leency ROLLED UP FIX |
36 | // Leency ROLLED UP FIX |
34 | sys_process_info(#procinfo, -1); |
37 | sys_process_info(#procinfo, -1); |
35 | IF (procinfo.ysize<70) return; |
38 | IF (procinfo.ysize<70) return; |
36 | 39 | ||
37 | // |
40 | // |
38 | EBX = xsize / 2 - 10; |
41 | EBX = xsize / 2 - 10; |
39 | EBX = EBX << 16 + 20; |
42 | EBX = EBX << 16 + BTNSIZE; |
40 | sys_draw_button(EBX, 25<<16+20, 911, clLightGray); |
43 | sys_draw_button(EBX, HEADER_Y<<16+BTNSIZE, 911+BT_HIDE, clLightGray); |
- | 44 | draw_rectangle(xsize/2-10,HEADER_Y,BTNSIZE,BTNSIZE,clWhite,clDarkGray); |
|
41 | 45 | ||
42 | // |
46 | // |
- | 47 | sys_draw_button(5<<16+32, HEADER_Y<<16+BTNSIZE, 1001+BT_HIDE, clLightGray); |
|
- | 48 | draw_rectangle(5,HEADER_Y,32,BTNSIZE,clWhite,clDarkGray); |
|
- | 49 | game_mode[0] = mode + '0'; |
|
43 | sys_draw_button(10<<16+7, 23<<16+7, 1001, 0x118811); |
50 | sys_write_text(9<<16+HEADER_Y+3, 0x90000000+clDarkGray, #game_mode, 3); |
44 | 51 | ||
45 | // |
52 | // |
46 | //sys_draw_button(20<<16+7, ECX, EDX+1, 0xddbb44); |
53 | //sys_draw_button(BTNSIZE<<16+7, ECX, EDX+1, 0xddbb44); |
47 | 54 | ||
48 | draw_time(); // draw timer |
55 | draw_time(); // draw timer |
49 | draw_minesi(); // draw mines |
56 | draw_mines_left(); // draw mines |
50 | draw_squares(); // draw field |
57 | draw_squares(); // draw field |
51 | } |
58 | } |
52 | 59 | ||
53 | dword num_colors[8]= |
60 | dword num_colors[8]= |
54 | { |
61 | { |
55 | 0x4444d0, // 1 |
62 | 0x4444d0, // 1 |
56 | 0x118811, // 2 |
63 | 0x118811, // 2 |
57 | 0xd04444, // 3 |
64 | 0xd04444, // 3 |
58 | 0x111199, // 4 |
65 | 0x111199, // 4 |
59 | 0x991111, // 5 |
66 | 0x991111, // 5 |
60 | 0x117089, // 6 |
67 | 0x117089, // 6 |
61 | 0x000000, // 7 |
68 | 0x000000, // 7 |
62 | 0x808080 // 8 |
69 | 0x808080 // 8 |
63 | }; |
70 | }; |
64 | 71 | ||
65 | 72 | ||
66 | // Îòðèñîâêà îäíîé êëåòêè |
73 | // Îòðèñîâêà îäíîé êëåòêè |
67 | void draw_square(int x, y) |
74 | void draw_square(int x, y) |
68 | { |
75 | { |
69 | int xl, xr, yt, yb; // ñëåâà, ñïðàâà, ñâåðõó, ñíèçó |
76 | int xl, xr, yt, yb; // ñëåâà, ñïðàâà, ñâåðõó, ñíèçó |
70 | dword tcolor = clBlack; // öâåò çíà÷åíèÿ êëåòêè ïî óìîë÷àíèþ ÷åðíûé |
77 | dword tcolor = clBlack; // öâåò çíà÷åíèÿ êëåòêè ïî óìîë÷àíèþ ÷åðíûé |
71 | byte tchar, tval; |
78 | byte tchar, tval; |
72 | 79 | ||
73 | xl = XPX * x + XST; |
80 | xl = XPX * x + XST; |
74 | xr = xl + XPX - 1; |
81 | xr = xl + XPX - 1; |
75 | yt = YPX * y + YST; |
82 | yt = YPX * y + YST; |
76 | yb = yt + YPX - 1; |
83 | yb = yt + YPX - 1; |
77 | 84 | ||
78 | EBX = xl+1 << 16 + xr - xl-1; |
85 | EBX = xl+1 << 16 + xr - xl-1; |
79 | ECX = yt+1 << 16 + yb - yt-1; |
86 | ECX = yt+1 << 16 + yb - yt-1; |
80 | $inc ebx |
87 | $inc ebx |
81 | $inc ecx |
88 | $inc ecx |
82 | sys_draw_bar(EBX, ECX, clLightGray); // ðèñóåò çàêðàøåííûé ïðÿìîóãîëüíèê |
89 | sys_draw_bar(EBX, ECX, clLightGray); // ðèñóåò çàêðàøåííûé ïðÿìîóãîëüíèê |
83 | 90 | ||
84 | if (!get_open(x, y)) |
91 | if (!get_open(x, y)) |
85 | { |
92 | { |
86 | // ðèñóåì ðàìêó |
93 | // ðèñóåì ðàìêó |
87 | ECX = yt << 16 + yb - 1; |
94 | ECX = yt << 16 + yb - 1; |
88 | sys_draw_line(xl<<16+xl, ECX, clWhite); |
95 | sys_draw_line(xl<<16+xl, ECX, clWhite); |
89 | EBX = xl << 16 + xr - 1; |
96 | EBX = xl << 16 + xr - 1; |
90 | sys_draw_line(EBX, yt << 16 + yt, EDX); |
97 | sys_draw_line(EBX, yt << 16 + yt, EDX); |
91 | sys_draw_line(xr << 16 + xl, yb << 16 + yb, clDarkGray); |
98 | sys_draw_line(xr << 16 + xl, yb << 16 + yb, clDarkGray); |
92 | sys_draw_line(xr << 16 + xr, yb << 16 + yt, EDX); |
99 | sys_draw_line(xr << 16 + xr, yb << 16 + yt, EDX); |
93 | 100 | ||
94 | SWITCH (get_mark(x, y)) |
101 | SWITCH (get_mark(x, y)) |
95 | { |
102 | { |
96 | CASE 2: tcolor = 0x121288; tchar = '?'; BREAK; |
103 | CASE 2: tcolor = 0x121288; tchar = '?'; BREAK; |
97 | CASE 1: tcolor = 0xd04444; tchar = 'P'; |
104 | CASE 1: tcolor = 0xd04444; tchar = 'P'; |
98 | } |
105 | } |
99 | 106 | ||
100 | IF (get_mark(x,y)) |
107 | IF (get_mark(x,y)) |
101 | { |
108 | { |
102 | EBX = xl + 5 << 16 + yt + 4; |
109 | EBX = xl + 5 << 16 + yt + 4; |
103 | sys_write_text(EBX, tcolor, #tchar, 1); |
110 | sys_write_text(EBX, tcolor, #tchar, 1); |
104 | EBX += 0x00010000; |
111 | EBX += 0x00010000; |
105 | /* Âòîðîé ðàç - ðåãèñòðû ñîõðàíÿþòñÿ */ |
112 | /* Âòîðîé ðàç - ðåãèñòðû ñîõðàíÿþòñÿ */ |
106 | sys_write_text(EBX, ECX, EDX, ESI); |
113 | sys_write_text(EBX, ECX, EDX, ESI); |
107 | } |
114 | } |
108 | } |
115 | } |
109 | else // get_open(x,y)==TRUE |
116 | else // get_open(x,y)==TRUE |
110 | { |
117 | { |
111 | tval = get_value(x, y); |
118 | tval = get_value(x, y); |
112 | IF (tval != 0) |
119 | IF (tval != 0) |
113 | { |
120 | { |
114 | IF (tval == MINE) |
121 | IF (tval == MINE) |
115 | { |
122 | { |
116 | tcolor = 0xee1111; |
123 | tcolor = 0xee1111; |
117 | tchar = '*'; |
124 | tchar = '*'; |
118 | } |
125 | } |
119 | ELSE |
126 | ELSE |
120 | { |
127 | { |
121 | tchar = tval + '0'; |
128 | tchar = tval + '0'; |
122 | tcolor = num_colors[tval-1]; |
129 | tcolor = num_colors[tval-1]; |
123 | } |
130 | } |
124 | EBX = xl + 5 << 16 + yt + 5; |
131 | EBX = xl + 5 << 16 + yt + 5; |
125 | sys_write_text(EBX, tcolor, #tchar, 1); |
132 | sys_write_text(EBX, tcolor, #tchar, 1); |
126 | EBX += 0x00010000; |
133 | EBX += 0x00010000; |
127 | sys_write_text(EBX, ECX, EDX, ESI); |
134 | sys_write_text(EBX, ECX, EDX, ESI); |
128 | } |
135 | } |
129 | sys_draw_line(xl << 16 + xl, yt << 16 + yb, clDarkGray); |
136 | sys_draw_line(xl << 16 + xl, yt << 16 + yb, clDarkGray); |
130 | sys_draw_line(xl << 16 + xr, yt << 16 + yt, EDX); |
137 | sys_draw_line(xl << 16 + xr, yt << 16 + yt, EDX); |
131 | } |
138 | } |
132 | } |
139 | } |
133 | - | ||
134 | - | ||
135 | // Òàéìåð |
140 | |
136 | void draw_time() |
141 | void draw_time() |
137 | { |
142 | { |
138 | sys_draw_bar(XST<<16+25, 31<<16+14, 0xCCCCCC); |
143 | sys_draw_bar(xsize-XST-58<<16+29, HEADER_Y<<16+20, clWhiteGray); |
139 | sys_write_number(0x00030000, time, XST<<16+32, 0x10ff0000); |
144 | sys_write_number(0x00030000, time, xsize-XST-56<<16+HEADER_Y+3, 0x101166C3); |
140 | } |
145 | } |
141 | 146 | ||
142 | - | ||
143 | // Èíäèêàòîð êîëè÷åñòâà íåðàññòàâëåííûõ ìèí |
147 | |
144 | void draw_minesi() |
148 | void draw_mines_left() |
145 | { |
- | |
146 | EBX = xsize - XST - 25; |
- | |
147 | $PUSH EBX |
- | |
148 | EBX = EBX << 16 + 25; |
149 | { |
149 | sys_draw_bar(EBX, 31<<16+14, 0xCCCCCC); |
- | |
150 | $POP EDX |
- | |
151 | EDX <<= 16; EDX += 32; |
150 | sys_draw_bar(xsize-XST-29<<16+29, HEADER_Y<<16+20, clWhiteGray); |
152 | sys_write_number(0x00030000, cmines, EDX, 0x10ff0000); |
151 | sys_write_number(0x00030000, cmines, xsize-XST-27<<16+HEADER_Y+3, 0x10ff0000); |
153 | } |
152 | } |
154 | 153 | ||
155 | 154 | ||
156 | // Îòðèñîâêà ìèííîãî ïîëÿ |
155 | // Îòðèñîâêà ìèííîãî ïîëÿ |
157 | void draw_squares() |
156 | void draw_squares() |
158 | { |
157 | { |
159 | int x,y; |
158 | int x,y; |
160 | 159 | ||
161 | FOR (y=0; y < ncy; y++) |
160 | FOR (y=0; y < ncy; y++) |
162 | FOR (x=0; x < ncx; x++) |
161 | FOR (x=0; x < ncx; x++) |
163 | draw_square(x, y); |
162 | draw_square(x, y); |
164 | }>>=><=>16+14,><16+14,>><>16+32,><16+32,>16+14,><16+14,>16+25,><16+25,>><>><>><>><>><>><>><>><>><>><>><>><>16+xl,><16+xl,>><>><>><>16+7,><16+7,>16+7,><16+7,>16+7,><16+7,>16+20,><16+20,>><>70)>><>><> |
163 | } |
- | 164 | ||
- | 165 | void draw_rectangle(dword x,y,w,h,color1,color2) |
|
- | 166 | { |
|
- | 167 | sys_draw_bar(x<<16+w+1,y<<16+1,color1); |
|
- | 168 | sys_draw_bar(x<<16+1,y+1<<16+h-1,color1); |
|
- | 169 | sys_draw_bar(x+w<<16+1,y+1<<16+h,color2); |
|
- | 170 | sys_draw_bar(x<<16+w,y+h<<16+1,color2); |
|
- | 171 | }16+1,color2); |
|
165 | 172 | }><16+1,color2); |
|
- | 173 | }>16+w,y+h<<16+1,color2); |
|
- | 174 | }><16+w,y+h<<16+1,color2); |
|
- | 175 | }>16+h,color2); |
|
- | 176 | ><16+h,color2); |
|
- | 177 | >16+1,y+1<<16+h,color2); |
|
- | 178 | ><16+1,y+1<<16+h,color2); |
|
- | 179 | >16+h-1,color1); |
|
- | 180 | ><16+h-1,color1); |
|
- | 181 | >16+1,y+1<<16+h-1,color1); |
|
- | 182 | ><16+1,y+1<<16+h-1,color1); |
|
- | 183 | >16+1,color1); |
|
- | 184 | ><16+1,color1); |
|
- | 185 | >16+w+1,y<<16+1,color1); |
|
- | 186 | ><16+w+1,y<<16+1,color1); |
|
- | 187 | >>>16+HEADER_Y+3,><16+HEADER_Y+3,>16+20,><16+20,>16+29,><16+29,>16+HEADER_Y+3,><16+HEADER_Y+3,>16+20,><16+20,>16+29,><16+29,>><>><>><>><>><>><>><>><>><>><>><>><>16+xl,><16+xl,>><>><>><>16+7,><16+7,>16+HEADER_Y+3,><16+HEADER_Y+3,>16+BTNSIZE,><16+BTNSIZE,>16+32,><16+32,>16+BTNSIZE,><16+BTNSIZE,>><>70)>><>><> |