Update programs/games/flood-it/flood-it.c
All checks were successful
Build system / Check kernel codestyle (pull_request) Successful in 32s
Build system / Build (pull_request) Successful in 5m36s

update game info

Signed-off-by: Kiril Lipatov <lipatov.kiril@gmail.com>
This commit is contained in:
2025-03-28 18:18:16 +01:00
parent eb7e8083cd
commit 5118b580e7

View File

@@ -1,424 +1,426 @@
//Leency 2011 - 2025, Flood-it! v3.0, GPL // SPDX-License-Identifier: GPL-2.0-only
// Flood-it! - Strategy game: Flood the board with one color, within a step limit.
#include "lib\kolibri.h" // Copyright (C) 2011-2025 Leency
#include "lib\random.h"
#include "lib\kolibri.h"
system_colors sc; #include "lib\random.h"
proc_info Form;
dword help_window_stak[100]; system_colors sc;
proc_info Form;
#define DEFAULT_BLOCK_COUNT 14 dword help_window_stak[100];
#define DEFAULT_MAX_CLICKS 25
#define MAX_BLOCK_SIZE 28 #define DEFAULT_BLOCK_COUNT 14
char board_size = -1; #define DEFAULT_MAX_CLICKS 25
int BLOCK_SIZE; //cell size #define MAX_BLOCK_SIZE 28
int BLOCKS_NUM; //number of cells by X and Y char board_size = -1;
int MAX_CLICKS; //max clicks for win int BLOCK_SIZE; //cell size
int CLICKS; //how many clicks user already did int BLOCKS_NUM; //number of cells by X and Y
int game_end; int MAX_CLICKS; //max clicks for win
int CLICKS; //how many clicks user already did
#define USER_PANEL_WIDTH 144 int game_end;
//six colors are used in a game for a cells #define USER_PANEL_WIDTH 144
//and seventh color is used to mark a cell during filling process
dword FIELD_COLORS[] = {0xf18db6, 0x605ca8, 0xfddc80, 0xdc4a20, 0x46b1e2, 0x7e9d1e, 0x232323}; //six colors are used in a game for a cells
char BOARD_SIZES[] = "S\0L"; //and seventh color is used to mark a cell during filling process
dword FIELD_COLORS[] = {0xf18db6, 0x605ca8, 0xfddc80, 0xdc4a20, 0x46b1e2, 0x7e9d1e, 0x232323};
char BOARD_SIZES[] = "S\0L";
#ifdef LANG_RUS
char *BUTTON_CAPTIONS[]={ " <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> [F2]", " <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> [F1]", " <20><>室 [Esc]", 0};
char CLICKS_TEXT[]=" <20><><EFBFBD><EFBFBD><EFBFBD>: /"; #ifdef LANG_RUS
char LEVELS_TEXT[]=" <20><><EFBFBD><EFBFBD>:"; char *BUTTON_CAPTIONS[]={ " ‡ ­®¢® [F2]", " <20>®¬®éì [F1]", " ‚ë室 [Esc]", 0};
char CLICKS_TEXT[]=" Š«¨ª¨: /";
char HELP_WINDOW_CAPTION[]="<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"; char LEVELS_TEXT[]=" <20>®«¥:";
char *HELP_TEXT[]={ "<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> Flood-it?",
"", char HELP_WINDOW_CAPTION[]="<EFBFBD>®¬®éì";
"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> 梥⮬ <20><> <20><><EFBFBD><EFBFBD><E7A5AD><EFBFBD> <20><>᫮ 室<><E5AEA4>.", char *HELP_TEXT[]={ "Š ª ¨£à âì ¢® Flood-it?",
"<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>,", "ª¢ ¤à â¨ª®¢ á«¥¢ , ¨ ª«¥âª¨ ®ªà áïâáï í⨬ 梥⮬ - â ª ¢ë ¯à¨á®¥¤¨­¨â¥",
"<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!", "á®á¥¤­¨¥ ª«¥âª¨ ⮩ ¦¥ ®ªà áª¨. ‡ å¢ â¨âì ¯®«¥ ­ã¦­® §  ¬¨­¨¬ «ì­®¥",
"", "ç¨á«® 室®¢. <20>®è £®¢ ï áâà â¥£¨ï á ¨­â¥à¥á­ë¬ ¯à¨­æ¨¯®¬ - ¨§¬¥­¨áì,",
"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><><E2A0AA> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:", "çâ®¡ë ¯®¡¥¤¨âì!",
"[Q] [W] [E]", "",
"[A] [S] [D]", "ˆ£à âì â ª¦¥ ¬®¦­® ª« ¢¨è ¬¨:",
0}; "[Q] [W] [E]",
#elif LANG_EST "[A] [S] [D]",
char *BUTTON_CAPTIONS[]={ "Uus m<>ng [F2]", "Abi [F1]", "V<EFBFBD>lju [Esc]", 0}; 0};
char CLICKS_TEXT[]="Klikki: /"; #elif LANG_EST
char LEVELS_TEXT[]="V<EFBFBD>li:"; char *BUTTON_CAPTIONS[]={ "Uus mäng [F2]", "Abi [F1]", "Välju [Esc]", 0};
char CLICKS_TEXT[]="Klikki: /";
char HELP_WINDOW_CAPTION[]="Help"; char LEVELS_TEXT[]="Väli:";
char *HELP_TEXT[]={ "Kuidas m<>ngida m<>ngu Flood-it?",
"", char HELP_WINDOW_CAPTION[]="Help";
"Ujuta kogu m<EFBFBD>nguv<EFBFBD>li <20>le <20>he v<>rviga lubatud k<>ikude arvuga.", char *HELP_TEXT[]={ "Kuidas mängida mängu Flood-it?",
"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,", "Ujuta kogu mänguväli üle ühe värviga lubatud käikude arvuga.",
"siis iga kokkupuutuv sama v<>rv muutub samaks. Nii saad ujutada", "Mängu alustad ülemisest vasakust nurgast ja edened valides ühe värvi",
"teised alad m<>nguv<75>ljal <20>le. Valida saad 2 m<>nguv<75>lja suuruse", "vajutades nuppudele vasakul. Kui sa muudad värvi pragusel alal,",
"vahel. Proovi v<>li <20>le ujutada etteandtud k<>ikude arvuga!", "siis iga kokkupuutuv sama värv muutub samaks. Nii saad ujutada",
"", "teised alad mänguväljal üle. Valida saad 2 mänguvälja suuruse",
"M<EFBFBD>ngida saab ka klaviatuuriga:", "vahel. Proovi väli üle ujutada etteandtud käikude arvuga!",
"[Q] [W] [E]", "",
"[A] [S] [D]", "Mängida saab ka klaviatuuriga:",
0}; "[Q] [W] [E]",
#else "[A] [S] [D]",
char *BUTTON_CAPTIONS[]={ "Restart [F2]", " Help [F1]", " Exit [Esc]", 0}; 0};
char CLICKS_TEXT[]="Clicks: /"; #else
char LEVELS_TEXT[]="Board:"; char *BUTTON_CAPTIONS[]={ "Restart [F2]", " Help [F1]", " Exit [Esc]", 0};
char CLICKS_TEXT[]="Clicks: /";
char HELP_WINDOW_CAPTION[]="Help"; char LEVELS_TEXT[]="Board:";
char *HELP_TEXT[]={ "How to play Flood-it?",
"", char HELP_WINDOW_CAPTION[]="Help";
"Flood the whole board with one color within the allowed steps.", char *HELP_TEXT[]={ "How to play Flood-it?",
"You start from the top left corner and progress by selecting one", "",
"of the colored buttons on the left. When you change your current area", "Flood the whole board with one color within the allowed steps.",
"color, every adjacent square with the same color also changes, that", "You start from the top left corner and progress by selecting one",
"way you can flood other areas of the board. Select from 3 sizes of", "of the colored buttons on the left. When you change your current area",
"the board and try to flood-it in the least amount of steps!", "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",
"You can also play with keyboard:", "the board and try to flood-it in the least amount of steps!",
"[Q] [W] [E]", "",
"[A] [S] [D]", "You can also play with keyboard:",
0}; "[Q] [W] [E]",
#endif "[A] [S] [D]",
0};
#endif
unsigned char color_matrix[28*28]; //our field
unsigned char loss_matrix[14*14]={ unsigned char color_matrix[28*28]; //our field
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, unsigned char loss_matrix[14*14]={
2, 3, 3, 3, 2, 3, 3, 3, 2, 3, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2,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,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 4, 1, 4, 4, 1, 4, 1, 4, 4, 1, 4,
}; 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
void main() };
{
int key, id; void main()
{
set_board_size(0); //small board by default int key, id;
new_game();
set_board_size(0); //small board by default
loop() switch(WaitEvent()) new_game();
{
case evButton: loop() switch(WaitEvent())
id = GetButtonID(); {
IF (id==1) || (id==4) ExitProcess(); case evButton:
IF (id==2) goto _NEW_GAME_MARK; id = GetButtonID();
IF (id==3) goto _HELP_MARK; IF (id==1) || (id==4) ExitProcess();
IF (id>=100) { IF (id==2) goto _NEW_GAME_MARK;
make_turn(id-100); IF (id==3) goto _HELP_MARK;
} IF (id>=100) {
if (id==10) set_board_size(0); make_turn(id-100);
if (id==11) set_board_size(1); }
break; if (id==10) set_board_size(0);
case evKey: if (id==11) set_board_size(1);
key = GetKeyScancode(); break;
IF (key==01) //Escape case evKey:
ExitProcess(); key = GetKeyScancode();
IF (key==59) //F1 IF (key==01) //Escape
{ ExitProcess();
_HELP_MARK: IF (key==59) //F1
CreateThread(#help_thread,#help_window_stak); {
break; _HELP_MARK:
} CreateThread(#help_thread,#help_window_stak);
IF (key==60) //F2 break;
{ }
_NEW_GAME_MARK: IF (key==60) //F2
new_game(); {
draw_clicks_num(); _NEW_GAME_MARK:
draw_field(); new_game();
break; draw_clicks_num();
} draw_field();
IF (key==16) make_turn(0); //Q break;
IF (key==17) make_turn(1); //W }
IF (key==18) make_turn(2); //E IF (key==16) make_turn(0); //Q
IF (key==30) make_turn(3); //A IF (key==17) make_turn(1); //W
IF (key==31) make_turn(4); //S IF (key==18) make_turn(2); //E
IF (key==32) make_turn(5); //D IF (key==30) make_turn(3); //A
break; IF (key==31) make_turn(4); //S
case evReDraw: IF (key==32) make_turn(5); //D
draw_window(); break;
} case evReDraw:
} draw_window();
}
void set_board_size(char s) }
{
if (board_size != s) { void set_board_size(char s)
board_size = s; {
if (board_size != s) {
BLOCKS_NUM = board_size + 1 * DEFAULT_BLOCK_COUNT; board_size = s;
MAX_CLICKS = board_size + 1 * DEFAULT_MAX_CLICKS;
BLOCKS_NUM = board_size + 1 * DEFAULT_BLOCK_COUNT;
BLOCK_SIZE = GetScreenHeight() - 70 / BLOCKS_NUM; MAX_CLICKS = board_size + 1 * DEFAULT_MAX_CLICKS;
if (BLOCK_SIZE > MAX_BLOCK_SIZE) BLOCK_SIZE = MAX_BLOCK_SIZE;
BLOCK_SIZE = GetScreenHeight() - 70 / BLOCKS_NUM;
new_game(); if (BLOCK_SIZE > MAX_BLOCK_SIZE) BLOCK_SIZE = MAX_BLOCK_SIZE;
MoveSize(-1, -1, BLOCK_SIZE*BLOCKS_NUM +14+USER_PANEL_WIDTH, new_game();
BLOCK_SIZE*BLOCKS_NUM +GetSkinHeight()+14);
} MoveSize(-1, -1, BLOCK_SIZE*BLOCKS_NUM +14+USER_PANEL_WIDTH,
} BLOCK_SIZE*BLOCKS_NUM +GetSkinHeight()+14);
}
}
void make_turn(int turn_id)
{
IF (color_matrix[0]==turn_id) return; //ignore no-sence click: first item color is equal to a new color void make_turn(int turn_id)
IF (!game_is_ended()) { {
CLICKS++; IF (color_matrix[0]==turn_id) return; //ignore no-sence click: first item color is equal to a new color
draw_clicks_num(); IF (!game_is_ended()) {
fill_field(turn_id); CLICKS++;
if (!game_is_ended()) draw_field(); draw_clicks_num();
} fill_field(turn_id);
} if (!game_is_ended()) draw_field();
}
void draw_window() }
{
int i; void draw_window()
#define BUTTON_SIZE 28 {
int i;
sc.get(); #define BUTTON_SIZE 28
DefineAndDrawWindow(300,176, BLOCK_SIZE*BLOCKS_NUM +14+USER_PANEL_WIDTH, sc.get();
BLOCK_SIZE*BLOCKS_NUM +GetSkinHeight()+14, 0x74,0,"Flood-it!");
DefineAndDrawWindow(300,176, BLOCK_SIZE*BLOCKS_NUM +14+USER_PANEL_WIDTH,
// Fix rolled-up bug BLOCK_SIZE*BLOCKS_NUM +GetSkinHeight()+14, 0x74,0,"Flood-it!");
GetProcessInfo(#Form, SelfInfo);
IF (Form.status_window==4) return; // Fix rolled-up bug
GetProcessInfo(#Form, SelfInfo);
// Fill background to reduce window redraw IF (Form.status_window==4) return;
for (i=0;i<=4;i++)
{ // Fill background to reduce window redraw
ESI = sc.work; for (i=0;i<=4;i++)
IF (i==4) ESI = sc.work_graph; {
DrawRegion(USER_PANEL_WIDTH+i-5,i, BLOCK_SIZE*BLOCKS_NUM +9-i-i, ESI); ESI = sc.work;
} IF (i==4) ESI = sc.work_graph;
DrawBar(0,0, USER_PANEL_WIDTH-5, BLOCK_SIZE*BLOCKS_NUM+10, sc.work); DrawRegion(USER_PANEL_WIDTH+i-5,i, BLOCK_SIZE*BLOCKS_NUM +9-i-i, ESI);
}
// Main buttons to fill the board DrawBar(0,0, USER_PANEL_WIDTH-5, BLOCK_SIZE*BLOCKS_NUM+10, sc.work);
#define FILL_BUTTON_SIZE BUTTON_SIZE+8
for (i=0;i<6;i++) // Main buttons to fill the board
DefineButton(i%3*FILL_BUTTON_SIZE+17,i/3*FILL_BUTTON_SIZE+15,FILL_BUTTON_SIZE,FILL_BUTTON_SIZE, i+100,FIELD_COLORS[i]); #define FILL_BUTTON_SIZE BUTTON_SIZE+8
for (i=0;i<6;i++)
// Menu buttons DefineButton(i%3*FILL_BUTTON_SIZE+17,i/3*FILL_BUTTON_SIZE+15,FILL_BUTTON_SIZE,FILL_BUTTON_SIZE, i+100,FIELD_COLORS[i]);
for (i=0;i<3;i++)
{ // Menu buttons
DefineButton(17,i*31+140, 13*8+6, 25, i+2,sc.work_button); for (i=0;i<3;i++)
WriteText(17+4,i*31+146,0x90,sc.work_button_text,BUTTON_CAPTIONS[i],0); {
} DefineButton(17,i*31+140, 13*8+6, 25, i+2,sc.work_button);
WriteText(17+4,i*31+146,0x90,sc.work_button_text,BUTTON_CAPTIONS[i],0);
// Board size }
WriteText(17,BLOCKS_NUM*BLOCK_SIZE-25+7,0x90,sc.work_text,#LEVELS_TEXT,0);
for (i=0;i<2;i++) // Board size
{ WriteText(17,BLOCKS_NUM*BLOCK_SIZE-25+7,0x90,sc.work_text,#LEVELS_TEXT,0);
IF (board_size == i) { for (i=0;i<2;i++)
ESI=sc.work_button; {
EDI=sc.work_button_text; IF (board_size == i) {
} ELSE { ESI=sc.work_button;
ESI = sc.work; EDI=sc.work_button_text;
EDI = sc.work_text; } ELSE {
} ESI = sc.work;
EDI = sc.work_text;
DefineButton(i*32+69,BLOCKS_NUM*BLOCK_SIZE-24, 26,25, i+10,ESI); }
WriteText(i*32+69+9,BLOCKS_NUM*BLOCK_SIZE-24+6,0x90,EDI,#BOARD_SIZES+i+i,0);
$add ebx, 1<<16 //bold DefineButton(i*32+69,BLOCKS_NUM*BLOCK_SIZE-24, 26,25, i+10,ESI);
$int 0x40 WriteText(i*32+69+9,BLOCKS_NUM*BLOCK_SIZE-24+6,0x90,EDI,#BOARD_SIZES+i+i,0);
} $add ebx, 1<<16 //bold
$int 0x40
draw_clicks_num(); }
draw_field();
} draw_clicks_num();
draw_field();
void randomly_fill_the_board() }
{
int i; void randomly_fill_the_board()
for (i=0;i<BLOCKS_NUM*BLOCKS_NUM;i++) { {
color_matrix[i] = random(6); int i;
} for (i=0;i<BLOCKS_NUM*BLOCKS_NUM;i++) {
} color_matrix[i] = random(6);
}
void new_game() }
{
CLICKS = 0; void new_game()
game_end = false; {
randomly_fill_the_board(); CLICKS = 0;
} game_end = false;
randomly_fill_the_board();
void fill_field(int new_color_id) }
{
int i, j, void fill_field(int new_color_id)
old_color_id=color_matrix[0], {
restart; int i, j,
int cur_cell; old_color_id=color_matrix[0],
#define MARKED 6 restart;
int cur_cell;
color_matrix[0]=MARKED; #define MARKED 6
_RESTART_MARK: color_matrix[0]=MARKED;
restart=0; _RESTART_MARK:
for (i=0;i<BLOCKS_NUM;i++) restart=0;
for (j=0;j<BLOCKS_NUM;j++)
{ for (i=0;i<BLOCKS_NUM;i++)
cur_cell = i*BLOCKS_NUM+j; for (j=0;j<BLOCKS_NUM;j++)
IF (color_matrix[cur_cell]<>old_color_id) continue; //if not a needed color then continue {
IF (color_matrix[cur_cell]==MARKED) continue; //if already marked then continue cur_cell = i*BLOCKS_NUM+j;
IF (color_matrix[cur_cell]<>old_color_id) continue; //if not a needed color then continue
IF (j>0) && (color_matrix[i*BLOCKS_NUM+j-1]==MARKED) color_matrix[cur_cell]=MARKED; //left IF (color_matrix[cur_cell]==MARKED) continue; //if already marked then continue
IF (i>0) && (color_matrix[i-1*BLOCKS_NUM+j]==MARKED) color_matrix[cur_cell]=MARKED; //top
IF (j<BLOCKS_NUM-1) && (color_matrix[i*BLOCKS_NUM+j+1]==MARKED) color_matrix[cur_cell]=MARKED; //right IF (j>0) && (color_matrix[i*BLOCKS_NUM+j-1]==MARKED) color_matrix[cur_cell]=MARKED; //left
IF (i<BLOCKS_NUM-1) && (color_matrix[i+1*BLOCKS_NUM+j]==MARKED) color_matrix[cur_cell]=MARKED; //bottom IF (i>0) && (color_matrix[i-1*BLOCKS_NUM+j]==MARKED) color_matrix[cur_cell]=MARKED; //top
IF (j<BLOCKS_NUM-1) && (color_matrix[i*BLOCKS_NUM+j+1]==MARKED) color_matrix[cur_cell]=MARKED; //right
IF (color_matrix[cur_cell]==MARKED) restart=1; IF (i<BLOCKS_NUM-1) && (color_matrix[i+1*BLOCKS_NUM+j]==MARKED) color_matrix[cur_cell]=MARKED; //bottom
}
IF (restart) goto _RESTART_MARK; IF (color_matrix[cur_cell]==MARKED) restart=1;
}
for (i=0;i<BLOCKS_NUM*BLOCKS_NUM;i++) IF (restart) goto _RESTART_MARK;
IF (color_matrix[i]==MARKED) color_matrix[i]=new_color_id;
} for (i=0;i<BLOCKS_NUM*BLOCKS_NUM;i++)
IF (color_matrix[i]==MARKED) color_matrix[i]=new_color_id;
void draw_win_or_loose_animation(dword matrix) }
{
int i, j, ii, jj; void draw_win_or_loose_animation(dword matrix)
for (i=0;i<14;i++) { {
for (j=0;j<14;j++) int i, j, ii, jj;
{ for (i=0;i<14;i++) {
ii = board_size * 2 + i; for (j=0;j<14;j++)
jj = board_size * 2 + j; {
color_matrix[ii*BLOCKS_NUM+jj]= ii = board_size * 2 + i;
color_matrix[ii+1*BLOCKS_NUM+jj]= jj = board_size * 2 + j;
color_matrix[ii*BLOCKS_NUM+jj+1]= color_matrix[ii*BLOCKS_NUM+jj]=
color_matrix[ii+1*BLOCKS_NUM+jj+1]=ESBYTE[i*14+j+matrix]; color_matrix[ii+1*BLOCKS_NUM+jj]=
draw_field(); color_matrix[ii*BLOCKS_NUM+jj+1]=
} color_matrix[ii+1*BLOCKS_NUM+jj+1]=ESBYTE[i*14+j+matrix];
} draw_field();
} }
}
int field_is_solid() }
{
int i; int field_is_solid()
if (game_end) return 1; {
game_end = 1; int i;
for (i=0;i<BLOCKS_NUM*BLOCKS_NUM;i++) { if (game_end) return 1;
IF (color_matrix[i]<>color_matrix[0]) game_end = 0; game_end = 1;
} for (i=0;i<BLOCKS_NUM*BLOCKS_NUM;i++) {
return game_end; IF (color_matrix[i]<>color_matrix[0]) game_end = 0;
} }
return game_end;
int game_is_ended() }
{
int i; int game_is_ended()
{
if (game_end) return 1; int i;
if (CLICKS>=MAX_CLICKS) //check for game end via max_clicks if (game_end) return 1;
{
IF (CLICKS==MAX_CLICKS) //probably user won on the last step if (CLICKS>=MAX_CLICKS) //check for game end via max_clicks
{ {
if (field_is_solid()) goto _WIN_MARK; IF (CLICKS==MAX_CLICKS) //probably user won on the last step
} {
draw_win_or_loose_animation(#loss_matrix); if (field_is_solid()) goto _WIN_MARK;
return 1; }
} else { draw_win_or_loose_animation(#loss_matrix);
if (!field_is_solid()) return 0; return 1;
} else {
//field is solid and CLICKS<MAX_CLICKS -> win if (!field_is_solid()) return 0;
_WIN_MARK: //field is solid and CLICKS<MAX_CLICKS -> win
for (i=0;i<25;i++) _WIN_MARK:
{
randomly_fill_the_board(); for (i=0;i<25;i++)
draw_field(); {
Pause(7); randomly_fill_the_board();
} draw_field();
Pause(7);
draw_win_or_loose_animation(#win_matrix); }
return 1;
} draw_win_or_loose_animation(#win_matrix);
} return 1;
}
}
void draw_clicks_num()
{
#define TEXT_X 19 void draw_clicks_num()
#define TEXT_Y 100 {
#define TEXT_X 19
DrawBar(TEXT_X, TEXT_Y, USER_PANEL_WIDTH-TEXT_X-5,16, sc.work); #define TEXT_Y 100
WriteText(TEXT_X,TEXT_Y,0x90,sc.work_text,#CLICKS_TEXT,0); DrawBar(TEXT_X, TEXT_Y, USER_PANEL_WIDTH-TEXT_X-5,16, sc.work);
IF (CLICKS<10) EBX=9*8+TEXT_X; WriteText(TEXT_X,TEXT_Y,0x90,sc.work_text,#CLICKS_TEXT,0);
else EBX=8*8+TEXT_X;
IF (CLICKS<10) EBX=9*8+TEXT_X;
WriteText(EBX,TEXT_Y,0x90,sc.work_text,itoa_nosign(CLICKS),0); else EBX=8*8+TEXT_X;
WriteText(11*8+TEXT_X,TEXT_Y,0x90,sc.work_text,itoa_nosign(MAX_CLICKS),0); WriteText(EBX,TEXT_Y,0x90,sc.work_text,itoa_nosign(CLICKS),0);
}
WriteText(11*8+TEXT_X,TEXT_Y,0x90,sc.work_text,itoa_nosign(MAX_CLICKS),0);
}
void draw_field()
{
int i, j; void draw_field()
int color_id; {
int i, j;
for (i=0;i<BLOCKS_NUM;i++) int color_id;
for (j=0;j<BLOCKS_NUM;j++)
{ for (i=0;i<BLOCKS_NUM;i++)
color_id = color_matrix[i*BLOCKS_NUM+j]; for (j=0;j<BLOCKS_NUM;j++)
DrawBar(j*BLOCK_SIZE+USER_PANEL_WIDTH, i*BLOCK_SIZE+5, BLOCK_SIZE,BLOCK_SIZE, FIELD_COLORS[color_id]); {
} 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_thread()
{
int i; void help_thread()
{
loop() switch (WaitEvent()) int i;
{
case evButton: loop() switch (WaitEvent())
ExitProcess(); {
case evKey: case evButton:
IF (GetKeyScancode()==001) ExitProcess(); //Esc ExitProcess();
break; case evKey:
case evReDraw: IF (GetKeyScancode()==001) ExitProcess(); //Esc
//for (i=0; HELP_TEXT[i]<>0; i++;) {}; //calculate line numbers, predefined i=12 used to reduce size break;
DefineAndDrawWindow(400,200,612,12*19+25+GetSkinHeight(),0x34,sc.work,#HELP_WINDOW_CAPTION); case evReDraw:
WriteText(6,12,0x90,sc.work_text,HELP_TEXT[0],0); //for a bold text //for (i=0; HELP_TEXT[i]<>0; i++;) {}; //calculate line numbers, predefined i=12 used to reduce size
for (i=0; HELP_TEXT[i]<>0; i++;) WriteText(7,i*19+12,0x90,sc.work_text,HELP_TEXT[i],0); DefineAndDrawWindow(400,200,612,12*19+25+GetSkinHeight(),0x34,sc.work,#HELP_WINDOW_CAPTION);
} WriteText(6,12,0x90,sc.work_text,HELP_TEXT[0],0); //for a bold text
} for (i=0; HELP_TEXT[i]<>0; i++;) WriteText(7,i*19+12,0x90,sc.work_text,HELP_TEXT[i],0);
}
}
stop: stop: