Subversion Repositories Kolibri OS

Rev

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

  1. /*
  2. Just Clicks v0.6
  3. Copyright (C) 2008 Leency & Veliant
  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. #jumptomain NONE
  11. #include "lib\kolibri.h--"
  12. #include "lib\random.h--"
  13. #include "img.txt"
  14.  
  15. byte i, need_redraw, XX, YY;
  16.  
  17. struct
  18. {
  19.   byte x;
  20.   byte y;
  21.   byte button_id;
  22.   byte mark;
  23.   dword color;
  24. }matrix[8*8];
  25.  
  26.  
  27.  
  28. void destroy_button(dword ID)
  29. {
  30.         IF ((matrix[ID-8].color == matrix[ID].color)&&(matrix[ID-8].mark!=1)){
  31.                 matrix[ID-8].mark=1;
  32.                 need_redraw=1;
  33.                 destroy_button(ID-8);
  34.         }
  35.         IF ((matrix[ID+8].color == matrix[ID].color)&&(matrix[ID+8].mark!=1)){
  36.                 matrix[ID+8].mark=1;
  37.                 need_redraw=1;
  38.                 destroy_button(ID+8);
  39.         }
  40.         IF ((ID!=0)&&(ID!=8)&&(ID!=16)&&(ID!=24)&&(ID!=32)&&(ID!=40)&&(ID!=48)&&(ID!=56))
  41.                 IF ((matrix[ID-1].color == matrix[ID].color)&&(matrix[ID-1].mark!=1)){
  42.                         matrix[ID-1].mark=1;
  43.                         need_redraw=1;
  44.                         destroy_button(ID-1);
  45.                 }
  46.         IF ((ID!=7)&&(ID!=15)&&(ID!=23)&&(ID!=31)&&(ID!=39)&&(ID!=47)&&(ID!=55)&&(ID!=63))
  47.             IF ((matrix[ID+1].color == matrix[ID].color)&&(matrix[ID+1].mark!=1)){
  48.                         matrix[ID+1].mark=1;
  49.                         need_redraw=1;
  50.                         destroy_button(ID+1);
  51.                 }
  52.         IF (matrix[ID].x<XX){XX=matrix[ID].x;  IF (matrix[ID].y>YY) YY=matrix[ID].y;}
  53.         IF (matrix[ID].y>YY){YY=matrix[ID].y;  IF (matrix[ID].x<XX) XX=matrix[ID].x;}
  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 count_blocks()
  77. {
  78.         byte kol_vo=0;
  79.         FOR (i=0;i<8;i++) FOR (j=0;j<8;j++) IF (matrix[j*8+i].mark==0) kol_vo++;
  80.         return kol_vo;
  81. }
  82.  
  83.  
  84. byte check_for_end ()
  85. byte id_next_two, id_next_one, crr;
  86. {
  87.         for (j=0; j<8; j++)     for (i=0; i<8; i++)
  88.                 {
  89.                         crr=j*8+i;
  90.                         id_next_one=crr+1;
  91.                         id_next_two=j+1*8+i;
  92.                         IF (matrix[crr].color==matrix[id_next_one].color)&&(matrix[crr].mark==0)&&(matrix[id_next_one].mark==0) return 0;
  93.                         IF (matrix[crr].color==matrix[id_next_two].color)&&(matrix[crr].mark==0)&&(matrix[id_next_two].mark==0) return 0;
  94.                 }
  95.         return 1;
  96. }
  97.  
  98. void move_it ()
  99. byte but_id_curr,but_id_next, count, x;
  100. {
  101.         for (x=0;x<8;x++)
  102.         {
  103.                 count = 0;
  104.                 FOR (i=0;i<8;i++) IF (matrix[i*8+x].mark==1) count++;
  105.                 if (count == 8) for (i=0;i<8;i++)
  106.                         {
  107.                                 XX=x;
  108.                                 WHILE (XX<7)
  109.                                 {
  110.                                         but_id_curr=i*8+XX;
  111.                                         but_id_next=i*8+XX+1;
  112.                                         matrix[but_id_curr].mark=matrix[but_id_next].mark;
  113.                                         matrix[but_id_curr].color=matrix[but_id_next].color;
  114.                                         matrix[but_id_next].mark=1;
  115.                                         IF (XX+1 == 7)  matrix[but_id_next].mark=1;
  116.                                         XX++;
  117.                                 }
  118.                         }
  119.         }
  120. }
  121.  
  122.  
  123. void main()
  124. {       dword id;
  125.         randomize();
  126.         skin_width = GetSkinWidth();
  127.         ReDraw_Blocks(1);
  128.         loop()
  129.         {
  130.                 switch(WaitEvent())
  131.                 {
  132.                         CASE evButton:
  133.                                 id=GetButtonID();
  134.                                 IF (id==600) {ExitProcess(); break;}
  135.                                 ELSE IF (id==500) {ReDraw_Blocks(1);break;}
  136.                                 ELSE    {
  137.                                         destroy_button(id);
  138.                                                 IF (XX!=9)&&(need_redraw==1)
  139.                                                 {
  140.                                                 shift_bars(XX,YY);
  141.                                                 IF (YY == 7) {move_it();move_it();}
  142.                                                 XX=9;
  143.                                                 YY=0;
  144.                                                 ReDraw_Blocks(0);
  145.                                                 }
  146.                                                 break;
  147.                                         }
  148.                         case evKey: IF (GetKey()==051) ReDraw_Blocks(1); break;//New game
  149.                         case evReDraw:  draw_window();  break;
  150.                 }
  151.         }
  152.         ExitProcess();
  153. }
  154.  
  155. void ReDraw_Blocks(dword newgame)
  156. {
  157.         dword num=0, y;
  158.         y=skin_width;
  159.         for (i=0;i<8;i++)
  160.         {
  161.                 for (j=0;j<8;j++)
  162.                 {
  163.                         IF (newgame == 1)
  164.                         {
  165.                                 matrix[num].mark=0;
  166.                                 XX=9; YY=0;
  167.                                 matrix[num].color = random(5)+1;
  168.                         }
  169.                         DefineButton(1,1,1,1,i*8+j+BT_DEL,1);
  170.                         matrix[num].x=j;
  171.                         matrix[num].y=i;
  172.                         IF (matrix[num].mark==0)
  173.                                 {
  174.                                 DefineButton(j*21+5,y-22, 20, 20, num+BT_HIDE, matrix[num].color);
  175.                                 PutImage(matrix[num].color-1*21*21*3+#img,21,21,j*21+5,y-22);
  176.                                 }       ELSE DrawBar(j*21+5,y-22,21,21, 0xB2B4BF);
  177.                         num++;
  178.                 }
  179.                 y=y+21;
  180.         }
  181.         EDI = 0x00E4DFE1;  //梥⠯ ­¥«¨
  182.         IF (check_for_end()==1) WriteText(95,178,0xC0,0x000000,"¥§ã«ìâ â:",10); //184
  183.                 ELSE WriteText(95,178,0xC0,0x000000," Žáâ «®áì:",10);
  184.         WriteText(155,178,0xC0,0x000000,IntToStr(count_blocks()),0); //«®ª®¢ ®áâ «®áì
  185.                 IF (count_blocks()<10) DrawBar(161,178,6,8,0xE4DFE1);
  186.         need_redraw=0;
  187. }
  188.  
  189. void draw_window()
  190. {
  191.         WindowRedrawStatus(1);
  192.         DefineAndDrawWindow(300,176,177,201+skin_width,0x04,0x00B2B4BF,0,0,0);
  193.         DefineButton(155,2-skin_width,18,18,600+BT_HIDE+BT_NOFRAME,0x0866CC00); //ª­®¯ª  § ªàëâ¨ï
  194.         DrawTitle("Just Clicks v0.6 L&V");
  195.         DrawBar(5,168,168,29,0xE4DFE1); //¯®«¥ á­¨§ã
  196.         DrawFlatButton(9,172,84,19,500,0xE4DFE1); //New E4DFE1
  197.                 WriteText(14,178,0x80,0,"New game (F2) ",14);
  198.         //WriteText(95,172,0x80,0,"  “஢¥­ì:01",10); //“஢¥­ì
  199.         ReDraw_Blocks(0);
  200.         WindowRedrawStatus(2);
  201. }
  202.  
  203. stop:
  204.