Subversion Repositories Kolibri OS

Rev

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