Subversion Repositories Kolibri OS

Rev

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

  1. /*
  2. Just Clicks v0.4
  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 "files\kolibri.h--"
  12. #include "files\random.h--"
  13.  
  14. //«®ª «¨§ æ¨ï ¨ ­ áâனª¨
  15. dword header = "Just Clicks v0.4 L&V";
  16. //
  17.  
  18. byte y, i, count, need_redraw, num, id, mark, XX, YY;    //j,
  19.  
  20. struct
  21. {
  22.   byte x;
  23.   byte y;
  24.   byte button_id;
  25.   byte mark;
  26.   dword color;
  27. }matrix[8*8];
  28.  
  29. inline fastcall void sys_draw_button(dword EBX, ECX, EDX, ESI)
  30. { EAX = 8;  $int 0x40 }
  31.  
  32.  
  33. void destroy_button(dword ID)
  34. dword dest_color;
  35. {
  36.         dest_color=matrix[ID].color;
  37.         IF ((matrix[ID-8].color == dest_color)&&(matrix[ID-8].mark!=1)){
  38.                 matrix[ID-8].mark=1;
  39.                 need_redraw=1;
  40.                 destroy_button(ID-8);
  41.         }
  42.         IF ((matrix[ID+8].color == dest_color)&&(matrix[ID+8].mark!=1)){
  43.                 matrix[ID+8].mark=1;
  44.                 need_redraw=1;
  45.                 destroy_button(ID+8);
  46.         }
  47.         IF ((ID!=0)&&(ID!=8)&&(ID!=16)&&(ID!=24)&&(ID!=32)&&(ID!=40)&&(ID!=48)&&(ID!=56)){
  48.         IF ((matrix[ID-1].color == dest_color)&&(matrix[ID-1].mark!=1)){
  49.                         matrix[ID-1].mark=1;
  50.                         need_redraw=1;
  51.                         destroy_button(ID-1);
  52.         }
  53.         }
  54.         IF ((ID!=7)&&(ID!=15)&&(ID!=23)&&(ID!=31)&&(ID!=39)&&(ID!=47)&&(ID!=55)&&(ID!=63)){
  55.             IF ((matrix[ID+1].color == dest_color)&&(matrix[ID+1].mark!=1)){
  56.                         matrix[ID+1].mark=1;
  57.                         need_redraw=1;
  58.                         destroy_button(ID+1);
  59.                 }
  60.         }
  61.         IF (matrix[ID].x<XX){
  62.                 XX=matrix[ID].x;
  63.                 IF (matrix[ID].y>YY) YY=matrix[ID].y;
  64.         }
  65.         IF (matrix[ID].y>YY){
  66.                 YY=matrix[ID].y;
  67.             IF (matrix[ID].x<XX)        XX=matrix[ID].x;
  68.         }
  69. }
  70.  
  71. void shift_bars(byte AA, BB)
  72. byte id_curr,id_next,bz;
  73. {
  74.   for (j=AA;j<8;j++)
  75.   {
  76.         i=BB;
  77.         while (i>0)
  78.         {
  79.                 id_curr=i*8+j;
  80.                 bz=i-1;
  81.                 _HH:
  82.                 id_next=bz*8+j;
  83.                 IF (matrix[id_curr].mark == 1){
  84.                         IF (bz>0)&&(matrix[id_next].mark == 1){
  85.                                 bz--;
  86.                                 GOTO _HH;
  87.                         }ELSE IF (matrix[id_next].mark == 0){
  88.                                 matrix[id_curr].color=matrix[id_next].color;
  89.                                 matrix[id_curr].mark=matrix[id_next].mark;
  90.                                 matrix[id_next].mark=1;
  91.                         }
  92.                 };
  93.                 i--;
  94.         }
  95.   }
  96. }
  97.  
  98. byte count_blocks()
  99. byte kol_vo;
  100. {
  101.         kol_vo=0;
  102.         FOR (i=0;i<8;i++) FOR (j=0;j<8;j++) IF (matrix[j*8+i].mark==0) kol_vo++;
  103.         return kol_vo;
  104. }
  105.  
  106.  
  107. byte check_for_end ()
  108. byte end, id_next_two, id_next_one, crr;
  109. {
  110.         end=1;
  111.         j=0;
  112.         while (end==1)&&(j<8){
  113.                 i=0;
  114.                 while (end==1)&&(i<8)
  115.                 {
  116.                         crr=j*8+i;
  117.                         id_next_one=crr+1;
  118.                         id_next_two=j+1;
  119.                         id_next_two=id_next_two*8+i;
  120.                         IF(matrix[crr].color==matrix[id_next_one].color)&&(matrix[crr].mark==0)&&(matrix[id_next_one].mark==0)&&(i<7)   end=0;
  121.                         IF (matrix[crr].color==matrix[id_next_two].color)&&(matrix[crr].mark==0)&&(matrix[id_next_two].mark==0) end=0;
  122.                         i++;
  123.                 }
  124.                 j++;
  125.         }
  126.         return end;
  127. }
  128.  
  129. void move_it ()
  130. byte but_id, but_id_curr,but_id_next, x, y, xx, yy;
  131. {
  132.         for (x=0;x<8;x++){
  133.                 count = 0;
  134.                 FOR (y=0;y<8;y++)
  135.                 {
  136.                         but_id=y*8+x;
  137.                         IF (matrix[but_id].mark==1) count++;
  138.                 }
  139.                 if (count == 8) for (yy=0;yy<8;yy++)
  140.                         {
  141.                                 xx=x;
  142.                                 WHILE (xx<7)
  143.                                 {
  144.                                         but_id_curr=yy*8+xx;
  145.                                         but_id_next=yy*8+xx+1;
  146.                                         matrix[but_id_curr].mark=matrix[but_id_next].mark;
  147.                                         matrix[but_id_curr].color=matrix[but_id_next].color;
  148.                                         matrix[but_id_next].mark=1;
  149.                                         IF (xx+1 == 7)  matrix[but_id_next].mark=1;
  150.                                         xx++;
  151.                                 }
  152.                         }
  153.         }
  154. }
  155.  
  156.  
  157. void main()
  158. {
  159.         randomize();
  160.         ReDraw_Blocks(1);
  161.         loop()
  162.         {
  163.                 switch(WaitEvent())
  164.                 {
  165.                         CASE evButton:
  166.                                 id=GetButtonID();
  167.                                 IF (id==600) {ExitProcess(); break;}
  168.                                 ELSE IF (id==500) {ReDraw_Blocks(1);break;}
  169.                                 ELSE    {
  170.                                         destroy_button(id);
  171.                                                 IF (XX!=9)&&(need_redraw==1)
  172.                                                 {
  173.                                                 shift_bars(XX,YY);
  174.                                                 IF (YY == 7) {move_it();move_it();}
  175.                                                 XX=9;
  176.                                                 YY=0;
  177.                                                 ReDraw_Blocks(0);
  178.                                                 }
  179.                                                 break;
  180.                                         }
  181.                         case evKey: IF (GetKey()==051) ReDraw_Blocks(1); break;//New game
  182.                         case evReDraw:  draw_window();  break;
  183.                 }
  184.         }
  185.         ExitProcess();
  186. }
  187.  
  188. void ReDraw_Blocks(dword newgame)
  189. {
  190.         num=0;
  191.         for (i=0;i<8;i++) FOR (j=0;j<8;j++) DefineButton(1,1,1,1,i*8+j+BT_DEL,1);
  192.         y=skin_width;
  193.         for (i=0;i<8;i++)
  194.         {
  195.                 for (j=0;j<8;j++)
  196.                 {
  197.                         if (newgame == 1)
  198.                         {
  199.                                 matrix[num].mark=0;
  200.                                 XX=9;
  201.                                 YY=0;
  202.                                 SWITCH (random(5))
  203.                                 {
  204.                                    CASE 0: matrix[num].color=0x083366CC;BREAK; //Brown
  205.                                    CASE 1: matrix[num].color=0x08FF3333;BREAK; //Red
  206.                                    CASE 2: matrix[num].color=0x0866CC00;BREAK; //Green
  207.                                    CASE 3: matrix[num].color=0x0833CCFF;BREAK; //light Blue
  208.                                    CASE 4: matrix[num].color=0x08FF9900;          //Orange
  209.                                 };
  210.                         }
  211.                         mark=matrix[num].mark;
  212.                         matrix[num].x=j;
  213.                         matrix[num].y=i;
  214.                         IF (mark==0) sys_draw_button(j*21+5 << 16 + 20, y << 16 + 20, num, matrix[num].color);
  215.                                 ELSE kos_DrawBar(j*21+5 << 16 + 21, y << 16 + 21, 0xB2B4BF);
  216.                         num++;
  217.                 }
  218.                 y=y+21;
  219.         }
  220.         EDI = 0x00E4DFE1;  //梥⠯ ­¥«¨
  221.         IF (check_for_end()==1) WriteText(95,184,0xC0,0x000000,"¥§ã«ìâ â:",10);
  222.         ELSE {
  223.                 WriteText(95,184,0xC0,0x000000," Žáâ «®áì:",10);
  224.                 WriteText(155,184,0xC0,0x000000,IntToStr(count_blocks()),0); //«®ª®¢ ®áâ «®áì
  225.                 }
  226.         need_redraw=0; newgame=0;
  227. }
  228.  
  229. void draw_window()
  230. {
  231.         WindowRedrawStatus(1);
  232.         skin_width = GetSkinWidth();
  233.         DefineAndDrawWindow(300,176,177,201+skin_width,0x04,0x00B2B4BF,0,0,0);
  234.         DefineButton(155,2-skin_width,18,18,600+BT_HIDE+BT_NOFRAME,0x0866CC00); //ª­®¯ª  § ªàëâ¨ï
  235.         DrawTitle(#header);
  236.         DrawBar(5,168,168,29,0xE4DFE1); //¯®«¥ á­¨§ã
  237.         DrawFlatButton(9,172,84,19,500,0xE4DFE1); //New
  238.                 WriteText(14,178,0x80,0x5F86B6,"New game (F2) ",14);
  239.         WriteText(95,172,0x80,0,"  “஢¥­ì:01",10); //“஢¥­ì
  240.         ReDraw_Blocks(0);
  241.         WindowRedrawStatus(2);
  242. }
  243.  
  244. stop:
  245.