Subversion Repositories Kolibri OS

Rev

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

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