Subversion Repositories Kolibri OS

Rev

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

  1. /*
  2.    Memory Blocks for KolibriOS v1.2
  3.         Leency&Veliant Edition
  4.               2008-2020
  5. */
  6.  
  7. #define MEMSIZE 1024 * 20
  8. #define ENTRY_POINT #main
  9.  
  10. #include "..\lib\gui.h"
  11. #include "..\lib\random.h"
  12.  
  13. #include "..\lib\obj\libio.h"
  14. #include "..\lib\obj\libimg.h"
  15.  
  16. #ifndef AUTOBUILD
  17. #include "lang.h--"
  18. #endif
  19.  
  20. #define BTN_CLOSED 0
  21. #define BTN_PRESSED 1
  22. #define BTN_OPEN 2
  23.  
  24. #define CELL_SIZE 43
  25. #define PANEL_Y CELL_SIZE+4*6 + 4
  26. #define PANEL_H 36
  27. #define WIN_W CELL_SIZE+4*10 + 4
  28. #define WIN_H PANEL_Y+PANEL_H
  29.  
  30. #define ROWS 6
  31. #define COLS 10
  32. #define COUNT ROWS*COLS
  33.  
  34. #ifdef LANG_RUS
  35.         #define LABEL_NEW_GAME "®¢ ï ¨£à ";
  36. #else
  37.         #define LABEL_NEW_GAME " New game";
  38. #endif
  39.  
  40. int bitstat[COUNT], bitpict[COUNT];
  41. dword butonsx[COUNT], butonsy[COUNT];
  42. dword firstbit, secondbit;
  43. int count;
  44.  
  45.  
  46. void main()
  47. {  
  48.         dword id;
  49.         load_dll(libio,  #libio_init,1);
  50.         load_dll(libimg, #libimg_init,1);
  51.  
  52.         skin.load("/sys/icons32.png");
  53.         skin.replace_color(0x00000000, 0xFFFfff);
  54.  
  55.         NewGame();
  56.  
  57.         loop() switch(@WaitEvent())
  58.         {
  59.                 case evKey:
  60.                         if (@GetKeyScancode()==SCAN_CODE_F2) NewGame();
  61.                         break;
  62.                        
  63.                 case evButton:
  64.                         id = @GetButtonID();
  65.                         if (id==1) @ExitProcess();
  66.                         else if (id==5) NewGame();
  67.                         else {
  68.                                         id -= 100;
  69.                                         if (bitstat[id] == BTN_CLOSED)
  70.                                         {
  71.                                                 if (firstbit != 0x0BAD)
  72.                                                 {
  73.                                                         if (secondbit != 0x0BAD)
  74.                                                         {
  75.                                                                 if (bitpict[firstbit] == bitpict[secondbit])
  76.                                                                         bitstat[firstbit] = bitstat[secondbit] = BTN_OPEN;
  77.                                                                 else
  78.                                                                         bitstat[firstbit] = bitstat[secondbit] = BTN_CLOSED;
  79.                                                                 ReDraw_Game_Button(firstbit);
  80.                                                                 ReDraw_Game_Button(secondbit);
  81.                                                                 secondbit = 0x0BAD;
  82.                                                                 firstbit = id;
  83.                                                                 bitstat[id] = BTN_PRESSED;
  84.                                                                 ReDraw_Game_Button(id);
  85.                                                                 count++;
  86.                                                         }
  87.                                                         else if (firstbit != id)
  88.                                                         {
  89.                                                                 secondbit = id;
  90.                                                                 bitstat[id] = BTN_PRESSED;
  91.                                                                 ReDraw_Game_Button(id);
  92.                                                                 count++;
  93.                                                         }
  94.                                                 }
  95.                                                 else
  96.                                                 {
  97.                                                         firstbit = id;
  98.                                                         bitstat[id] = BTN_PRESSED;
  99.                                                         ReDraw_Game_Button(id);
  100.                                                         count++;
  101.                                                 }
  102.                                         }
  103.                                         Draw_Count();
  104.                         }
  105.                         break;
  106.  
  107.                 case evReDraw:
  108.                         sc.get();
  109.                         DefineAndDrawWindow(215,100,WIN_W + 9,WIN_H+4+GetSkinHeight(),
  110.                                 0x34,0xC0C0C0,"Memory Blocks",0);
  111.                         Draw_Panel();
  112.                         Draw_Game_Pole();
  113.         }
  114. }
  115.  
  116. void NewGame()
  117. {
  118.         int off;
  119.         int i;
  120.  
  121.         FOR (i = 0; i < COUNT; i++)
  122.         {
  123.                 bitstat[i] = 0;
  124.                 bitpict[i] = 0;
  125.         }
  126.  
  127.         count = 0;
  128.         firstbit = secondbit = 0x0BAD;
  129.         FOR (i = 0; i < COUNT/2; i++)
  130.         {
  131.                 do off = random(COUNT); while (bitpict[off] != 0);
  132.                 bitpict[off] = i;
  133.                 do off = random(COUNT); while (bitpict[off] != 0);
  134.                 bitpict[off] = i;
  135.         }
  136.         Draw_Game_Pole();
  137.         Draw_Panel();
  138. }
  139.  
  140. void Draw_Game_Pole()
  141. {
  142.         int i;
  143.         byte j;
  144.         for (j = 0; j < COLS; j++)      for (i = 0; i < ROWS; i++)
  145.         {
  146.                         butonsx[j*ROWS+i] = CELL_SIZE+4 * j + 4; //save coordinates to avoid
  147.                         butonsy[j*ROWS+i] = CELL_SIZE+4 * i + 4; //their recalculation after
  148.                         ReDraw_Game_Button(j*ROWS + i);
  149.         }
  150. }
  151.  
  152. void ReDraw_Game_Button(int id)
  153. {
  154.         dword xx, yy;
  155.         xx = butonsx[id];
  156.         yy = butonsy[id];
  157.         DefineButton(xx, yy, CELL_SIZE, CELL_SIZE, 100 + BT_HIDE + id, 0);
  158.         DrawRectangle3D(xx, yy, CELL_SIZE, CELL_SIZE, 0x94AECE, 0x94AECE);//border
  159.         switch (bitstat[id])
  160.         {
  161.                 case BTN_CLOSED:
  162.                         DrawRectangle3D(xx + 1, yy + 1, CELL_SIZE-2, CELL_SIZE-2, 0xFFFFFF, 0xDEDEDE);//bump
  163.                         DrawBar(xx + 2, yy + 2, CELL_SIZE-3, CELL_SIZE-3, 0xBDC7D6);//background
  164.                         break;
  165.                 case BTN_PRESSED:
  166.                         DrawWideRectangle(xx + 1, yy + 1, CELL_SIZE-1, CELL_SIZE-1, 2, 0x94DB00);//border green
  167.                         DrawBar(xx + 3, yy + 3, CELL_SIZE-5, CELL_SIZE-5, 0xFFFfff);//background
  168.                         img_draw stdcall(skin.image, xx+6, yy+6, 32, 32, 0, bitpict[id]*32);
  169.                         BREAK;
  170.                 case BTN_OPEN:
  171.                         DrawBar(xx+1, yy+1, CELL_SIZE-1, CELL_SIZE-1, 0xFFFfff);//background
  172.                         img_draw stdcall(skin.image, xx+6, yy+6, 32, 32, 0, bitpict[id]*32);
  173.         }
  174. }
  175.  
  176. void Draw_Panel()
  177. {
  178.         DrawBar(0, PANEL_Y, WIN_W, 1, sc.work_dark);
  179.         DrawBar(0, PANEL_Y+1, WIN_W, 1, sc.work_light);
  180.         DrawBar(0, PANEL_Y+2, WIN_W, PANEL_H-2, sc.work);
  181.         DefineButton(9, PANEL_Y+5, 102, 26, 5, sc.button);
  182.         WriteText(20, PANEL_Y+11, 0x90, sc.button_text, LABEL_NEW_GAME);
  183.         Draw_Count();
  184. }
  185.  
  186. void Draw_Count()
  187. {
  188.         EDI = sc.work; //writing a number with bg
  189.         WriteNumber(WIN_W-32, PANEL_Y + 12, 0xD0, sc.work_text, 3, count);
  190. }
  191.  
  192.  
  193.  
  194.  
  195. stop:
  196.