Subversion Repositories Kolibri OS

Rev

Rev 1003 | 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.  
  16. byte i,j, XX, YY;
  17.  
  18. struct
  19. {
  20.   byte x;
  21.   byte y;
  22.   byte button_id;
  23.   byte mark;
  24.   dword color;
  25. }matrix[64];
  26.  
  27.  
  28. void check_n_destroy(byte ID, ID1)
  29. {
  30.         IF (matrix[ID1].color == matrix[ID].color) && (matrix[ID1].mark!=1)
  31.         {
  32.                 matrix[ID1].mark=1;
  33.                 destroy_button(ID1);
  34.         }
  35. }
  36.  
  37.  
  38. void destroy_button(byte ID)
  39. {
  40.         check_n_destroy(ID, ID-8);
  41.         check_n_destroy(ID, ID+8);
  42.                 IF (ID!=0)&&(ID!=8)&&(ID!=16)&&(ID!=24)&&(ID!=32)&&(ID!=40)&&(ID!=48)&&(ID!=56)
  43.         check_n_destroy(ID, ID-1);
  44.                 IF (ID!=7)&&(ID!=15)&&(ID!=23)&&(ID!=31)&&(ID!=39)&&(ID!=47)&&(ID!=55)&&(ID!=63)
  45.         check_n_destroy(ID, ID+1);
  46.  
  47.         IF (matrix[ID].x<XX) {XX=matrix[ID].x;  IF (matrix[ID].y>YY) YY=matrix[ID].y;}
  48.         IF (matrix[ID].y>YY) {YY=matrix[ID].y;  IF (matrix[ID].x<XX) XX=matrix[ID].x;}
  49. }
  50.  
  51.  
  52. void shift_bars(byte AA, BB)
  53. byte id_curr,id_next,bz;
  54. {
  55.   for (j=AA;j<8;j++) for (i=BB; i>0; i--)
  56.         {
  57.                 id_curr=i*8+j;
  58.                 bz=i-1;
  59.                 _HH:
  60.                 id_next=bz*8+j;
  61.                 IF (matrix[id_curr].mark == 1)
  62.                         IF (bz>0)&&(matrix[id_next].mark == 1) {bz--; GOTO _HH;}
  63.                         ELSE IF (matrix[id_next].mark == 0)
  64.                         {
  65.                                 matrix[id_curr].color=matrix[id_next].color;
  66.                                 matrix[id_curr].mark=matrix[id_next].mark;
  67.                                 matrix[id_next].mark=1;
  68.                         }
  69.         }
  70. }
  71.  
  72. byte check_for_end()
  73. {
  74.         byte id_next, id_curr;
  75.         for (j=0; j<64; j+=8)  for (i=0; i<8; i++)
  76.                 {
  77.                         id_curr=j+i;
  78.                         id_next=id_curr+1;
  79.                         IF (matrix[id_curr].color==matrix[id_next].color)&&(matrix[id_curr].mark==0)&&(matrix[id_next].mark==0) return 0;
  80.                         IF (matrix[id_curr].color==matrix[id_next+7].color)&&(matrix[id_curr].mark==0)&&(matrix[id_next+7].mark==0) return 0;
  81.                 }
  82.         return 1;
  83. }
  84.  
  85. void move_it()
  86. byte but_id, count, x;
  87. {
  88.         for (x=0;x<8;x++)
  89.         {
  90.                 count = 0;
  91.                 FOR (i=0;i<8;i++) IF (matrix[i*8+x].mark==1) count++;
  92.                 if (count == 8) FOR (i=0;i<8;i++)
  93.                         {
  94.                                 XX=x;
  95.                                 WHILE (XX<7)
  96.                                 {
  97.                                         but_id=i*8+XX;
  98.                                         matrix[but_id].mark=matrix[but_id+1].mark;
  99.                                         matrix[but_id].color=matrix[but_id+1].color;
  100.                                         IF (XX == 6)    matrix[but_id+1].mark=1;
  101.                                         XX++;
  102.                                 }
  103.                         }
  104.         }
  105. }
  106.  
  107.  
  108. void ReDraw_Blocks(byte newgame)
  109. {
  110.         byte num=0, y=22, count_blocks=0, temp[10];
  111.         for (i=0;i<8;i++)
  112.         {
  113.                 for (j=0;j<8;j++)
  114.                 {
  115.                         IF (newgame)
  116.                         {
  117.                                 matrix[num].mark=0;
  118.                                 XX=9; YY=0;
  119.                                 matrix[num].color = random(5)+1;
  120.                         }
  121.                         DeleteButton(i*8+j);
  122.                         matrix[num].x=j;
  123.                         matrix[num].y=i;
  124.                         IF (matrix[num].mark==0)
  125.                                 {
  126.                                 DefineButton(j*21,y-22, 20, 20, num+BT_HIDE, 0);
  127.                                 PutImage(matrix[num].color-1*1323+#img,21,21,j*21,y-22);
  128.                                 }       ELSE DrawBar(j*21,y-22,21,21, 0xB2B4BF);
  129.                         num++;
  130.                 }
  131.                 y=y+21;
  132.         }
  133.         DrawBar(90,178,71,8,0xE4DFE1);
  134.         IF (check_for_end()==1) WriteText(90,178,0x80,0,"¥§ã«ìâ â:",10);
  135.         ELSE WriteText(96,178,0x80,0,"Žáâ «®áì:",10);
  136.         FOR (i=0;i<8;i++) FOR (j=0;j<8;j++) IF (matrix[j*8+i].mark==0) count_blocks++;
  137.         WriteNumber(150,178,0x80,0,count_blocks);
  138.         //
  139.         if (check_for_end()==1) && (count_blocks<8)
  140.         {
  141.                 DrawFlatButton(21,42,125,62,0,0xE4DFE1,"");
  142.                 IF (count_blocks==0) copystr(" ‹ãçè¥ ¢á¥å!", #temp);  
  143.                 IF (count_blocks==1) copystr("  à¥ªà á­®", #temp);
  144.                 IF (count_blocks==2) copystr("Žç¥­ì å®à®è®!", #temp);
  145.                 IF (count_blocks>=3) //¡ £!!!
  146.                 {
  147.                         copystr("   ¥¯«®å®", #temp);
  148.                         count_blocks=3;
  149.                 }
  150.                 PutImage(count_blocks*42*37*3+#cups,42,37,63,48);
  151.                 WriteText(46,91,0x80,0x0,#temp,0);
  152.         }
  153. }
  154.  
  155.  
  156. void main()
  157. {       byte id, skin_width;
  158.         randomize();
  159.         ReDraw_Blocks(1);
  160.         loop()
  161.         {
  162.                 switch(WaitEvent())
  163.                 {
  164.                         CASE evKey:
  165.                                 IF (GetKey()==051) ReDraw_Blocks(1); //New game
  166.                                 break;
  167.                         CASE evButton:
  168.                                 id=GetButtonID();
  169.                                 IF (id==255) ExitProcess();
  170.                                 IF (id==254) ReDraw_Blocks(1); //New game
  171.                                 IF (id<65) //Color Button
  172.                                 {      
  173.                                 destroy_button(id);
  174.                                         IF (XX!=9)
  175.                                         {
  176.                                                 shift_bars(XX,YY);
  177.                                                 IF (YY==7) {move_it();move_it();}
  178.                                                 XX=9;
  179.                                                 YY=0;
  180.                                                 ReDraw_Blocks(0);
  181.                                         }
  182.                                 }    
  183.                                 break;
  184.                         case evReDraw:
  185.                                 WindowRedrawStatus(1);
  186.                                 skin_width = GetSkinWidth();
  187.                                 DefineAndDrawWindow(400,276,177,201+skin_width,0x74,0x10B2B4BF,0,0,"Just Clicks v0.76");
  188.                                 DefineButton(150,2-skin_width,18,18,255+BT_HIDE+BT_NOFRAME,0x0866CC00);
  189.                                 DrawBar(0,168,168,29,0xE4DFE1);
  190.                                 //DrawFlatButton(9,172,84,19,254,0xE4DFE1,"New game (F2)");
  191.                                 DrawFlatButton(4,172,80,19,254,0xE4DFE1,"‡ ­®¢® (F2)");
  192.                                 ReDraw_Blocks(0);
  193.                                 WindowRedrawStatus(2);
  194.                 }
  195.         }
  196. }
  197.  
  198. stop:
  199.