Subversion Repositories Kolibri OS

Rev

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