Subversion Repositories Kolibri OS

Rev

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