Subversion Repositories Kolibri OS

Rev

Rev 126 | Rev 964 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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