Rev 6166 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
31 | halyavin | 1 | /******************************************************************************* |
2 | |||
3 | MenuetOS MineSweeper |
||
126 | poddubny | 4 | Copyright (C) 2003, 2004 Ivan Poddubny |
31 | halyavin | 5 | |
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 |
||
8 | the Free Software Foundation; either version 2 of the License, or |
||
9 | (at your option) any later version. |
||
10 | |||
11 | This program is distributed in the hope that it will be useful, |
||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
14 | GNU General Public License for more details. |
||
15 | |||
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 |
||
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
19 | |||
20 | *******************************************************************************/ |
||
7661 | leency | 21 | ?define HEADER_Y 4 |
22 | ?define BTNSIZE 19 |
||
23 | char game_mode[] = "1/3"; |
||
31 | halyavin | 24 | |
964 | leency | 25 | void draw_window() // Процедура отрисовки окна |
31 | halyavin | 26 | { |
27 | sys_get_colors(#colors, 40); |
||
28 | |||
29 | // WINDOW |
||
2060 | leency | 30 | sys_window_redraw(1); |
7661 | leency | 31 | EBX = xpos << 16 + xsize + 9; |
31 | halyavin | 32 | ECX = ypos << 16 + ysize; |
7661 | leency | 33 | sys_draw_window(EBX, ECX, 0x34CCCCCC, colors.w_work | 0x80000000, "MineSweeper"); |
2060 | leency | 34 | sys_window_redraw(2); |
35 | |||
36 | // Leency ROLLED UP FIX |
||
37 | sys_process_info(#procinfo, -1); |
||
38 | IF (procinfo.ysize<70) return; |
||
964 | leency | 39 | |
7661 | leency | 40 | // |
31 | halyavin | 41 | EBX = xsize / 2 - 10; |
7661 | leency | 42 | EBX = EBX << 16 + BTNSIZE; |
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); |
||
31 | halyavin | 45 | |
46 | // |
||
7661 | leency | 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'; |
||
50 | sys_write_text(9<<16+HEADER_Y+3, 0x90000000+clDarkGray, #game_mode, 3); |
||
31 | halyavin | 51 | |
52 | // |
||
7661 | leency | 53 | //sys_draw_button(BTNSIZE<<16+7, ECX, EDX+1, 0xddbb44); |
31 | halyavin | 54 | |
55 | draw_time(); // draw timer |
||
7661 | leency | 56 | draw_mines_left(); // draw mines |
31 | halyavin | 57 | draw_squares(); // draw field |
58 | } |
||
59 | |||
60 | dword num_colors[8]= |
||
61 | { |
||
62 | 0x4444d0, // 1 |
||
63 | 0x118811, // 2 |
||
64 | 0xd04444, // 3 |
||
65 | 0x111199, // 4 |
||
66 | 0x991111, // 5 |
||
67 | 0x117089, // 6 |
||
68 | 0x000000, // 7 |
||
69 | 0x808080 // 8 |
||
70 | }; |
||
71 | |||
126 | poddubny | 72 | |
73 | // Отрисовка одной клетки |
||
31 | halyavin | 74 | void draw_square(int x, y) |
75 | { |
||
126 | poddubny | 76 | int xl, xr, yt, yb; // слева, справа, сверху, снизу |
77 | dword tcolor = clBlack; // цвет значения клетки по умолчанию черный |
||
78 | byte tchar, tval; |
||
31 | halyavin | 79 | |
80 | xl = XPX * x + XST; |
||
81 | xr = xl + XPX - 1; |
||
82 | yt = YPX * y + YST; |
||
83 | yb = yt + YPX - 1; |
||
84 | |||
964 | leency | 85 | EBX = xl+1 << 16 + xr - xl-1; |
86 | ECX = yt+1 << 16 + yb - yt-1; |
||
31 | halyavin | 87 | $inc ebx |
88 | $inc ecx |
||
126 | poddubny | 89 | sys_draw_bar(EBX, ECX, clLightGray); // рисует закрашенный прямоугольник |
31 | halyavin | 90 | |
91 | if (!get_open(x, y)) |
||
92 | { |
||
126 | poddubny | 93 | // рисуем рамку |
31 | halyavin | 94 | ECX = yt << 16 + yb - 1; |
95 | sys_draw_line(xl<<16+xl, ECX, clWhite); |
||
96 | EBX = xl << 16 + xr - 1; |
||
97 | sys_draw_line(EBX, yt << 16 + yt, EDX); |
||
98 | sys_draw_line(xr << 16 + xl, yb << 16 + yb, clDarkGray); |
||
99 | sys_draw_line(xr << 16 + xr, yb << 16 + yt, EDX); |
||
100 | |||
101 | SWITCH (get_mark(x, y)) |
||
102 | { |
||
103 | CASE 2: tcolor = 0x121288; tchar = '?'; BREAK; |
||
104 | CASE 1: tcolor = 0xd04444; tchar = 'P'; |
||
105 | } |
||
106 | |||
107 | IF (get_mark(x,y)) |
||
108 | { |
||
964 | leency | 109 | EBX = xl + 5 << 16 + yt + 4; |
31 | halyavin | 110 | sys_write_text(EBX, tcolor, #tchar, 1); |
111 | EBX += 0x00010000; |
||
112 | /* Второй раз - регистры сохраняются */ |
||
113 | sys_write_text(EBX, ECX, EDX, ESI); |
||
114 | } |
||
115 | } |
||
116 | else // get_open(x,y)==TRUE |
||
117 | { |
||
118 | tval = get_value(x, y); |
||
126 | poddubny | 119 | IF (tval != 0) |
31 | halyavin | 120 | { |
126 | poddubny | 121 | IF (tval == MINE) |
122 | { |
||
123 | tcolor = 0xee1111; |
||
124 | tchar = '*'; |
||
125 | } |
||
126 | ELSE |
||
127 | { |
||
128 | tchar = tval + '0'; |
||
129 | tcolor = num_colors[tval-1]; |
||
130 | } |
||
964 | leency | 131 | EBX = xl + 5 << 16 + yt + 5; |
126 | poddubny | 132 | sys_write_text(EBX, tcolor, #tchar, 1); |
133 | EBX += 0x00010000; |
||
134 | sys_write_text(EBX, ECX, EDX, ESI); |
||
31 | halyavin | 135 | } |
136 | sys_draw_line(xl << 16 + xl, yt << 16 + yb, clDarkGray); |
||
137 | sys_draw_line(xl << 16 + xr, yt << 16 + yt, EDX); |
||
138 | } |
||
139 | } |
||
140 | |||
141 | void draw_time() |
||
142 | { |
||
7661 | leency | 143 | sys_draw_bar(xsize-XST-58<<16+29, HEADER_Y<<16+20, clWhiteGray); |
144 | sys_write_number(0x00030000, time, xsize-XST-56<<16+HEADER_Y+3, 0x101166C3); |
||
31 | halyavin | 145 | } |
146 | |||
126 | poddubny | 147 | |
7661 | leency | 148 | void draw_mines_left() |
31 | halyavin | 149 | { |
7661 | leency | 150 | sys_draw_bar(xsize-XST-29<<16+29, HEADER_Y<<16+20, clWhiteGray); |
151 | sys_write_number(0x00030000, cmines, xsize-XST-27<<16+HEADER_Y+3, 0x10ff0000); |
||
31 | halyavin | 152 | } |
153 | |||
126 | poddubny | 154 | |
155 | // Отрисовка минного поля |
||
31 | halyavin | 156 | void draw_squares() |
157 | { |
||
158 | int x,y; |
||
159 | |||
964 | leency | 160 | FOR (y=0; y < ncy; y++) |
161 | FOR (x=0; x < ncx; x++) |
||
31 | halyavin | 162 | draw_square(x, y); |
964 | leency | 163 | } |
7661 | leency | 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); |