Subversion Repositories Kolibri OS

Rev

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