Subversion Repositories Kolibri OS

Rev

Rev 7221 | Blame | Last modification | View Log | Download | RSS feed

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