Rev 551 | Rev 6166 | Go to most recent revision | 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 | *******************************************************************************/ |
||
21 | |||
964 | leency | 22 | void draw_window() // Процедура отрисовки окна |
31 | halyavin | 23 | { |
24 | sys_window_redraw(1); |
||
25 | sys_get_colors(#colors, 40); |
||
26 | |||
27 | // WINDOW |
||
28 | EBX = xpos << 16 + xsize; |
||
29 | ECX = ypos << 16 + ysize; |
||
551 | spraid | 30 | sys_draw_window(EBX, ECX, 0x14CCCCCC, colors.w_grab | 0x80000000, "MineSweeper"); |
964 | leency | 31 | |
177 | heavyiron | 32 | // |
31 | halyavin | 33 | EBX = xsize / 2 - 10; |
34 | EBX = EBX << 16 + 20; |
||
35 | sys_draw_button(EBX, 25<<16+20, 911, clLightGray); |
||
36 | |||
37 | // |
||
38 | sys_draw_button(10<<16+7, 23<<16+7, 1001, 0x118811); |
||
39 | |||
40 | // |
||
964 | leency | 41 | //sys_draw_button(20<<16+7, ECX, EDX+1, 0xddbb44); |
31 | halyavin | 42 | |
43 | draw_time(); // draw timer |
||
44 | draw_minesi(); // draw mines |
||
45 | draw_squares(); // draw field |
||
46 | |||
964 | leency | 47 | sys_window_redraw(2); |
31 | halyavin | 48 | } |
49 | |||
50 | dword num_colors[8]= |
||
51 | { |
||
52 | 0x4444d0, // 1 |
||
53 | 0x118811, // 2 |
||
54 | 0xd04444, // 3 |
||
55 | 0x111199, // 4 |
||
56 | 0x991111, // 5 |
||
57 | 0x117089, // 6 |
||
58 | 0x000000, // 7 |
||
59 | 0x808080 // 8 |
||
60 | }; |
||
61 | |||
126 | poddubny | 62 | |
63 | // Отрисовка одной клетки |
||
31 | halyavin | 64 | void draw_square(int x, y) |
65 | { |
||
126 | poddubny | 66 | int xl, xr, yt, yb; // слева, справа, сверху, снизу |
67 | dword tcolor = clBlack; // цвет значения клетки по умолчанию черный |
||
68 | byte tchar, tval; |
||
31 | halyavin | 69 | |
70 | xl = XPX * x + XST; |
||
71 | xr = xl + XPX - 1; |
||
72 | yt = YPX * y + YST; |
||
73 | yb = yt + YPX - 1; |
||
74 | |||
964 | leency | 75 | EBX = xl+1 << 16 + xr - xl-1; |
76 | ECX = yt+1 << 16 + yb - yt-1; |
||
31 | halyavin | 77 | $inc ebx |
78 | $inc ecx |
||
126 | poddubny | 79 | sys_draw_bar(EBX, ECX, clLightGray); // рисует закрашенный прямоугольник |
31 | halyavin | 80 | |
81 | if (!get_open(x, y)) |
||
82 | { |
||
126 | poddubny | 83 | // рисуем рамку |
31 | halyavin | 84 | ECX = yt << 16 + yb - 1; |
85 | sys_draw_line(xl<<16+xl, ECX, clWhite); |
||
86 | EBX = xl << 16 + xr - 1; |
||
87 | sys_draw_line(EBX, yt << 16 + yt, EDX); |
||
88 | sys_draw_line(xr << 16 + xl, yb << 16 + yb, clDarkGray); |
||
89 | sys_draw_line(xr << 16 + xr, yb << 16 + yt, EDX); |
||
90 | |||
91 | SWITCH (get_mark(x, y)) |
||
92 | { |
||
93 | CASE 2: tcolor = 0x121288; tchar = '?'; BREAK; |
||
94 | CASE 1: tcolor = 0xd04444; tchar = 'P'; |
||
95 | } |
||
96 | |||
97 | IF (get_mark(x,y)) |
||
98 | { |
||
964 | leency | 99 | EBX = xl + 5 << 16 + yt + 4; |
31 | halyavin | 100 | sys_write_text(EBX, tcolor, #tchar, 1); |
101 | EBX += 0x00010000; |
||
102 | /* Второй раз - регистры сохраняются */ |
||
103 | sys_write_text(EBX, ECX, EDX, ESI); |
||
104 | } |
||
105 | } |
||
106 | else // get_open(x,y)==TRUE |
||
107 | { |
||
108 | tval = get_value(x, y); |
||
126 | poddubny | 109 | IF (tval != 0) |
31 | halyavin | 110 | { |
126 | poddubny | 111 | IF (tval == MINE) |
112 | { |
||
113 | tcolor = 0xee1111; |
||
114 | tchar = '*'; |
||
115 | } |
||
116 | ELSE |
||
117 | { |
||
118 | tchar = tval + '0'; |
||
119 | tcolor = num_colors[tval-1]; |
||
120 | } |
||
964 | leency | 121 | EBX = xl + 5 << 16 + yt + 5; |
126 | poddubny | 122 | sys_write_text(EBX, tcolor, #tchar, 1); |
123 | EBX += 0x00010000; |
||
124 | sys_write_text(EBX, ECX, EDX, ESI); |
||
31 | halyavin | 125 | } |
126 | sys_draw_line(xl << 16 + xl, yt << 16 + yb, clDarkGray); |
||
127 | sys_draw_line(xl << 16 + xr, yt << 16 + yt, EDX); |
||
128 | } |
||
129 | } |
||
130 | |||
126 | poddubny | 131 | |
132 | // Таймер |
||
31 | halyavin | 133 | void draw_time() |
134 | { |
||
135 | sys_draw_bar(XST<<16+25, 31<<16+10, 0xCCCCCC); |
||
964 | leency | 136 | sys_write_number(0x00030000, time, XST<<16+32, 0x10ff0000); |
31 | halyavin | 137 | } |
138 | |||
126 | poddubny | 139 | |
140 | // Индикатор количества нерасставленных мин |
||
31 | halyavin | 141 | void draw_minesi() |
142 | { |
||
143 | EBX = xsize - XST - 25; |
||
144 | $PUSH EBX |
||
145 | EBX = EBX << 16 + 25; |
||
126 | poddubny | 146 | sys_draw_bar(EBX, 31<<16+10, 0xCCCCCC); |
31 | halyavin | 147 | $POP EDX |
126 | poddubny | 148 | EDX <<= 16; EDX += 32; |
964 | leency | 149 | sys_write_number(0x00030000, cmines, EDX, 0x10ff0000); |
31 | halyavin | 150 | } |
151 | |||
126 | poddubny | 152 | |
153 | // Отрисовка минного поля |
||
31 | halyavin | 154 | void draw_squares() |
155 | { |
||
156 | int x,y; |
||
157 | |||
964 | leency | 158 | FOR (y=0; y < ncy; y++) |
159 | FOR (x=0; x < ncx; x++) |
||
31 | halyavin | 160 | draw_square(x, y); |
964 | leency | 161 | }>>=><=>16+10,><16+10,>><>16+32,><16+32,>16+10,><16+10,>16+25,><16+25,>><>><>><>><>><>><>><>><>><>><>><>><>16+xl,><16+xl,>><>><>><>16+7,><16+7,>16+7,><16+7,>16+7,><16+7,>16+20,><16+20,>><>><>><> |