Subversion Repositories Kolibri OS

Rev

Rev 109 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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