Subversion Repositories Kolibri OS

Rev

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