Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
778 gluk 1
/*
2056 leency 2
Just Clicks v0.8
3
Copyright (C) 2011 Leency
4
 
5
Just Clicks v0.79
6
Copyright (C) 2011 clevermouse
7
 
778 gluk 8
Clickomania v0.3
9
Copyright (C) 2005 Александр Мушиков aka Olaf
10
*/
11
 
12
#pragma option meos
13
#include "lib\kolibri.h--"
14
#include "lib\random.h--"
1003 leency 15
#include "files\boxes.txt"
16
#include "files\cups.txt"
1768 clevermous 17
 
18
#ifndef AUTOBUILD
19
#include "lang.h--"
20
#endif
778 gluk 21
 
1003 leency 22
byte i,j, XX, YY;
1768 clevermous 23
system_colors sc;
2056 leency 24
proc_info Form;
1003 leency 25
 
778 gluk 26
struct
27
{
28
  byte x;
29
  byte y;
30
  byte button_id;
31
  byte mark;
32
  dword color;
1003 leency 33
}matrix[64];
778 gluk 34
 
35
 
1006 leency 36
void check_n_destroy(byte ID, ID1)
37
{
38
	IF (matrix[ID1].color == matrix[ID].color) && (matrix[ID1].mark!=1)
39
	{
40
		matrix[ID1].mark=1;
41
		destroy_button(ID1);
42
	}
43
}
778 gluk 44
 
1006 leency 45
 
1003 leency 46
void destroy_button(byte ID)
778 gluk 47
{
1006 leency 48
	check_n_destroy(ID, ID-8);
49
	check_n_destroy(ID, ID+8);
50
		IF (ID!=0)&&(ID!=8)&&(ID!=16)&&(ID!=24)&&(ID!=32)&&(ID!=40)&&(ID!=48)&&(ID!=56)
51
	check_n_destroy(ID, ID-1);
52
		IF (ID!=7)&&(ID!=15)&&(ID!=23)&&(ID!=31)&&(ID!=39)&&(ID!=47)&&(ID!=55)&&(ID!=63)
53
	check_n_destroy(ID, ID+1);
54
 
1003 leency 55
	IF (matrix[ID].xYY) YY=matrix[ID].y;}
56
	IF (matrix[ID].y>YY) {YY=matrix[ID].y;  IF (matrix[ID].x
778 gluk 57
}
58
 
1006 leency 59
 
778 gluk 60
void shift_bars(byte AA, BB)
61
byte id_curr,id_next,bz;
62
{
63
  for (j=AA;j<8;j++) for (i=BB; i>0; i--)
64
	{
65
		id_curr=i*8+j;
66
		bz=i-1;
67
		_HH:
68
		id_next=bz*8+j;
69
		IF (matrix[id_curr].mark == 1)
1822 clevermous 70
			IF (matrix[id_next].mark == 1)&&(bz>0) {bz--; GOTO _HH;}
778 gluk 71
			ELSE IF (matrix[id_next].mark == 0)
72
			{
73
				matrix[id_curr].color=matrix[id_next].color;
74
				matrix[id_curr].mark=matrix[id_next].mark;
75
				matrix[id_next].mark=1;
76
			}
77
	}
78
}
79
 
1003 leency 80
byte check_for_end()
778 gluk 81
{
1003 leency 82
	byte id_next, id_curr;
83
	for (j=0; j<64; j+=8)  for (i=0; i<8; i++)
778 gluk 84
		{
1003 leency 85
			id_curr=j+i;
86
			id_next=id_curr+1;
87
			IF (matrix[id_curr].color==matrix[id_next].color)&&(matrix[id_curr].mark==0)&&(matrix[id_next].mark==0) return 0;
88
			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 89
		}
90
	return 1;
91
}
92
 
1003 leency 93
void move_it()
94
byte but_id, count, x;
778 gluk 95
{
96
	for (x=0;x<8;x++)
97
	{
98
		count = 0;
99
		FOR (i=0;i<8;i++) IF (matrix[i*8+x].mark==1) count++;
1003 leency 100
		if (count == 8) FOR (i=0;i<8;i++)
778 gluk 101
			{
102
				XX=x;
103
				WHILE (XX<7)
104
				{
1003 leency 105
					but_id=i*8+XX;
106
					matrix[but_id].mark=matrix[but_id+1].mark;
107
					matrix[but_id].color=matrix[but_id+1].color;
108
					IF (XX == 6)	matrix[but_id+1].mark=1;
778 gluk 109
					XX++;
110
				}
111
			}
112
	}
113
}
114
 
115
 
1003 leency 116
void ReDraw_Blocks(byte newgame)
778 gluk 117
{
1003 leency 118
	byte num=0, y=22, count_blocks=0, temp[10];
778 gluk 119
	for (i=0;i<8;i++)
120
	{
121
		for (j=0;j<8;j++)
122
		{
1003 leency 123
			IF (newgame)
778 gluk 124
			{
125
				matrix[num].mark=0;
126
				XX=9; YY=0;
127
				matrix[num].color = random(5)+1;
128
			}
1003 leency 129
			DeleteButton(i*8+j);
778 gluk 130
			matrix[num].x=j;
131
			matrix[num].y=i;
132
			IF (matrix[num].mark==0)
133
				{
1006 leency 134
				DefineButton(j*21,y-22, 20, 20, num+BT_HIDE, 0);
135
				PutImage(matrix[num].color-1*1323+#img,21,21,j*21,y-22);
1768 clevermous 136
				}
137
			ELSE
138
				DrawBar(j*21,y-22,21,21, 0xB2B4BF);
778 gluk 139
			num++;
140
		}
141
		y=y+21;
142
	}
1768 clevermous 143
#ifdef LANG_RUS
144
	DrawBar(90,178,71,8,sc.work);
145
	IF (check_for_end()==1) WriteText(90,178,0x80,sc.work_text,"Результат:",10);
146
	ELSE WriteText(96,178,0x80,sc.work_text,"Осталось:",10);
147
#else
148
	DrawBar(108,178,60,8,sc.work);
149
	IF (check_for_end()==1) WriteText(108,178,0x80,sc.work_text,"Result:",10);
150
	ELSE WriteText(108,178,0x80,sc.work_text,"Blocks:",10);
151
#endif
1003 leency 152
	FOR (i=0;i<8;i++) FOR (j=0;j<8;j++) IF (matrix[j*8+i].mark==0) count_blocks++;
1768 clevermous 153
	WriteNumber(150,178,0x80,sc.work_text,count_blocks);
1003 leency 154
	//
155
	if (check_for_end()==1) && (count_blocks<8)
156
	{
1768 clevermous 157
		DrawFlatButton();
158
#ifdef LANG_RUS
1003 leency 159
		IF (count_blocks==0) copystr(" Лучше всех!", #temp);
160
		IF (count_blocks==1) copystr("  Прекрасно", #temp);
161
		IF (count_blocks==2) copystr("Очень хорошо!", #temp);
1768 clevermous 162
#else
163
		IF (count_blocks==0) copystr("The best!", #temp);
164
		IF (count_blocks==1) copystr("Wonderful", #temp);
165
		IF (count_blocks==2) copystr("Very good", #temp);
166
#endif
1003 leency 167
		IF (count_blocks>=3) //баг!!!
168
		{
1768 clevermous 169
#ifdef LANG_RUS
1003 leency 170
			copystr("   Неплохо", #temp);
1768 clevermous 171
#else
172
			copystr(" Not bed", #temp);
173
#endif
1003 leency 174
			count_blocks=3;
175
		}
1768 clevermous 176
		PutImage(count_blocks*4662+#cups,42,37,63,48);
177
#ifdef LANG_RUS
1006 leency 178
		WriteText(46,91,0x80,0x0,#temp,0);
1768 clevermous 179
#else
180
		WriteText(58,91,0x80,0x0,#temp,0);
181
#endif
1003 leency 182
	}
778 gluk 183
}
184
 
1003 leency 185
 
186
void main()
1768 clevermous 187
{	byte id;
188
	//randomize();
1003 leency 189
	ReDraw_Blocks(1);
190
	loop()
191
	{
192
		switch(WaitEvent())
193
		{
1006 leency 194
			CASE evKey:
195
				IF (GetKey()==051) ReDraw_Blocks(1); //New game
196
				break;
1003 leency 197
			CASE evButton:
198
				id=GetButtonID();
199
				IF (id==255) ExitProcess();
1006 leency 200
				IF (id==254) ReDraw_Blocks(1); //New game
201
				IF (id<65) //Color Button
202
				{
203
     				destroy_button(id);
204
					IF (XX!=9)
205
					{
206
						shift_bars(XX,YY);
207
						IF (YY==7) {move_it();move_it();}
208
						XX=9;
209
						YY=0;
210
						ReDraw_Blocks(0);
211
					}
212
				}
213
				break;
1003 leency 214
			case evReDraw:
2056 leency 215
				DefineAndDrawWindow(400,276,177,201+GetSkinWidth(),0x74,0x10B2B4BF,0,0,"Just Clicks v0.8");
216
				DefineButton(150,-18,18,18,255+BT_HIDE+BT_NOFRAME,0); //кнопочка закрытия :]
2250 leency 217
				GetProcessInfo(#Form, SelfInfo);
2056 leency 218
				IF (Form.height==GetSkinWidth()+3) BREAK;
1768 clevermous 219
				sc.get();
220
				DrawBar(0,168,168,29,sc.work); //панелька снизу
221
#ifdef LANG_RUS
222
				DefineButton(9,172,76,19,254,sc.work_button);
223
				WriteText(16,178,0x80,sc.work_button_text,"Заново (F2)",0);
224
#else
225
				DefineButton(9,172,86,19,254,sc.work_button);
226
				WriteText(15,178,0x80,sc.work_button_text,"New game (F2)",0);
227
#endif
1003 leency 228
				ReDraw_Blocks(0);
229
		}
230
	}
778 gluk 231
}
232
 
1768 clevermous 233
 
234
void DrawFlatButton()
235
{
236
	DrawBar(21,42,125,1,0x94AECE); //полоса гор сверху
237
	DrawBar(21,104,125,1,0x94AECE); //полоса гор снизу
238
	DrawBar(21,42,1,62,0x94AECE); //полоса верт слева
239
	DrawBar(146,42,1,63,0x94AECE); //полоса верт справа
240
	DrawBar(22,43,124,1,0xFFFFFF); //полоса гор белая
241
	DrawBar(22,103,123,1,0xC7C7C7); //тень верт
242
	DrawBar(22,43,1,61,0xFFFFFF); //полоса верт белая
243
	DrawBar(145,44,1,60,0xC7C7C7); //тень верт
244
	DrawBar(23,44,122,59,0xE4DFE1); //заливка
245
}
246
 
778 gluk 247
stop: