Subversion Repositories Kolibri OS

Rev

Rev 126 | Rev 551 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*******************************************************************************
  2.  
  3.     MenuetOS MineSweeper
  4.     Copyright (C) 2003, 2004  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.  
  26.   sys_window_redraw(1);
  27.   sys_get_colors(#colors, 40);
  28.  
  29.   // WINDOW
  30.   EBX = xpos << 16 + xsize;
  31.   ECX = ypos << 16 + ysize;
  32.   sys_draw_window(EBX, ECX, 0x13CCCCCC, colors.w_grab | 0x80000000, "MineSweeper");
  33.  
  34.    // <NEW GAME> BUTTON (911)
  35.   EBX = xsize / 2 - 10;
  36.   EBX = EBX << 16 + 20;
  37.   sys_draw_button(EBX, 25<<16+20, 911, clLightGray);
  38.  
  39.   // <MAIN> BUTTON (1000)
  40. //  EBX = ncx * XPX; EBX += XST << 16;
  41. //  ECX = ncy * YPX; ECX += YST << 16;
  42. //  sys_draw_button(EBX, ECX, 1000, 0x60000000);
  43.  
  44.   // <CHANGE MODE> BUTTON (1001)
  45.   sys_draw_button(10<<16+7, 23<<16+7, 1001, 0x118811);
  46.  
  47.   // <USER FIELD> BUTTON (1002)
  48. //  sys_draw_button(20<<16+7, ECX, EDX+1, 0xddbb44);
  49.  
  50.   // <OPTIONS> BUTTON (1003)
  51.   // sys_draw_button();
  52.  
  53.   // <SCORES> BUTTON (1004)
  54.   // sys_draw_button();
  55.  
  56.   // <ABOUT> BUTTON (1005)
  57.   // sys_draw_button();
  58.  
  59.   sys_window_redraw(2);
  60.  
  61.   draw_time();     // draw timer
  62.   draw_minesi();   // draw mines
  63.   draw_squares();  // draw field
  64.  
  65. }
  66.  
  67. dword num_colors[8]=
  68. {
  69.   0x4444d0,  // 1
  70.   0x118811,  // 2
  71.   0xd04444,  // 3
  72.   0x111199,  // 4
  73.   0x991111,  // 5
  74.   0x117089,  // 6
  75.   0x000000,  // 7
  76.   0x808080   // 8
  77. };
  78.  
  79.  
  80. // ╬ЄЁшёютър юфэющ ъыхЄъш
  81. void draw_square(int x, y)
  82. {
  83.    int xl, xr, yt, yb;       // ёыхтр, ёяЁртр, ётхЁїє, ёэшчє
  84.    dword tcolor = clBlack;   // ЎтхЄ чэрўхэш  ъыхЄъш яю єьюыўрэш■ ўхЁэ√щ
  85.    byte tchar, tval;
  86.  
  87.    xl = XPX * x + XST;
  88.    xr = xl + XPX - 1;
  89.    yt = YPX * y + YST;
  90.    yb = yt + YPX - 1;
  91.  
  92.    EBX = xl << 16 + xr - xl;
  93.    ECX = yt << 16 + yb - yt;
  94.    $inc ebx
  95.    $inc ecx
  96.    sys_draw_bar(EBX, ECX, clLightGray);  // ЁшёєхЄ чръЁр°хээ√щ яЁ ьюєуюы№эшъ
  97.  
  98.    if (!get_open(x, y))
  99.    {
  100.       // Ёшёєхь Ёрьъє
  101.       ECX = yt << 16 + yb - 1;
  102.       sys_draw_line(xl<<16+xl, ECX, clWhite);
  103.       EBX = xl << 16 + xr - 1;
  104.       sys_draw_line(EBX, yt << 16 + yt, EDX);
  105.       sys_draw_line(xr << 16 + xl, yb << 16 + yb, clDarkGray);
  106.       sys_draw_line(xr << 16 + xr, yb << 16 + yt, EDX);
  107.  
  108.       SWITCH (get_mark(x, y))
  109.       {
  110.         CASE 2: tcolor = 0x121288; tchar = '?'; BREAK;
  111.         CASE 1: tcolor = 0xd04444; tchar = 'P';
  112.       }
  113.  
  114.       IF (get_mark(x,y))
  115.       {
  116.         EBX = xl + 5; EBX <<= 16; EBX += yt + 4;
  117.         sys_write_text(EBX, tcolor, #tchar, 1);
  118.         EBX += 0x00010000;
  119.         /*  ┬ЄюЁющ Ёрч - ЁхушёЄЁ√ ёюїЁрэ ■Єё   */
  120.         sys_write_text(EBX, ECX, EDX, ESI);
  121.       }
  122.    }
  123.    else          // get_open(x,y)==TRUE
  124.    {
  125.       tval = get_value(x, y);
  126.       IF (tval != 0)
  127.       {
  128.         IF (tval == MINE)
  129.         {
  130.           tcolor = 0xee1111;
  131.           tchar = '*';
  132.         }
  133.         ELSE
  134.         {
  135.           tchar = tval + '0';
  136.           tcolor = num_colors[tval-1];
  137.         }
  138.         EBX = xl + 5; EBX <<= 16; EBX += yt + 5;
  139.         sys_write_text(EBX, tcolor, #tchar, 1);
  140.         EBX += 0x00010000;
  141.         sys_write_text(EBX, ECX, EDX, ESI);
  142.       }
  143.       sys_draw_line(xl << 16 + xl, yt << 16 + yb, clDarkGray);
  144.       sys_draw_line(xl << 16 + xr, yt << 16 + yt, EDX);
  145.    }
  146. }
  147.  
  148.  
  149. // ╥рщьхЁ
  150. void draw_time()
  151. {
  152.   sys_draw_bar(XST<<16+25, 31<<16+10, 0xCCCCCC);
  153.   EBX = 0x00030000;
  154.   sys_write_number(EBX, time, XST<<16+32, 0x10ff0000);
  155. }
  156.  
  157.  
  158. // ╚эфшърЄюЁ ъюышўхёЄтр эхЁрёёЄртыхээ√ї ьшэ
  159. void draw_minesi()
  160. {
  161.   EBX = xsize - XST - 25;
  162.   $PUSH EBX
  163.   EBX = EBX << 16 + 25;
  164.   sys_draw_bar(EBX, 31<<16+10, 0xCCCCCC);
  165.   $POP EDX
  166.   EDX <<= 16; EDX += 32;
  167.   EBX = 0x00030000;
  168.   sys_write_number(EBX, cmines, EDX, 0x10ff0000);
  169. }
  170.  
  171.  
  172. // ╬ЄЁшёютър ьшээюую яюы 
  173. void draw_squares()
  174. {
  175.   int x,y;
  176.  
  177.   FOR (x=0; x < ncx; x++)
  178.     FOR (y=0; y < ncy; y++)
  179.       draw_square(x, y);
  180. }