Subversion Repositories Kolibri OS

Rev

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

  1. /*
  2. Just Clicks v0.8
  3. Copyright (C) 2011 Leency
  4.  
  5. Just Clicks v0.79
  6. Copyright (C) 2011 clevermouse
  7.  
  8. Clickomania v0.3
  9. Copyright (C) 2005 €«¥ªá ­¤à Œã訪®¢ aka Olaf
  10. */
  11.  
  12. #pragma option meos
  13. #include "lib\kolibri.h--"
  14. #include "lib\random.h--"
  15. #include "files\boxes.txt"
  16. #include "files\cups.txt"
  17.  
  18. #ifndef AUTOBUILD
  19. #include "lang.h--"
  20. #endif
  21.  
  22. byte i,j, XX, YY;
  23. system_colors sc;
  24. proc_info Form;
  25.  
  26. struct
  27. {
  28.   byte x;
  29.   byte y;
  30.   byte button_id;
  31.   byte mark;
  32.   dword color;
  33. }matrix[64];
  34.  
  35.  
  36. void check_n_destroy(byte ID, ID1)
  37. {
  38.         IF (matrix[ID1].color == matrix[ID].color) && (matrix[ID1].mark!=1)
  39.         {
  40.                 matrix[ID1].mark=1;
  41.                 destroy_button(ID1);
  42.         }
  43. }
  44.  
  45.  
  46. void destroy_button(byte ID)
  47. {
  48.         check_n_destroy(ID, ID-8);
  49.         check_n_destroy(ID, ID+8);
  50.                 IF (ID!=0)&&(ID!=8)&&(ID!=16)&&(ID!=24)&&(ID!=32)&&(ID!=40)&&(ID!=48)&&(ID!=56)
  51.         check_n_destroy(ID, ID-1);
  52.                 IF (ID!=7)&&(ID!=15)&&(ID!=23)&&(ID!=31)&&(ID!=39)&&(ID!=47)&&(ID!=55)&&(ID!=63)
  53.         check_n_destroy(ID, ID+1);
  54.  
  55.         IF (matrix[ID].x<XX) {XX=matrix[ID].x;  IF (matrix[ID].y>YY) YY=matrix[ID].y;}
  56.         IF (matrix[ID].y>YY) {YY=matrix[ID].y;  IF (matrix[ID].x<XX) XX=matrix[ID].x;}
  57. }
  58.  
  59.  
  60. void shift_bars(byte AA, BB)
  61. byte id_curr,id_next,bz;
  62. {
  63.   for (j=AA;j<8;j++) for (i=BB; i>0; i--)
  64.         {
  65.                 id_curr=i*8+j;
  66.                 bz=i-1;
  67.                 _HH:
  68.                 id_next=bz*8+j;
  69.                 IF (matrix[id_curr].mark == 1)
  70.                         IF (matrix[id_next].mark == 1)&&(bz>0) {bz--; GOTO _HH;}
  71.                         ELSE IF (matrix[id_next].mark == 0)
  72.                         {
  73.                                 matrix[id_curr].color=matrix[id_next].color;
  74.                                 matrix[id_curr].mark=matrix[id_next].mark;
  75.                                 matrix[id_next].mark=1;
  76.                         }
  77.         }
  78. }
  79.  
  80. byte check_for_end()
  81. {
  82.         byte id_next, id_curr;
  83.         for (j=0; j<64; j+=8)  for (i=0; i<8; i++)
  84.                 {
  85.                         id_curr=j+i;
  86.                         id_next=id_curr+1;
  87.                         IF (matrix[id_curr].color==matrix[id_next].color)&&(matrix[id_curr].mark==0)&&(matrix[id_next].mark==0) return 0;
  88.                         IF (matrix[id_curr].color==matrix[id_next+7].color)&&(matrix[id_curr].mark==0)&&(matrix[id_next+7].mark==0) return 0;
  89.                 }
  90.         return 1;
  91. }
  92.  
  93. void move_it()
  94. byte but_id, count, x;
  95. {
  96.         for (x=0;x<8;x++)
  97.         {
  98.                 count = 0;
  99.                 FOR (i=0;i<8;i++) IF (matrix[i*8+x].mark==1) count++;
  100.                 if (count == 8) FOR (i=0;i<8;i++)
  101.                         {
  102.                                 XX=x;
  103.                                 WHILE (XX<7)
  104.                                 {
  105.                                         but_id=i*8+XX;
  106.                                         matrix[but_id].mark=matrix[but_id+1].mark;
  107.                                         matrix[but_id].color=matrix[but_id+1].color;
  108.                                         IF (XX == 6)    matrix[but_id+1].mark=1;
  109.                                         XX++;
  110.                                 }
  111.                         }
  112.         }
  113. }
  114.  
  115.  
  116. void ReDraw_Blocks(byte newgame)
  117. {
  118.         byte num=0, y=22, count_blocks=0, temp[10];
  119.         for (i=0;i<8;i++)
  120.         {
  121.                 for (j=0;j<8;j++)
  122.                 {
  123.                         IF (newgame)
  124.                         {
  125.                                 matrix[num].mark=0;
  126.                                 XX=9; YY=0;
  127.                                 matrix[num].color = random(5)+1;
  128.                         }
  129.                         DeleteButton(i*8+j);
  130.                         matrix[num].x=j;
  131.                         matrix[num].y=i;
  132.                         IF (matrix[num].mark==0)
  133.                                 {
  134.                                 DefineButton(j*21,y-22, 20, 20, num+BT_HIDE, 0);
  135.                                 PutImage(matrix[num].color-1*1323+#img,21,21,j*21,y-22);
  136.                                 }
  137.                         ELSE
  138.                                 DrawBar(j*21,y-22,21,21, 0xB2B4BF);
  139.                         num++;
  140.                 }
  141.                 y=y+21;
  142.         }
  143. #ifdef LANG_RUS
  144.         DrawBar(90,178,71,8,sc.work);
  145.         IF (check_for_end()==1) WriteText(90,178,0x80,sc.work_text,"¥§ã«ìâ â:",10);
  146.         ELSE WriteText(96,178,0x80,sc.work_text,"Žáâ «®áì:",10);
  147. #else
  148.         DrawBar(108,178,60,8,sc.work);
  149.         IF (check_for_end()==1) WriteText(108,178,0x80,sc.work_text,"Result:",10);
  150.         ELSE WriteText(108,178,0x80,sc.work_text,"Blocks:",10);
  151. #endif
  152.         FOR (i=0;i<8;i++) FOR (j=0;j<8;j++) IF (matrix[j*8+i].mark==0) count_blocks++;
  153.         WriteNumber(150,178,0x80,sc.work_text,count_blocks);
  154.         //
  155.         if (check_for_end()==1) && (count_blocks<8)
  156.         {
  157.                 DrawFlatButton();
  158. #ifdef LANG_RUS
  159.                 IF (count_blocks==0) copystr(" ‹ãçè¥ ¢á¥å!", #temp);  
  160.                 IF (count_blocks==1) copystr("  à¥ªà á­®", #temp);
  161.                 IF (count_blocks==2) copystr("Žç¥­ì å®à®è®!", #temp);
  162. #else
  163.                 IF (count_blocks==0) copystr("The best!", #temp);
  164.                 IF (count_blocks==1) copystr("Wonderful", #temp);
  165.                 IF (count_blocks==2) copystr("Very good", #temp);
  166. #endif
  167.                 IF (count_blocks>=3) //¡ £!!!
  168.                 {
  169. #ifdef LANG_RUS
  170.                         copystr("   ¥¯«®å®", #temp);
  171. #else
  172.                         copystr(" Not bed", #temp);
  173. #endif
  174.                         count_blocks=3;
  175.                 }
  176.                 PutImage(count_blocks*4662+#cups,42,37,63,48);
  177. #ifdef LANG_RUS
  178.                 WriteText(46,91,0x80,0x0,#temp,0);
  179. #else
  180.                 WriteText(58,91,0x80,0x0,#temp,0);
  181. #endif
  182.         }
  183. }
  184.  
  185.  
  186. void main()
  187. {       byte id;
  188.         //randomize();
  189.         ReDraw_Blocks(1);
  190.         loop()
  191.         {
  192.                 switch(WaitEvent())
  193.                 {
  194.                         CASE evKey:
  195.                                 IF (GetKey()==051) ReDraw_Blocks(1); //New game
  196.                                 break;
  197.                         CASE evButton:
  198.                                 id=GetButtonID();
  199.                                 IF (id==255) ExitProcess();
  200.                                 IF (id==254) ReDraw_Blocks(1); //New game
  201.                                 IF (id<65) //Color Button
  202.                                 {      
  203.                                 destroy_button(id);
  204.                                         IF (XX!=9)
  205.                                         {
  206.                                                 shift_bars(XX,YY);
  207.                                                 IF (YY==7) {move_it();move_it();}
  208.                                                 XX=9;
  209.                                                 YY=0;
  210.                                                 ReDraw_Blocks(0);
  211.                                         }
  212.                                 }    
  213.                                 break;
  214.                         case evReDraw:
  215.                                 DefineAndDrawWindow(400,276,177,201+GetSkinWidth(),0x74,0x10B2B4BF,0,0,"Just Clicks v0.8");
  216.                                 DefineButton(150,-18,18,18,255+BT_HIDE+BT_NOFRAME,0); //ª­®¯®çª  § ªàëâ¨ï :]
  217.                                 GetProcessInfo(#Form, SelfInfo);
  218.                                 IF (Form.height==GetSkinWidth()+3) BREAK;
  219.                                 sc.get();
  220.                                 DrawBar(0,168,168,29,sc.work); //¯ ­¥«ìª  á­¨§ã
  221. #ifdef LANG_RUS
  222.                                 DefineButton(9,172,76,19,254,sc.work_button);
  223.                                 WriteText(16,178,0x80,sc.work_button_text,"‡ ­®¢® (F2)",0);
  224. #else
  225.                                 DefineButton(9,172,86,19,254,sc.work_button);
  226.                                 WriteText(15,178,0x80,sc.work_button_text,"New game (F2)",0);
  227. #endif
  228.                                 ReDraw_Blocks(0);
  229.                 }
  230.         }
  231. }
  232.  
  233.  
  234. void DrawFlatButton()
  235. {
  236.         DrawBar(21,42,125,1,0x94AECE); //¯®«®á  £®à ᢥàåã
  237.         DrawBar(21,104,125,1,0x94AECE); //¯®«®á  £®à á­¨§ã
  238.         DrawBar(21,42,1,62,0x94AECE); //¯®«®á  ¢¥àâ á«¥¢ 
  239.         DrawBar(146,42,1,63,0x94AECE); //¯®«®á  ¢¥àâ á¯à ¢ 
  240.         DrawBar(22,43,124,1,0xFFFFFF); //¯®«®á  £®à ¡¥« ï
  241.         DrawBar(22,103,123,1,0xC7C7C7); //â¥­ì ¢¥àâ
  242.         DrawBar(22,43,1,61,0xFFFFFF); //¯®«®á  ¢¥àâ ¡¥« ï
  243.         DrawBar(145,44,1,60,0xC7C7C7); //â¥­ì ¢¥àâ
  244.         DrawBar(23,44,122,59,0xE4DFE1); //§ «¨¢ª 
  245. }
  246.  
  247. stop:
  248.