Subversion Repositories Kolibri OS

Rev

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