1,7 → 1,7 |
/******************************************************************************* |
|
MenuetOS MineSweeper |
Copyright (C) 2003 Ivan Poddubny |
Copyright (C) 2003, 2004 Ivan Poddubny |
|
This program is free software; you can redistribute it and/or modify |
it under the terms of the GNU General Public License as published by |
19,22 → 19,22 |
|
*******************************************************************************/ |
|
//? pragma option LST // generate ASM listing file - ñîçäàòü àññåìáëåðíûé ëèñòèíã |
//? warning TRUE // âêëþ÷èòü ðåæèì âûâîäà ïðåäóïðåæäåíèé |
? pragma option meos |
? pragma option LST // generate ASM listing file - ñîçäàòü àññåìáëåðíûé ëèñòèíã |
? warning TRUE // âêëþ÷èòü ðåæèì âûâîäà ïðåäóïðåæäåíèé |
? jumptomain NONE |
? include "msys.h--" // MenuetOS system functions - ñèñòåìíûå ôóíêöèè MenuetOS |
//? define DEBUG 1 |
|
? print "\nÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿" |
? print "\n³ MeOS MineSweeper v0.3 ³" |
? print "\n³ (C) Ivan Poddubny (ivan-yar@bk.ru) 2003 ³" |
? print "\nÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ\n\n" |
? print "\nÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿" |
? print "\n³ MenuetOS MineSweeper v0.4 ³" |
? print "\n³ (C) Ivan Poddubny (ivan-yar@bk.ru) 2003,2004 ³" |
? print "\nÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ\n\n" |
|
/************************************** DATA **************************************/ |
|
? define XPX 16 // X pixels by square - ðàçìåð êëåòêè â ïèêñåëÿõ |
? define YPX 16 // Y pixels by square |
? define MINE 255 // çíà÷åíèå äëÿ ìèíû â ïîëå value |
? define MINE 255 // â êëåòêå ìèíà, åñëè value = MINE |
|
struct |
{ |
59,7 → 59,7 |
|
int XST, // offset of first pixel X - ñìåùåíèå ïîëÿ îò ãðàíèöû îêíà |
YST, |
ncx, // number of squares in X - ðàçìåð ïîë |
ncx, // number of squares in X - ðàçìåð ïîëÿ |
ncy, |
cmines, // mines discovered - êîëè÷åñòâî íåîòêðûòûõ ìèí |
initmines, // number of initial mines - èçíà÷àëüíîå êîëè÷åñòâî ìèí |
88,6 → 88,7 |
$int 0x40 |
} |
|
|
inline void fastcall mouse_disable() |
{ |
$mov eax,40 |
95,6 → 96,7 |
$int 0x40 |
} |
|
|
? include "timer.h--" // timer functions |
? include "draw.h--" // drawing functions |
? include "access.h--" // get & set functions |
101,8 → 103,9 |
? include "random.h--" // random number generator |
//? include "uf.h--" // user field window |
|
|
void init() |
// Èíèöèàëèçàöè |
// Èíèöèàëèçàöèÿ |
{ |
XST = 10; YST = 52; // FIELD POSITION IN WINDOW |
|
126,6 → 129,7 |
ysize = ncy * YPX + YST + XST; |
} // init |
|
|
void clear_all() |
// Î÷èñòèòü ïîëå |
{ |
135,10 → 139,11 |
$REP $STOSD |
} // clear_all |
|
|
void new_game() |
// Íîâàÿ èãðà |
{ |
init(); // èíèöèàëèçàöè |
init(); // èíèöèàëèçàöèÿ |
randomize(); // ãåíåðàòîð ñëó÷àéíûõ ÷èñåë |
clear_all(); // î÷èñòèòü ïîëå |
|
149,16 → 154,22 |
time = 0; // âðåìÿ = 0 |
} // new_game |
|
|
void set_mines(int nminas, no_x, no_y) |
// Ðàññòàâèòü ìèíû |
{ |
int i, x, y, a, b; |
|
#ifdef DEBUG |
sys_debug_write_string("MINE: set_mines called\n"); |
#endif |
|
sqclosed = ncx * ncy - nminas; // êîëè÷åñòâî ÍÅîòêðûòûõ êëåòîê = ïëîùàäü ïîëÿ - êîë-âî ìèí |
|
FOR (i = nminas; i > 0; i--) // ðàññòàâèòü ìèíû |
{ |
x = random(ncx); y = random(ncy); |
x = random(ncx); |
y = random(ncy); |
WHILE ((get_value(x, y) == MINE) || ((x == no_x) && (y == no_y))) |
{ |
x = random(ncx); |
190,6 → 201,7 |
} |
} // set_mines |
|
|
inline void do_mouse(void) |
// Îáðàáîò÷èê ìûøè |
{ |
196,7 → 208,11 |
int x,y; |
|
EAX = sys_read_mouse(2); // ìûøü íå íàæàòà -> âûõîä |
IF (EAX == 0) return; |
IF (EAX == 0) |
{ |
// sys_debug_write_string("Strange\n"); |
return; |
} |
|
mouse_status = AL; |
|
216,8 → 232,10 |
IF (firstmine == TRUE) |
{ |
firstmine = FALSE; |
set_mines(cmines, x, y); |
set_mines(initmines, x, y); |
start_timer(); |
time = 1; |
draw_time(); |
} |
IF (get_value(x, y) == MINE) |
{ |
252,10 → 270,10 |
end_game(); |
} |
|
if (sqclosed == 0) |
IF (sqclosed == 0) |
{ |
// îòêðûòû âñå êëåòêè |
// all squares are opened |
{ |
mouse_en = FALSE; // çàïðåòèòü ìûøü |
stop_timer(); |
stop_game = TRUE; // èãðà çàâåðøåíà |
273,11 → 291,16 |
} |
} // do_mouse |
|
|
void open_square(int x, y) |
// Îòêðûòü êëåòêó |
{ |
int a, b, i; |
|
#ifdef DEBUG |
sys_debug_write_string("MINE: open_square called\n"); |
#endif |
|
set_open(x, y, TRUE); |
sqclosed--; |
|
305,6 → 328,7 |
} |
} // open_square |
|
|
int open_near_squares(int x, y) |
// Îòêðûòü áëèçëåæàùèå êëåòêè (îáå êíîïêè ìûøè âìåñòå) |
{ |
311,6 → 335,10 |
int a, b, i; |
dword suma = 0; |
|
#ifdef DEBUG |
sys_debug_write_string("MINE: open_near_squares called\n"); |
#endif |
|
a = x; |
b = y; |
FOR (i = 0; i < 8; i++) |
349,16 → 377,21 |
open_square(a, b); |
} |
} |
RETURN suma; |
return suma; |
} |
ELSE |
RETURN 0; |
return 0; |
} // open_near_squares |
|
|
void end_game() |
{ |
int x,y; |
|
#ifdef DEBUG |
sys_debug_write_string("MINE: end_game called\n"); |
#endif |
|
stop_game = TRUE; |
stop_timer(); |
for (x=0; x<ncx; x++) |
397,7 → 430,7 |
|
void main() |
{ |
sys_delay(5); // for old kernel only! |
//sys_delay(5); // for old kernel only! |
new_game(); |
draw_window(); |
|
406,16 → 439,16 |
{ |
switch (sys_wait_event_timeout(100)) // wait for 1 second |
{ |
CASE evReDraw: |
case evReDraw: |
draw_window(); |
continue; |
|
CASE evKey: |
case evKey: |
IF (sys_get_key() == 27) |
sys_exit_process(); |
continue; |
|
CASE evButton: |
case evButton: |
EAX = sys_get_button_id(); |
IF (EAX == 911) // new game |
{ |
429,14 → 462,13 |
// mode++; mode%=3; mode++; |
EAX = mode; EAX++; EAX = EAX%3; EAX++; mode = AL; |
|
// get window position - ïîëó÷èòü êîîðäèíàòû îêíà |
sys_process_info(#procinfo, -1); |
xpos = procinfo.xstart; |
ypos = procinfo.ystart; |
|
// start a new process and terminate this one |
sys_create_thread(#main, ESP); |
sys_exit_process(); |
new_game(); |
EBX = ECX = -1; |
EDX = xsize; |
ESI = ysize; |
EAX = 67; |
$int 0x40 |
continue; |
} |
//ELSE IF (EAX == 1002) |
//{ |
444,17 → 476,17 |
//} |
ELSE IF (EAX == 1) // close window |
sys_exit_process(); |
CONTINUE; |
continue; |
|
case evMouse: |
IF (!mouse_en) // is mouse enabled ? |
CONTINUE; |
continue; |
do_mouse(); |
// wait for mouse release - æäàòü îòïóñêàíèÿ êíîïêè |
WHILE (sys_read_mouse(2) == mouse_status) |
{ |
check_timer(); |
sys_delay(6); |
sys_delay(3); |
CONTINUE; |
} |
check_timer(); |