Subversion Repositories Kolibri OS

Rev

Rev 1006 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

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