2011-10-19 02:30:16 +04:00
//Leency 06.10.2011, Flood-it! v2.4, GPL
2011-10-06 20:06:15 +04:00
# include "lib\kolibri.h"
# include "lib\random.h"
# ifndef AUTOBUILD
# include "lang.h--"
# endif
system_colors sc ;
proc_info Form ;
dword stak [ 100 ] ; //<2F> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
int DIFFICULTY_LEV_PARAMS [ ] = { 28 , 14 , 25 , //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD>
17 , 28 , 50 } ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
//<2F> <> -<2D> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> "<22> <> <EFBFBD> <EFBFBD> <EFBFBD> "
int BLOCK_SIZE = 28 ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
int BLOCKS_NUM = 14 ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <20> <20> <> Y
int MAX_CLICKS = 25 ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
int CLICKS = 0 ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD>
# define USER_PANEL_WIDTH 119
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> , <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> (<28> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ) <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> ,
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
dword FIELD_COLORS [ ] = { 0xf18db6 , 0x605ca8 , 0xfddc80 , 0xdc4a20 , 0x46b1e2 , 0x7e9d1e , 0x232323 , 0 } ;
char * BOARD_SIZES [ ] = { " S " , " L " , 0 } ;
# ifdef LANG_RUS
2011-10-09 13:24:33 +04:00
char * BUTTON_CAPTIONS [ ] = { " <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> [F2] " , " <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> [F1] " , " <20> <> 室 [Esc] " , 0 } ;
2011-10-06 20:06:15 +04:00
char CLICKS_TEXT [ ] = " <20> <> <EFBFBD> <EFBFBD> <EFBFBD> : / " ;
char LEVELS_TEXT [ ] = " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> :" ;
char HELP_WINDOW_CAPTION [ ] = " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> " ;
char * HELP_TEXT [ ] = { " <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> Flood-it?" ,
" " ,
" <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> 梥⮬ <20> <> <20> <> ࠭<EFBFBD> 祭<EFBFBD> <E7A5AD> <EFBFBD> <20> <> 室<> <E5AEA4> ." ,
" <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> 稭<EFBFBD> <E7A8AD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> 孥<EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> ⪨. <20> 롥<EFBFBD> <EBA1A5> <EFBFBD> <EFBFBD> 梥<> , <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <20> <> " ,
" <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ⨪<EFBFBD> <EFBFBD> <> <E1ABA5> , <20> <20> <> <EFBFBD> ⪨ <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> ⨬ 梥⮬ - ⠪ <20> <> <20> <> <EFBFBD> ᮥ<EFBFBD> <E1AEA5> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> " ,
" <EFBFBD> <EFBFBD> ᥤ<EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> ⪨ ⮩ <20> <> <20> <> <EFBFBD> <EFBFBD> ᪨. <20> <> 墠<EFBFBD> <E5A2A0> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> 㦭<EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 쭮<EFBFBD> " ,
" <EFBFBD> <EFBFBD> 室<> <E5AEA4> . <20> <> 蠣<EFBFBD> <E8A0A3> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> ⥣<EFBFBD> <E2A5A3> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> ਭ樯<E0A8AD> <E6A8AF> - <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ," ,
2011-10-07 20:07:50 +04:00
" <EFBFBD> ⮡<EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> !" ,
" " ,
" <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ⠪<> <E2A0AA> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> 蠬<EFBFBD> :" ,
" [Q] [W] [E] " ,
" [A] [S] [D] " ,
0 } ;
2013-09-24 22:50:05 +04:00
# elif LANG_EST
char * BUTTON_CAPTIONS [ ] = { " Uus m<> ng [F2] " , " Abi [F1] " , " V<EFBFBD> lju [Esc] " , 0 } ;
char CLICKS_TEXT [ ] = " Klikki: / " ;
char LEVELS_TEXT [ ] = " V<EFBFBD> li: " ;
char HELP_WINDOW_CAPTION [ ] = " Help " ;
char * HELP_TEXT [ ] = { " Kuidas m<> ngida m<> ngu Flood-it? " ,
" " ,
" Ujuta kogu m<> nguv<75> li <20> le <20> he v<> rviga lubatud k<> ikude arvuga. " ,
" M<EFBFBD> ngu alustad <20> lemisest vasakust nurgast ja edened valides <20> he v<> rvi " ,
" vajutades nuppudele vasakul. Kui sa muudad v<> rvi pragusel alal, " ,
" siis iga kokkupuutuv sama v<> rv muutub samaks. Nii saad ujutada " ,
" teised alad m<> nguv<75> ljal <20> le. Valida saad 2 m<> nguv<75> lja suuruse " ,
" vahel. Proovi v<> li <20> le ujutada etteandtud k<> ikude arvuga! " ,
" Kaasahaarav ja l<> bus! " ,
" " ,
" M<EFBFBD> ngida saab ka klaviatuuriga: " ,
" [Q] [W] [E] " ,
" [A] [S] [D] " ,
0 } ;
2011-10-06 20:06:15 +04:00
# else
char * BUTTON_CAPTIONS [ ] = { " New Game [F2] " , " Help [F1] " , " Exit [Esc] " , 0 } ;
char CLICKS_TEXT [ ] = " Clicks: / " ;
char LEVELS_TEXT [ ] = " Board: " ;
char HELP_WINDOW_CAPTION [ ] = " Help " ;
char * HELP_TEXT [ ] = { " How to play Flood-it? " ,
" " ,
" Flood the whole board with one color within the allowed steps. " ,
" You start from the top left corner and progress by selecting one " ,
2011-10-07 20:07:50 +04:00
" of the colored buttons on the left. When you change your current area " ,
2011-10-06 20:06:15 +04:00
" color, every adjacent square with the same color also changes, that " ,
" way you can flood other areas of the board. Select from 3 sizes of " ,
" the board and try to flood-it in the least amount of steps! " ,
2011-10-07 20:07:50 +04:00
" Addictive and Fun! " ,
" " ,
" You can also play with keyboard: " ,
" [Q] [W] [E] " ,
" [A] [S] [D] " ,
0 } ;
2011-10-06 20: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) | | ( id = = 4 ) ExitProcess ( ) ;
IF ( id = = 2 ) goto _NEW_GAME_MARK ;
IF ( id = = 3 ) goto _HELP_MARK ;
2011-10-09 13:24:33 +04:00
IF ( id > = 100 )
{
make_turn ( id - 100 ) ;
break ;
}
2011-10-06 20:06:15 +04:00
if ( id > = 10 )
{
id = id - 10 * 3 ;
2011-10-07 21:23:38 +04:00
IF ( BLOCK_SIZE = = DIFFICULTY_LEV_PARAMS [ id ] ) break ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2011-10-06 20:06:15 +04:00
BLOCK_SIZE = DIFFICULTY_LEV_PARAMS [ id ] ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
BLOCKS_NUM = DIFFICULTY_LEV_PARAMS [ id + 1 ] ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <20> <20> <> Y
MAX_CLICKS = DIFFICULTY_LEV_PARAMS [ id + 2 ] ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
new_game ( ) ;
MoveSize ( - 1 , - 1 , BLOCK_SIZE * BLOCKS_NUM + 14 + USER_PANEL_WIDTH , BLOCK_SIZE * BLOCKS_NUM + GetSkinWidth ( ) + 14 ) ;
}
break ;
case evKey :
key = GetKey ( ) ;
2011-10-07 21:23:38 +04:00
IF ( key = = 027 ) //Escape
2011-10-06 20:06:15 +04:00
ExitProcess ( ) ;
2011-10-07 21:23:38 +04:00
IF ( key = = 050 ) //F1
2011-10-06 20:06:15 +04:00
{
_HELP_MARK :
CreateThread ( # help , # stak ) ;
}
2011-10-07 21:23:38 +04:00
IF ( key = = 051 ) //F2
2011-10-06 20:06:15 +04:00
{
_NEW_GAME_MARK :
new_game ( ) ;
draw_clicks_num ( ) ;
draw_field ( ) ;
}
2011-10-07 21:23:38 +04:00
IF ( key = = 113 ) make_turn ( 0 ) ; //Q
IF ( key = = 119 ) make_turn ( 1 ) ; //W
IF ( key = = 101 ) make_turn ( 2 ) ; //E
IF ( key = = 097 ) make_turn ( 3 ) ; //A
IF ( key = = 115 ) make_turn ( 4 ) ; //S
IF ( key = = 100 ) make_turn ( 5 ) ; //D
2011-10-06 20:06:15 +04:00
break ;
case evReDraw :
draw_window ( ) ;
}
}
}
2011-10-07 20:07:50 +04:00
void make_turn ( int turn_id )
{
2011-10-07 21:23:38 +04:00
IF ( color_matrix [ 0 ] = = turn_id ) return ; //<2F> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> , <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD>
IF ( CLICKS > = MAX_CLICKS ) return ; //<2F> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2011-10-07 20:07:50 +04:00
CLICKS + + ;
draw_clicks_num ( ) ;
fill_field ( turn_id ) ;
draw_field ( ) ;
check_for_end ( ) ; //<2F> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
}
2011-10-06 20:06:15 +04:00
void draw_window ( )
{
int i , j ;
# define BUTTON_SIZE 28
sc . get ( ) ;
DefineAndDrawWindow ( 300 , 176 , BLOCK_SIZE * BLOCKS_NUM + 14 + USER_PANEL_WIDTH , BLOCK_SIZE * BLOCKS_NUM + GetSkinWidth ( ) + 14 , 0x74 , sc . work , 0 , 0 , " Flood-it! " ) ;
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
GetProcessInfo ( # Form , SelfInfo ) ;
2011-10-19 02:30:16 +04:00
IF ( Form . status_window = = 4 ) return ;
2011-10-06 20:06:15 +04:00
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> -> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
for ( i = 0 ; i < = 4 ; i + + )
{
2011-10-07 21:23:38 +04:00
IF ( i < > 4 )
2011-10-06 20:06:15 +04:00
DrawRegion ( USER_PANEL_WIDTH + i - 5 , i , BLOCK_SIZE * BLOCKS_NUM + 9 - i - i , BLOCK_SIZE * BLOCKS_NUM + 9 - i - i , sc . work ) ;
else
DrawRegion ( USER_PANEL_WIDTH + i - 5 , i , BLOCK_SIZE * BLOCKS_NUM + 9 - i - i , BLOCK_SIZE * BLOCKS_NUM + 9 - i - i , sc . work_graph ) ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
}
DrawBar ( 0 , 0 , USER_PANEL_WIDTH - 5 , BLOCK_SIZE * BLOCKS_NUM + 10 , sc . work ) ;
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
for ( i = 0 ; i < 2 ; i + + )
for ( j = 0 ; j < 3 ; j + + )
DefineButton ( j * BUTTON_SIZE + 17 , i * BUTTON_SIZE + 15 , BUTTON_SIZE , BUTTON_SIZE , i * 3 + j + 100 , FIELD_COLORS [ i * 3 + j ] ) ;
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
for ( j = 0 ; j < 3 ; j + + )
{
DefineButton ( 17 , j * 25 + 120 , 13 * 6 + 6 , 20 , j + 2 , sc . work_button ) ;
WriteText ( 17 + 4 , j * 25 + 127 , 0x80 , sc . work_button_text , BUTTON_CAPTIONS [ j ] , 0 ) ;
}
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
WriteText ( 17 , BLOCKS_NUM * BLOCK_SIZE - 20 + 7 , 0x80 , sc . work_text , # LEVELS_TEXT , 0 ) ;
for ( j = 0 ; j < 2 ; j + + )
{
DefineButton ( j * 25 + 56 , BLOCKS_NUM * BLOCK_SIZE - 20 , 20 , 20 , j + 10 , sc . work_button ) ;
2011-10-07 21:23:38 +04:00
IF ( BLOCK_SIZE = = DIFFICULTY_LEV_PARAMS [ j * 3 ] ) EDI = 0x800080 ;
2011-10-06 20:06:15 +04:00
else EDI = sc . work_button_text ;
WriteText ( j * 25 + 56 + 8 , BLOCKS_NUM * BLOCK_SIZE - 20 + 7 , 0x80 , EDI , BOARD_SIZES [ j ] , 0 ) ;
WriteText ( j * 25 + 56 + 9 , BLOCKS_NUM * BLOCK_SIZE - 20 + 7 , 0x80 , EDI , BOARD_SIZES [ j ] , 0 ) ;
}
draw_clicks_num ( ) ;
draw_field ( ) ;
}
void new_game ( )
{
2011-10-09 13:24:33 +04:00
int i ;
2011-10-06 20:06:15 +04:00
CLICKS = 0 ;
2011-10-09 13:24:33 +04:00
for ( i = 0 ; i < BLOCKS_NUM * BLOCKS_NUM ; i + + )
color_matrix [ i ] = random ( 6 ) ;
2011-10-06 20:06:15 +04:00
}
void fill_field ( int new_color_id )
{
2011-10-09 13:24:33 +04:00
int i , j ,
2011-10-06 20:06:15 +04:00
old_color_id = color_matrix [ 0 ] ,
restart ;
# define MARKED 6
color_matrix [ 0 ] = MARKED ;
_RESTART_MARK :
restart = 0 ;
for ( i = 0 ; i < BLOCKS_NUM ; i + + )
for ( j = 0 ; j < BLOCKS_NUM ; j + + )
{
2011-10-07 21:23:38 +04:00
IF ( color_matrix [ i * BLOCKS_NUM + j ] < > old_color_id ) continue ; //<2F> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
IF ( color_matrix [ i * BLOCKS_NUM + j ] = = MARKED ) continue ; //<2F> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> , <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD>
2011-10-06 20:06:15 +04:00
2011-10-07 21:23:38 +04:00
IF ( j > 0 ) & & ( color_matrix [ i * BLOCKS_NUM + j - 1 ] = = MARKED ) color_matrix [ i * BLOCKS_NUM + j ] = MARKED ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD>
IF ( i > 0 ) & & ( color_matrix [ i - 1 * BLOCKS_NUM + j ] = = MARKED ) color_matrix [ i * BLOCKS_NUM + j ] = MARKED ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
IF ( j < BLOCKS_NUM - 1 ) & & ( color_matrix [ i * BLOCKS_NUM + j + 1 ] = = MARKED ) color_matrix [ i * BLOCKS_NUM + j ] = MARKED ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
IF ( i < BLOCKS_NUM - 1 ) & & ( color_matrix [ i + 1 * BLOCKS_NUM + j ] = = MARKED ) color_matrix [ i * BLOCKS_NUM + j ] = MARKED ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2011-10-06 20:06:15 +04:00
2011-10-07 21:23:38 +04:00
IF ( color_matrix [ i * BLOCKS_NUM + j ] = = MARKED ) restart = 1 ; //<2F> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> , <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> - <20> <> <EFBFBD> <20> <> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2011-10-06 20:06:15 +04:00
}
2011-10-07 21:23:38 +04:00
IF ( restart ) goto _RESTART_MARK ;
2011-10-06 20:06:15 +04:00
2011-10-09 13:24:33 +04:00
for ( i = 0 ; i < BLOCKS_NUM * BLOCKS_NUM ; i + + )
IF ( color_matrix [ i ] = = MARKED ) color_matrix [ i ] = new_color_id ;
2011-10-06 20:06:15 +04:00
}
int check_for_end ( )
{
int i , j , ii , jj ;
if ( CLICKS > = MAX_CLICKS ) //<2F> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
{
2011-10-07 21:23:38 +04:00
IF ( CLICKS = = MAX_CLICKS ) //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
2011-10-06 20:06:15 +04:00
{
2011-10-09 13:24:33 +04:00
for ( i = 0 ; i < BLOCKS_NUM * BLOCKS_NUM ; i + + ) //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> , <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2011-10-19 02:30:16 +04:00
IF ( color_matrix [ i ] < > color_matrix [ 0 ] ) goto _loss_MARK ;
2011-10-06 20:06:15 +04:00
goto _WIN_MARK ;
}
2011-10-19 02:30:16 +04:00
_loss_MARK :
2011-10-06 20:06:15 +04:00
for ( i = 0 ; i < 14 ; i + + )
for ( j = 0 ; j < 14 ; j + + )
{
2011-10-07 21:23:38 +04:00
IF ( BLOCK_SIZE = = DIFFICULTY_LEV_PARAMS [ 0 ] )
2011-10-06 20:06:15 +04:00
{
ii = i ;
jj = j ;
}
else
{
ii = i * 2 ;
jj = j * 2 ;
}
2011-10-19 02:30:16 +04:00
color_matrix [ ii * BLOCKS_NUM + jj ] = loss_matrix [ i * 14 + j ] ;
color_matrix [ ii + 1 * BLOCKS_NUM + jj ] = loss_matrix [ i * 14 + j ] ;
color_matrix [ ii * BLOCKS_NUM + jj + 1 ] = loss_matrix [ i * 14 + j ] ;
color_matrix [ ii + 1 * BLOCKS_NUM + jj + 1 ] = loss_matrix [ i * 14 + j ] ;
2011-10-06 20:06:15 +04:00
draw_field ( ) ;
//Pause(5);
}
return 1 ;
}
2011-10-09 13:24:33 +04:00
for ( i = 0 ; i < BLOCKS_NUM * BLOCKS_NUM ; i + + ) //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> , <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
IF ( color_matrix [ i ] < > color_matrix [ 0 ] ) return 0 ;
2011-10-06 20:06:15 +04:00
//<2F> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> MAX_CLICKS -> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
_WIN_MARK :
for ( i = 0 ; i < 25 ; i + + )
{
new_game ( ) ;
draw_field ( ) ;
Pause ( 7 ) ;
}
CLICKS = MAX_CLICKS ;
for ( i = 0 ; i < 14 ; i + + )
for ( j = 0 ; j < 14 ; j + + )
{
2011-10-07 21:23:38 +04:00
IF ( BLOCK_SIZE = = DIFFICULTY_LEV_PARAMS [ 0 ] ) //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2011-10-06 20:06:15 +04:00
{
ii = i ;
jj = j ;
}
else
{
ii = i * 2 ;
jj = j * 2 ;
}
color_matrix [ ii * BLOCKS_NUM + jj ] = win_matrix [ i * 14 + j ] ;
color_matrix [ ii + 1 * BLOCKS_NUM + jj ] = win_matrix [ i * 14 + j ] ;
color_matrix [ ii * BLOCKS_NUM + jj + 1 ] = win_matrix [ i * 14 + j ] ;
color_matrix [ ii + 1 * BLOCKS_NUM + jj + 1 ] = win_matrix [ i * 14 + j ] ;
draw_field ( ) ;
//Pause(5);
}
return 1 ;
}
void draw_clicks_num ( )
{
# define TEXT_X 21
# define TEXT_Y 92
DrawBar ( 8 * 6 + TEXT_X , TEXT_Y , 6 * 2 , 9 , sc . work ) ;
WriteText ( TEXT_X , TEXT_Y , 0x80 , sc . work_text , # CLICKS_TEXT , 0 ) ;
2011-10-07 21:23:38 +04:00
IF ( CLICKS < 10 ) EBX = 9 * 6 + TEXT_X ;
2011-10-06 20:06:15 +04:00
else EBX = 8 * 6 + TEXT_X ;
WriteText ( EBX , TEXT_Y , 0x80 , sc . work_text , IntToStr ( CLICKS ) , 0 ) ;
WriteText ( 11 * 6 + TEXT_X , TEXT_Y , 0x80 , sc . work_text , IntToStr ( MAX_CLICKS ) , 0 ) ;
}
void draw_field ( )
{
int i , j ;
int color_id ;
for ( i = 0 ; i < BLOCKS_NUM ; i + + )
for ( j = 0 ; j < BLOCKS_NUM ; j + + )
{
color_id = color_matrix [ i * BLOCKS_NUM + j ] ;
DrawBar ( j * BLOCK_SIZE + USER_PANEL_WIDTH , i * BLOCK_SIZE + 5 , BLOCK_SIZE , BLOCK_SIZE , FIELD_COLORS [ color_id ] ) ;
}
}
void help ( )
{
int i ;
loop ( )
switch ( WaitEvent ( ) )
{
CASE evButton :
2011-10-07 21:23:38 +04:00
IF ( GetButtonID ( ) = = 1 ) ExitProcess ( ) ;
2011-10-06 20:06:15 +04:00
break ;
CASE evKey :
2011-10-07 21:23:38 +04:00
IF ( GetKey ( ) = = 27 ) ExitProcess ( ) ; //Esc
2011-10-06 20:06:15 +04:00
break ;
CASE evReDraw :
for ( i = 0 ; HELP_TEXT [ i ] < > 0 ; i + + ; ) { } ;
2011-10-07 20:07:50 +04:00
DefineAndDrawWindow ( 500 , 200 , 450 , i * 13 + 44 , 0x34 , sc . work , 0 , 0 , # HELP_WINDOW_CAPTION ) ;
2011-10-06 20:06:15 +04:00
WriteText ( 6 , 12 , 0x80 , sc . work_text , HELP_TEXT [ 0 ] , 0 ) ; //<2F> <> <EFBFBD> <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
for ( i = 0 ; HELP_TEXT [ i ] < > 0 ; i + + ; ) WriteText ( 5 , i * 13 + 12 , 0x80 , sc . work_text , HELP_TEXT [ i ] , 0 ) ;
}
}
stop :