Subversion Repositories Kolibri OS

Rev

Rev 778 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
778 gluk 1
/*
1003 leency 2
Just Clicks v0.75
3
Copyright (C) 2008 Leency
778 gluk 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--"
1003 leency 12
#include "files\boxes.txt"
13
#include "files\cups.txt"
778 gluk 14
 
15
 
1003 leency 16
byte i,j, XX, YY;
17
 
778 gluk 18
struct
19
{
20
  byte x;
21
  byte y;
22
  byte button_id;
23
  byte mark;
24
  dword color;
1003 leency 25
}matrix[64];
778 gluk 26
 
27
 
28
 
1003 leency 29
void destroy_button(byte ID)
778 gluk 30
{
1003 leency 31
	IF (matrix[ID-8].color == matrix[ID].color) && (matrix[ID-8].mark!=1)
32
	{
778 gluk 33
		matrix[ID-8].mark=1;
34
		destroy_button(ID-8);
35
	}
1003 leency 36
	IF (matrix[ID+8].color == matrix[ID].color) && (matrix[ID+8].mark!=1)
37
	{
778 gluk 38
		matrix[ID+8].mark=1;
39
		destroy_button(ID+8);
40
	}
1003 leency 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].xYY) YY=matrix[ID].y;}
54
	IF (matrix[ID].y>YY) {YY=matrix[ID].y;  IF (matrix[ID].x
778 gluk 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
 
1003 leency 77
byte check_for_end()
778 gluk 78
{
1003 leency 79
	byte id_next, id_curr;
80
	for (j=0; j<64; j+=8)  for (i=0; i<8; i++)
778 gluk 81
		{
1003 leency 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;
778 gluk 86
		}
87
	return 1;
88
}
89
 
1003 leency 90
void move_it()
91
byte but_id, count, x;
778 gluk 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++;
1003 leency 97
		if (count == 8) FOR (i=0;i<8;i++)
778 gluk 98
			{
99
				XX=x;
100
				WHILE (XX<7)
101
				{
1003 leency 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;
778 gluk 106
					XX++;
107
				}
108
			}
109
	}
110
}
111
 
112
 
1003 leency 113
void ReDraw_Blocks(byte newgame)
778 gluk 114
{
1003 leency 115
	byte num=0, y=22, count_blocks=0, temp[10];
778 gluk 116
	for (i=0;i<8;i++)
117
	{
118
		for (j=0;j<8;j++)
119
		{
1003 leency 120
			IF (newgame)
778 gluk 121
			{
122
				matrix[num].mark=0;
123
				XX=9; YY=0;
124
				matrix[num].color = random(5)+1;
125
			}
1003 leency 126
			DeleteButton(i*8+j);
778 gluk 127
			matrix[num].x=j;
128
			matrix[num].y=i;
129
			IF (matrix[num].mark==0)
130
				{
1003 leency 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);
778 gluk 133
				}	ELSE DrawBar(j*21+5,y-22,21,21, 0xB2B4BF);
134
			num++;
135
		}
136
		y=y+21;
137
	}
1003 leency 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
	}
778 gluk 158
}
159
 
1003 leency 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
	}
778 gluk 199
}
200
 
201
stop: