Mine game v0.62 (#172)

- proper window rolling up fix;
- bigger cells and fonts;
- add icon to a new game button;
- better alignment of ui elements in header.

Reviewed-on: https://git.kolibrios.org/KolibriOS/kolibrios/pulls/172
Reviewed-by: Max Logaev <maxlogaev@proton.me>
Co-authored-by: leency <lipatov.kiril@gmail.com>
Co-committed-by: leency <lipatov.kiril@gmail.com>
This commit is contained in:
leency 2025-03-22 09:40:04 +01:00 committed by Max Logaev
parent 8376fed87d
commit 5cf6c3baf9
4 changed files with 102 additions and 46 deletions

View File

@ -1,5 +1,11 @@
====Leency==== ====Leency====
v0.62 (21/03/2025)
- proper window rolling up fix
- bigger cells and fonts
- add icon to a new game button
- better alignment of ui elements in header
v0.52 (16/12/2008) v0.52 (16/12/2008)
- window rolling up fix - window rolling up fix

View File

@ -18,43 +18,42 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*******************************************************************************/ *******************************************************************************/
?define HEADER_Y 4
?define BTNSIZE 19
char game_mode[] = "1/3"; char game_mode[] = "1/3";
void draw_window() // Ïðîöåäóðà îòðèñîâêè îêíà void draw_window()
{ {
sys_get_colors(#colors, 40); dword iconimg = sys_memopen("ICONS18", 0, SHM_READ);
//sys_get_colors(#colors, 40);
// WINDOW
sys_window_redraw(1); sys_window_redraw(1);
EBX = xpos << 16 + xsize + 9; EBX = xpos << 16 + xsize + 9;
ECX = ypos << 16 + ysize; ECX = ypos << 16 + ysize;
sys_draw_window(EBX, ECX, 0x34CCCCCC, colors.w_work | 0x80000000, "MineSweeper"); sys_draw_window(EBX, ECX, 0x34CCCCCC, clGray | 0x80000000, "MineSweeper");
sys_window_redraw(2);
// Leency ROLLED UP FIX
sys_process_info(#procinfo, -1); sys_process_info(#procinfo, -1);
IF (procinfo.ysize<70) return; #define ROLLED_UP 0x04
IF (procinfo.status_window&ROLLED_UP) return;
// <NEW GAME> BUTTON (911) // <NEW GAME> BUTTON (911)
EBX = xsize / 2 - 10; sys_draw_button(CENTER_POS << 16 + BTNSIZE, HEADER_Y<<16+BTNSIZE, 911+BT_HIDE, clLightGray);
EBX = EBX << 16 + BTNSIZE; draw_rectangle(CENTER_POS,HEADER_Y,BTNSIZE,BTNSIZE,clWhite,clDarkGray);
sys_draw_button(EBX, HEADER_Y<<16+BTNSIZE, 911+BT_HIDE, clLightGray); draw_rectangle(CENTER_POS+1,HEADER_Y+1,BTNSIZE-2,BTNSIZE-2,clWhite,clWhite);
draw_rectangle(xsize/2-10,HEADER_Y,BTNSIZE,BTNSIZE,clWhite,clDarkGray); sys_put_palette_image(18*18*4*58 + iconimg, 18<<16+18, CENTER_POS+2<<16+HEADER_Y+2, 32, 0);
// <CHANGE MODE> BUTTON (1001) // <CHANGE MODE> BUTTON (1001)
sys_draw_button(5<<16+32, HEADER_Y<<16+BTNSIZE, 1001+BT_HIDE, clLightGray); sys_draw_button(5<<16+32, HEADER_Y<<16+BTNSIZE, 1001+BT_HIDE, clLightGray);
draw_rectangle(5,HEADER_Y,32,BTNSIZE,clWhite,clDarkGray); draw_rectangle(5,HEADER_Y,32,BTNSIZE,clWhite,clDarkGray);
game_mode[0] = mode + '0'; game_mode[0] = mode + '0';
sys_write_text(9<<16+HEADER_Y+3, 0x90000000+clDarkGray, #game_mode, 3); sys_write_text(9<<16+HEADER_Y+4, 0x90656565, #game_mode, 3);
// <USER FIELD> BUTTON (1002) // <USER FIELD> BUTTON (1002)
//sys_draw_button(BTNSIZE<<16+7, ECX, EDX+1, 0xddbb44); //sys_draw_button(BTNSIZE<<16+7, ECX, EDX+1, 0xddbb44);
draw_time(); // draw timer draw_time();
draw_mines_left(); // draw mines draw_mines_left();
draw_squares(); // draw field draw_squares();
sys_window_redraw(2);
} }
dword num_colors[8]= dword num_colors[8]=
@ -70,11 +69,11 @@ dword num_colors[8]=
}; };
// Îòðèñîâêà îäíîé êëåòêè // Draw a single square
void draw_square(int x, y) void draw_square(int x, y)
{ {
int xl, xr, yt, yb; // ñëåâà, ñïðàâà, ñâåðõó, ñíèçó int xl, xr, yt, yb; // lefx, right, top, bottom
dword tcolor = clBlack; // öâåò çíà÷åíèÿ êëåòêè ïî óìîë÷àíèþ ÷åðíûé dword tcolor = clBlack; // set default color as black
byte tchar, tval; byte tchar, tval;
xl = XPX * x + XST; xl = XPX * x + XST;
@ -86,7 +85,7 @@ void draw_square(int x, y)
ECX = yt+1 << 16 + yb - yt-1; ECX = yt+1 << 16 + yb - yt-1;
$inc ebx $inc ebx
$inc ecx $inc ecx
sys_draw_bar(EBX, ECX, clLightGray); // ðèñóåò çàêðàøåííûé ïðÿìîóãîëüíèê sys_draw_bar(EBX, ECX, clLightGray); // fill bg
if (!get_open(x, y)) if (!get_open(x, y))
{ {
@ -100,16 +99,16 @@ void draw_square(int x, y)
SWITCH (get_mark(x, y)) SWITCH (get_mark(x, y))
{ {
CASE 2: tcolor = 0x121288; tchar = '?'; BREAK; CASE 2: tcolor = 0x10121288; tchar = '?'; BREAK;
CASE 1: tcolor = 0xd04444; tchar = 'P'; CASE 1: tcolor = 0x10d04444; tchar = 'P';
} }
IF (get_mark(x,y)) IF (get_mark(x,y))
{ {
EBX = xl + 5 << 16 + yt + 4; EBX = xl + 6 << 16 + yt + 4;
sys_write_text(EBX, tcolor, #tchar, 1); sys_write_text(EBX, tcolor, #tchar, 1);
EBX += 0x00010000; EBX += 0x00010000;
/* Âòîðîé ðàç - ðåãèñòðû ñîõðàíÿþòñÿ */ /* Second run - registers are saved */
sys_write_text(EBX, ECX, EDX, ESI); sys_write_text(EBX, ECX, EDX, ESI);
} }
} }
@ -120,15 +119,15 @@ void draw_square(int x, y)
{ {
IF (tval == MINE) IF (tval == MINE)
{ {
tcolor = 0xee1111; tcolor = 0x10ee1111;
tchar = '*'; tchar = '*';
} }
ELSE ELSE
{ {
tchar = tval + '0'; tchar = tval + '0';
tcolor = num_colors[tval-1]; tcolor = num_colors[tval-1]+0x10000000;
} }
EBX = xl + 5 << 16 + yt + 5; EBX = xl + 7 << 16 + yt + 4;
sys_write_text(EBX, tcolor, #tchar, 1); sys_write_text(EBX, tcolor, #tchar, 1);
EBX += 0x00010000; EBX += 0x00010000;
sys_write_text(EBX, ECX, EDX, ESI); sys_write_text(EBX, ECX, EDX, ESI);
@ -140,19 +139,19 @@ void draw_square(int x, y)
void draw_time() void draw_time()
{ {
sys_draw_bar(xsize-XST-58<<16+29, HEADER_Y<<16+20, clWhiteGray); sys_draw_bar(xsize-XST-63<<16+34, HEADER_Y<<16+22, clWhiteGray);
sys_write_number(0x00030000, time, xsize-XST-56<<16+HEADER_Y+3, 0x101166C3); sys_write_number(0x00030000, time, xsize-XST-58<<16+HEADER_Y+4, 0x101166C3);
} }
void draw_mines_left() void draw_mines_left()
{ {
sys_draw_bar(xsize-XST-29<<16+29, HEADER_Y<<16+20, clWhiteGray); sys_draw_bar(xsize-XST-32<<16+32, HEADER_Y<<16+22, clWhiteGray);
sys_write_number(0x00030000, cmines, xsize-XST-27<<16+HEADER_Y+3, 0x10ff0000); sys_write_number(0x00030000, cmines, xsize-XST-29<<16+HEADER_Y+4, 0x10ff0000);
} }
// Îòðèñîâêà ìèííîãî ïîëÿ // Draw mine field
void draw_squares() void draw_squares()
{ {
int x,y; int x,y;

View File

@ -64,7 +64,8 @@ struct ProcessInfo
ystart, ystart,
xsize, xsize,
ysize; ysize;
byte not_used2[974]; char status_window;
byte reserved[1024-71];
}; };
#define SystemColors SystemColours // usa/british #define SystemColors SystemColours // usa/british
@ -212,6 +213,15 @@ inline fastcall dword sys_put_image(dword EBX, ECX, EDX)
$int 0x40 $int 0x40
} }
inline fastcall void sys_put_palette_image(dword EBX,ECX,EDX,ESI,EDI)
{
$push ebp
EAX = 65;
EBP = 0;
$int 0x40
$pop ebp
}
/********************************************************* /*********************************************************
08 = DEFINE BUTTON 08 = DEFINE BUTTON
@ -1117,11 +1127,44 @@ inline fastcall dword sys_debug_read_char(dword EBX)
} }
inline fastcall dword window_move_size(dword EBX,ECX,EDX,ESI){ inline fastcall dword sys_window_move_size(dword EBX,ECX,EDX,ESI){
EAX = 67; EAX = 67;
$int 0x40 $int 0x40
} }
/*********************************************************
68.11 = mem_init is required to work with heap
*********************************************************/
inline fastcall void sys_mem_init()
{
$mov eax, 68
$mov ebx, 11
$int 0x40
}
/*********************************************************
68.22 = shared memory
in:
ecx = area name, 31 symbols max
edx = area size for SHM_CREATE SHM_OPEN_ALWAYS
esi = flags, see the list below
out:
eax = pointer to memory or 0
edx = memsize
*********************************************************/
#define SHM_OPEN 0x00
#define SHM_OPEN_ALWAYS 0x04
#define SHM_CREATE 0x08
#define SHM_READ 0x00
#define SHM_WRITE 0x01
inline fastcall dword sys_memopen(ECX, EDX, ESI)
{
$mov eax, 68
$mov ebx, 22
$int 0x40
}
/********************************************************* /*********************************************************
-1 = EXIT PROCESS -1 = EXIT PROCESS

View File

@ -26,17 +26,26 @@
//? define DEBUG 1 //? define DEBUG 1
? print "\nÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿" ? print "\nÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿"
? print "\n³ KolibriOS MineSweeper v0.52 ³" ? print "\n³ KolibriOS MineSweeper v0.62 ³"
? print "\n³ (C) Leency (leency@mail.ru) 2010,2011 ³" ? print "\n³ (C) Leency (leency@mail.ru) 2010-2025 ³"
? print "\n³ (C) Ivan Poddubny (ivan-yar@bk.ru) 2003,2004 ³" ? print "\n³ (C) Ivan Poddubny (ivan-yar@bk.ru) 2003,2004 ³"
? print "\nÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ\n\n" ? print "\nÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ\n\n"
/************************************** DATA **************************************/ /************************************* DEFINES *************************************/
? define XPX 16 // X pixels by square - ðàçìåð êëåòêè â ïèêñåëÿõ ?define HEADER_Y 5
? define YPX 16 // Y pixels by square ?define BTNSIZE 21
?define CENTER_POS xsize / 2 - 10
?define XST 5 // offset of first pixel X - ñìåùåíèå ïîëÿ îò ãðàíèöû îêíà
?define YST 32
? define XPX 21 // X pixels by square - ðàçìåð êëåòêè â ïèêñåëÿõ
? define YPX 21 // Y pixels by square
? define MINE 255 // â êëåòêå ìèíà, åñëè value = MINE ? define MINE 255 // â êëåòêå ìèíà, åñëè value = MINE
/************************************** DATA **************************************/
struct struct
{ {
byte value; // number of mines - êîëè÷åñòâî ìèí â îêðóæàþùèõ êëåòêàõ byte value; // number of mines - êîëè÷åñòâî ìèí â îêðóæàþùèõ êëåòêàõ
@ -58,9 +67,6 @@ struct
byte nmines; byte nmines;
} stdmodes[3] = {9,9,10, 16,16,40, 30,16,99}; // {x,y,m} } stdmodes[3] = {9,9,10, 16,16,40, 30,16,99}; // {x,y,m}
?define XST 5 // offset of first pixel X - ñìåùåíèå ïîëÿ îò ãðàíèöû îêíà
?define YST 28
int ncx, // number of squares in X - ðàçìåð ïîëÿ int ncx, // number of squares in X - ðàçìåð ïîëÿ
ncy, ncy,
cmines, // mines discovered - êîëè÷åñòâî íåîòêðûòûõ ìèí cmines, // mines discovered - êîëè÷åñòâî íåîòêðûòûõ ìèí
@ -79,7 +85,7 @@ byte stop_game = FALSE, // game stopped -
firstmine; firstmine;
ProcessInfo procinfo; ProcessInfo procinfo;
SystemColors colors; //SystemColors colors;
/************************************** CODE **************************************/ /************************************** CODE **************************************/
@ -429,6 +435,8 @@ void end_game()
void main() void main()
{ {
sys_mem_init();
new_game(); new_game();
draw_window(); draw_window();
@ -458,11 +466,11 @@ void main()
ELSE IF (EAX == 1001) // change mode ELSE IF (EAX == 1001) // change mode
{ {
mode++; mode++;
if (mode==4) mode=1; IF (mode==4) mode=1;
//EAX = mode; EAX++; EAX = EAX%3; EAX++; mode = AL; //EAX = mode; EAX++; EAX = EAX%3; EAX++; mode = AL;
new_game(); new_game();
window_move_size(OLD,OLD,xsize+9,ysize); sys_window_move_size(OLD,OLD,xsize+9,ysize);
CONTINUE; CONTINUE;
} }
// ELSE IF (EAX == 1002) // ELSE IF (EAX == 1002)