Subversion Repositories Kolibri OS

Rev

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