#include <stdio.h>
|
#include <stdio.h>
|
#include <stdlib.h>
|
#include <stdlib.h>
|
#include <time.h>
|
#include <time.h>
|
#include <string.h>
|
#include <string.h>
|
/*
|
/*
|
* Minesweeper for Microwindows, adapted from MiniGUI
|
* Minesweeper for Microwindows, adapted from MiniGUI
|
*/
|
*/
|
extern int mwCurrentButtons; /* FIXME */
|
extern int mwCurrentButtons; /* FIXME */
|
|
|
|
|
#ifdef __rtems__
|
#ifdef __rtems__
|
#define srandom srand
|
#define srandom srand
|
#define random rand
|
#define random rand
|
#endif
|
#endif
|
|
|
#define MWINCLUDECOLORS
|
#define MWINCLUDECOLORS
|
#include "windows.h"
|
#include "windows.h"
|
#include "wintools.h"
|
#include "wintools.h"
|
|
|
typedef struct {
|
typedef struct {
|
int flag;
|
int flag;
|
int value;
|
int value;
|
BOOL test;
|
BOOL test;
|
BOOL hit;
|
BOOL hit;
|
BOOL bombout;
|
BOOL bombout;
|
BOOL error;
|
BOOL error;
|
}BOM;
|
}BOM;
|
|
|
typedef struct {
|
typedef struct {
|
int x;
|
int x;
|
int y;
|
int y;
|
BOOL NY;
|
BOOL NY;
|
}NO;
|
}NO;
|
|
|
typedef struct {
|
typedef struct {
|
int highscore;
|
int highscore;
|
char name[20];
|
char name[20];
|
}SCORE;
|
}SCORE;
|
|
|
typedef struct {
|
typedef struct {
|
DWORD dwStyle;
|
DWORD dwStyle;
|
LPSTR spCaption;
|
LPSTR spCaption;
|
HMENU hMenu;
|
HMENU hMenu;
|
HCURSOR hCursor;
|
HCURSOR hCursor;
|
HICON hIcon;
|
HICON hIcon;
|
WNDPROC MainWindowProc;
|
WNDPROC MainWindowProc;
|
int lx, ty, rx, by;
|
int lx, ty, rx, by;
|
COLORREF iBkColor;
|
COLORREF iBkColor;
|
DWORD dwAddData;
|
DWORD dwAddData;
|
HWND hHosting;
|
HWND hHosting;
|
} MAINWINCREATE, *PMAINWINCREATE;
|
} MAINWINCREATE, *PMAINWINCREATE;
|
|
|
#define IDOK 0
|
#define IDOK 0
|
#define GetCharWidth() 11
|
#define GetCharWidth() 11
|
#define GetCharHeight() 13
|
#define GetCharHeight() 13
|
|
|
extern MWIMAGEHDR image_mineflag;
|
extern MWIMAGEHDR image_mineflag;
|
extern MWIMAGEHDR image_mineface;
|
extern MWIMAGEHDR image_mineface;
|
extern MWIMAGEHDR image_minefacelost;
|
extern MWIMAGEHDR image_minefacelost;
|
extern MWIMAGEHDR image_minebomb;
|
extern MWIMAGEHDR image_minebomb;
|
extern MWIMAGEHDR image_minedone;
|
extern MWIMAGEHDR image_minedone;
|
extern MWIMAGEHDR image_minehitfalse;
|
extern MWIMAGEHDR image_minehitfalse;
|
|
|
HWND CreateMainWindow(PMAINWINCREATE pCreateInfo);
|
HWND CreateMainWindow(PMAINWINCREATE pCreateInfo);
|
BOOL PtInRect2(const RECT *lprc, int x, int y);
|
BOOL PtInRect2(const RECT *lprc, int x, int y);
|
void Draw3DUpFrame(HDC hDC, int l, int t, int r, int b, int fillc);
|
void Draw3DUpFrame(HDC hDC, int l, int t, int r, int b, int fillc);
|
void SearchGround(HDC hdc,int x,int y);
|
void SearchGround(HDC hdc,int x,int y);
|
int Open(HWND hWnd,int x,int y);
|
int Open(HWND hWnd,int x,int y);
|
LRESULT TestMyWinProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);
|
LRESULT TestMyWinProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);
|
void InitMyWinCreateInfo(PMAINWINCREATE pCreateInfo);
|
void InitMyWinCreateInfo(PMAINWINCREATE pCreateInfo);
|
void InitAbHostedCreateInfo(HWND hHosting, PMAINWINCREATE pCreateInfo);
|
void InitAbHostedCreateInfo(HWND hHosting, PMAINWINCREATE pCreateInfo);
|
void InitHighScoreCreateInfo (HWND hHosting, PMAINWINCREATE pCreateInfo);
|
void InitHighScoreCreateInfo (HWND hHosting, PMAINWINCREATE pCreateInfo);
|
void InitCongratulationCreateInfo (HWND hHosting, PMAINWINCREATE pCreateInfo);
|
void InitCongratulationCreateInfo (HWND hHosting, PMAINWINCREATE pCreateInfo);
|
void* TestMyWindow(void* data);
|
void* TestMyWindow(void* data);
|
void BombGame(HWND hWnd, int x, int y);
|
void BombGame(HWND hWnd, int x, int y);
|
void Finished(HWND hWnd);
|
void Finished(HWND hWnd);
|
void Cancel3DFrame(HDC hdc, int l,int t,int r,int b);
|
void Cancel3DFrame(HDC hdc, int l,int t,int r,int b);
|
void TextValue(HDC hdc, int x,int y,int value);
|
void TextValue(HDC hdc, int x,int y,int value);
|
void BombOut(HWND hWnd);
|
void BombOut(HWND hWnd);
|
void BothButtonDownProc(HWND hWnd, int x, int y);
|
void BothButtonDownProc(HWND hWnd, int x, int y);
|
void DrawDigit(HDC hdc, char* buffer, int CLOCK);
|
void DrawDigit(HDC hdc, char* buffer, int CLOCK);
|
|
|
#define ID_ABOUT 300
|
#define ID_ABOUT 300
|
#define ID_NEW 301
|
#define ID_NEW 301
|
#define ID_LARGE 302
|
#define ID_LARGE 302
|
#define ID_MIDDLE 303
|
#define ID_MIDDLE 303
|
#define ID_SMALL 304
|
#define ID_SMALL 304
|
#define ID_CLOSE 305
|
#define ID_CLOSE 305
|
#define ID_HIGHSCORE 306
|
#define ID_HIGHSCORE 306
|
#define ID_CLOCK 400
|
#define ID_CLOCK 400
|
|
|
#define WIDTH_LARGEWIN 544
|
#define WIDTH_LARGEWIN 544
|
#define HEIGHT_LARGEWIN 371
|
#define HEIGHT_LARGEWIN 371
|
#define WIDTH_MIDDLEWIN 287
|
#define WIDTH_MIDDLEWIN 287
|
#define HEIGHT_MIDDLEWIN 332
|
#define HEIGHT_MIDDLEWIN 332
|
#define WIDTH_SMALLWIN 178
|
#define WIDTH_SMALLWIN 178
|
#define HEIGHT_SMALLWIN 206
|
#define HEIGHT_SMALLWIN 206
|
|
|
#define WIDTH_FACE 30
|
#define WIDTH_FACE 30
|
#define HEIGHT_FACE 30
|
#define HEIGHT_FACE 30
|
|
|
#define WIDTH_DIGIT 11
|
#define WIDTH_DIGIT 11
|
#define WIDTH_BOMNUM (2*WIDTH_DIGIT)
|
#define WIDTH_BOMNUM (2*WIDTH_DIGIT)
|
#define HEIGHT_BOMNUM 30
|
#define HEIGHT_BOMNUM 30
|
|
|
#define WIDTH_CLOCK (3*WIDTH_DIGIT)
|
#define WIDTH_CLOCK (3*WIDTH_DIGIT)
|
#define HEIGHT_CLOCK 30
|
#define HEIGHT_CLOCK 30
|
#define FREQ_CLOCK 1000
|
#define FREQ_CLOCK 1000
|
|
|
#define WIDTH_BOX 18
|
#define WIDTH_BOX 18
|
#define HEIGHT_BOX 18
|
#define HEIGHT_BOX 18
|
|
|
#if 0
|
#if 0
|
static int winwidth = WIDTH_LARGEWIN; /* change this for startup mine size */
|
static int winwidth = WIDTH_LARGEWIN; /* change this for startup mine size */
|
static int winheight = HEIGHT_LARGEWIN;
|
static int winheight = HEIGHT_LARGEWIN;
|
static int sg_boxnumx = 30;
|
static int sg_boxnumx = 30;
|
static int sg_boxnumy = 18;
|
static int sg_boxnumy = 18;
|
static int bombnum = 99;
|
static int bombnum = 99;
|
#endif
|
#endif
|
|
|
#if 1
|
#if 1
|
static int winwidth = WIDTH_MIDDLEWIN; /* change this for startup mine size */
|
static int winwidth = WIDTH_MIDDLEWIN; /* change this for startup mine size */
|
static int winheight = HEIGHT_MIDDLEWIN;
|
static int winheight = HEIGHT_MIDDLEWIN;
|
static int sg_boxnumx = 16;
|
static int sg_boxnumx = 16;
|
static int sg_boxnumy = 16;
|
static int sg_boxnumy = 16;
|
static int bombnum = 40;
|
static int bombnum = 40;
|
#endif
|
#endif
|
|
|
#if 0
|
#if 0
|
static int winwidth = WIDTH_SMALLWIN; /* change this for startup mine size */
|
static int winwidth = WIDTH_SMALLWIN; /* change this for startup mine size */
|
static int winheight = HEIGHT_SMALLWIN;
|
static int winheight = HEIGHT_SMALLWIN;
|
static int sg_boxnumx = 8;
|
static int sg_boxnumx = 8;
|
static int sg_boxnumy = 8;
|
static int sg_boxnumy = 8;
|
static int bombnum = 10;
|
static int bombnum = 10;
|
#endif
|
#endif
|
|
|
static BOM bom[30][18];
|
static BOM bom[30][18];
|
static NO NoAdr[540];
|
static NO NoAdr[540];
|
static SCORE score[3];
|
static SCORE score[3];
|
static int itime, leftbombnum;
|
static int itime, leftbombnum;
|
static int oldx, oldy, adrx, adry;
|
static int oldx, oldy, adrx, adry;
|
static int flag_bombout, flag_finished, flag_size = 2;
|
static int flag_bombout, flag_finished, flag_size = 2;
|
static int second = 0 ;
|
static int second = 0 ;
|
static BOOL bTimer;
|
static BOOL bTimer;
|
static HWND hHighscore,hCongratulate;
|
static HWND hHighscore,hCongratulate;
|
static int offsetx;
|
static int offsetx;
|
static int x_face, x_bomnum, x_clock;
|
static int x_face, x_bomnum, x_clock;
|
|
|
void Cancel3DFrame(HDC hdc, int l, int t, int w, int h)
|
void Cancel3DFrame(HDC hdc, int l, int t, int w, int h)
|
{
|
{
|
HBRUSH hbr;
|
HBRUSH hbr;
|
RECT rc;
|
RECT rc;
|
|
|
SetTextColor (hdc,GRAY);
|
SetTextColor (hdc,GRAY);
|
Rectangle(hdc, l, t, l + w, t + h);
|
Rectangle(hdc, l, t, l + w, t + h);
|
hbr = CreateSolidBrush(LTGRAY);
|
hbr = CreateSolidBrush(LTGRAY);
|
SetRect(&rc, l+1, t+1, l+w, t+h);
|
SetRect(&rc, l+1, t+1, l+w, t+h);
|
FillRect(hdc, &rc, hbr);
|
FillRect(hdc, &rc, hbr);
|
DeleteObject(hbr);
|
DeleteObject(hbr);
|
}
|
}
|
|
|
void TextValue(HDC hdc, int x, int y, int value)
|
void TextValue(HDC hdc, int x, int y, int value)
|
{
|
{
|
int color = 0;
|
int color = 0;
|
char va[20];
|
char va[20];
|
switch(value)
|
switch(value)
|
{
|
{
|
case 1: color=BLUE; break;
|
case 1: color=BLUE; break;
|
case 2: color=GREEN; break;
|
case 2: color=GREEN; break;
|
case 3: color=RED; break;
|
case 3: color=RED; break;
|
case 4: color=MAGENTA; break;
|
case 4: color=MAGENTA; break;
|
case 5: color=YELLOW; break;
|
case 5: color=YELLOW; break;
|
case 6: color=CYAN; break;
|
case 6: color=CYAN; break;
|
case 7: color=RED; break;
|
case 7: color=RED; break;
|
case 8: color=GREEN; break;
|
case 8: color=GREEN; break;
|
}
|
}
|
SetBkColor(hdc,LTGRAY);
|
SetBkColor(hdc,LTGRAY);
|
SetTextColor(hdc,color);
|
SetTextColor(hdc,color);
|
sprintf(va,"%d",value);
|
sprintf(va,"%d",value);
|
|
|
TextOut(hdc, x + ((WIDTH_BOX - GetCharWidth ()) >> 1),
|
TextOut(hdc, x + ((WIDTH_BOX - GetCharWidth ()) >> 1),
|
y + ((HEIGHT_BOX - GetCharHeight ()) >> 1), va, -1);
|
y + ((HEIGHT_BOX - GetCharHeight ()) >> 1), va, -1);
|
}
|
}
|
|
|
void SearchGround(HDC hdc,int x,int y)
|
void SearchGround(HDC hdc,int x,int y)
|
{
|
{
|
int x1=0,y1=0;
|
int x1=0,y1=0;
|
int i=1;
|
int i=1;
|
|
|
bom[x][y].test=TRUE;
|
bom[x][y].test=TRUE;
|
NoAdr[itime].x=x;
|
NoAdr[itime].x=x;
|
NoAdr[itime].y=y;
|
NoAdr[itime].y=y;
|
NoAdr[itime].NY=FALSE;
|
NoAdr[itime].NY=FALSE;
|
itime++;
|
itime++;
|
Cancel3DFrame(hdc,x*WIDTH_BOX+offsetx, y*HEIGHT_BOX+HEIGHT_FACE,
|
Cancel3DFrame(hdc,x*WIDTH_BOX+offsetx, y*HEIGHT_BOX+HEIGHT_FACE,
|
WIDTH_BOX, HEIGHT_BOX);
|
WIDTH_BOX, HEIGHT_BOX);
|
while( i <= 8 )
|
while( i <= 8 )
|
{
|
{
|
switch(i)
|
switch(i)
|
{
|
{
|
case 1: x1=x-1; y1=y; break;
|
case 1: x1=x-1; y1=y; break;
|
case 2: x1=x-1; y1=y-1; break;
|
case 2: x1=x-1; y1=y-1; break;
|
case 3: x1=x-1; y1=y+1; break;
|
case 3: x1=x-1; y1=y+1; break;
|
case 4: x1=x+1; y1=y; break;
|
case 4: x1=x+1; y1=y; break;
|
case 5: x1=x+1; y1=y-1; break;
|
case 5: x1=x+1; y1=y-1; break;
|
case 6: x1=x+1; y1=y+1; break;
|
case 6: x1=x+1; y1=y+1; break;
|
case 7: y1=y-1; x1=x; break;
|
case 7: y1=y-1; x1=x; break;
|
case 8: y1=y+1; x1=x; break;
|
case 8: y1=y+1; x1=x; break;
|
}
|
}
|
if( x1>=0 && y1>=0 && x1<sg_boxnumx && y1<sg_boxnumy
|
if( x1>=0 && y1>=0 && x1<sg_boxnumx && y1<sg_boxnumy
|
&&!bom[x1][y1].hit&& !bom[x1][y1].test && !bom[x1][y1].value )
|
&&!bom[x1][y1].hit&& !bom[x1][y1].test && !bom[x1][y1].value )
|
SearchGround(hdc,x1,y1);
|
SearchGround(hdc,x1,y1);
|
|
|
if( x1>=0 && y1>=0 && x1<sg_boxnumx && y1<sg_boxnumy
|
if( x1>=0 && y1>=0 && x1<sg_boxnumx && y1<sg_boxnumy
|
&&!bom[x1][y1].hit
|
&&!bom[x1][y1].hit
|
&&!bom[x1][y1].test && bom[x1][y1].value!=0 )
|
&&!bom[x1][y1].test && bom[x1][y1].value!=0 )
|
{
|
{
|
bom[x1][y1].test=TRUE;
|
bom[x1][y1].test=TRUE;
|
NoAdr[itime].x=x1;
|
NoAdr[itime].x=x1;
|
NoAdr[itime].y=y1;
|
NoAdr[itime].y=y1;
|
NoAdr[itime].NY=TRUE;
|
NoAdr[itime].NY=TRUE;
|
itime++;
|
itime++;
|
Cancel3DFrame(hdc, x1*WIDTH_BOX+offsetx, y1*HEIGHT_BOX+HEIGHT_FACE,
|
Cancel3DFrame(hdc, x1*WIDTH_BOX+offsetx, y1*HEIGHT_BOX+HEIGHT_FACE,
|
WIDTH_BOX, HEIGHT_BOX);
|
WIDTH_BOX, HEIGHT_BOX);
|
TextValue(hdc, x1*WIDTH_BOX+offsetx, y1*HEIGHT_BOX+HEIGHT_FACE,
|
TextValue(hdc, x1*WIDTH_BOX+offsetx, y1*HEIGHT_BOX+HEIGHT_FACE,
|
bom[x1][y1].value);
|
bom[x1][y1].value);
|
}
|
}
|
i++;
|
i++;
|
}
|
}
|
}
|
}
|
|
|
BOOL Open(HWND hWnd,int x,int y)
|
BOOL Open(HWND hWnd,int x,int y)
|
{
|
{
|
int x1=0,y1=0;
|
int x1=0,y1=0;
|
int i=1;
|
int i=1;
|
HDC hdc;
|
HDC hdc;
|
|
|
hdc = GetDC(hWnd);
|
hdc = GetDC(hWnd);
|
while( i <= 8 )
|
while( i <= 8 )
|
{
|
{
|
switch( i ) {
|
switch( i ) {
|
case 1: x1=x-1; y1=y; break;
|
case 1: x1=x-1; y1=y; break;
|
case 2: x1=x-1; y1=y-1; break;
|
case 2: x1=x-1; y1=y-1; break;
|
case 3: x1=x-1; y1=y+1; break;
|
case 3: x1=x-1; y1=y+1; break;
|
case 4: x1=x+1; y1=y; break;
|
case 4: x1=x+1; y1=y; break;
|
case 5: x1=x+1; y1=y-1; break;
|
case 5: x1=x+1; y1=y-1; break;
|
case 6: x1=x+1; y1=y+1; break;
|
case 6: x1=x+1; y1=y+1; break;
|
case 7: y1=y-1; x1=x; break;
|
case 7: y1=y-1; x1=x; break;
|
case 8: y1=y+1; x1=x; break;
|
case 8: y1=y+1; x1=x; break;
|
}
|
}
|
|
|
if( x1>=0 && y1>=0 && x1<sg_boxnumx && y1<sg_boxnumy
|
if( x1>=0 && y1>=0 && x1<sg_boxnumx && y1<sg_boxnumy
|
&& !bom[x1][y1].hit && bom[x1][y1].flag) {
|
&& !bom[x1][y1].hit && bom[x1][y1].flag) {
|
ReleaseDC(hWnd, hdc);
|
ReleaseDC(hWnd, hdc);
|
return FALSE;
|
return FALSE;
|
}
|
}
|
|
|
if( x1>=0 && y1>=0 && x1<sg_boxnumx && y1<sg_boxnumy
|
if( x1>=0 && y1>=0 && x1<sg_boxnumx && y1<sg_boxnumy
|
&& !bom[x1][y1].test && !bom[x1][y1].value
|
&& !bom[x1][y1].test && !bom[x1][y1].value
|
&& !bom[x1][y1].flag ){
|
&& !bom[x1][y1].flag ){
|
SearchGround(hdc,x1,y1);
|
SearchGround(hdc,x1,y1);
|
}
|
}
|
|
|
if( x1>=0 && y1>=0 && x1<sg_boxnumx && y1<sg_boxnumy
|
if( x1>=0 && y1>=0 && x1<sg_boxnumx && y1<sg_boxnumy
|
&& !bom[x1][y1].test && bom[x1][y1].value!=0 )
|
&& !bom[x1][y1].test && bom[x1][y1].value!=0 )
|
{
|
{
|
bom[x1][y1].test=TRUE;
|
bom[x1][y1].test=TRUE;
|
NoAdr[itime].x=x1;
|
NoAdr[itime].x=x1;
|
NoAdr[itime].y=y1;
|
NoAdr[itime].y=y1;
|
NoAdr[itime].NY=TRUE;
|
NoAdr[itime].NY=TRUE;
|
itime++;
|
itime++;
|
Cancel3DFrame(hdc, x1*WIDTH_BOX+offsetx, y1*HEIGHT_BOX+HEIGHT_FACE,
|
Cancel3DFrame(hdc, x1*WIDTH_BOX+offsetx, y1*HEIGHT_BOX+HEIGHT_FACE,
|
WIDTH_BOX, HEIGHT_BOX);
|
WIDTH_BOX, HEIGHT_BOX);
|
TextValue(hdc, x1*WIDTH_BOX+offsetx, y1*HEIGHT_BOX+HEIGHT_FACE,
|
TextValue(hdc, x1*WIDTH_BOX+offsetx, y1*HEIGHT_BOX+HEIGHT_FACE,
|
bom[x1][y1].value);
|
bom[x1][y1].value);
|
}
|
}
|
i++;
|
i++;
|
}
|
}
|
|
|
ReleaseDC(hWnd, hdc);
|
ReleaseDC(hWnd, hdc);
|
return TRUE;
|
return TRUE;
|
}
|
}
|
|
|
void BombOut(HWND hWnd)
|
void BombOut(HWND hWnd)
|
{
|
{
|
int i,j;
|
int i,j;
|
HDC hdc;
|
HDC hdc;
|
|
|
hdc=GetDC(hWnd);
|
hdc=GetDC(hWnd);
|
|
|
for (i = 0; i < sg_boxnumx; i++) {
|
for (i = 0; i < sg_boxnumx; i++) {
|
for (j = 0; j < sg_boxnumy; j++) {
|
for (j = 0; j < sg_boxnumy; j++) {
|
if (bom[i][j].flag && !bom[i][j].hit) {
|
if (bom[i][j].flag && !bom[i][j].hit) {
|
Cancel3DFrame(hdc,i*WIDTH_BOX+offsetx,j*HEIGHT_BOX+HEIGHT_FACE,
|
Cancel3DFrame(hdc,i*WIDTH_BOX+offsetx,j*HEIGHT_BOX+HEIGHT_FACE,
|
WIDTH_BOX,HEIGHT_BOX);
|
WIDTH_BOX,HEIGHT_BOX);
|
|
|
DrawDIB(hdc, i*WIDTH_BOX+offsetx+1, j*HEIGHT_BOX+1+HEIGHT_FACE,
|
DrawDIB(hdc, i*WIDTH_BOX+offsetx+1, j*HEIGHT_BOX+1+HEIGHT_FACE,
|
&image_minebomb);
|
&image_minebomb);
|
bom[i][j].bombout = TRUE;
|
bom[i][j].bombout = TRUE;
|
}
|
}
|
if (!bom[i][j].flag && bom[i][j].hit){
|
if (!bom[i][j].flag && bom[i][j].hit){
|
Cancel3DFrame(hdc,i*WIDTH_BOX+offsetx,j*HEIGHT_BOX+HEIGHT_FACE,
|
Cancel3DFrame(hdc,i*WIDTH_BOX+offsetx,j*HEIGHT_BOX+HEIGHT_FACE,
|
WIDTH_BOX,HEIGHT_BOX);
|
WIDTH_BOX,HEIGHT_BOX);
|
|
|
DrawDIB(hdc, i*WIDTH_BOX+offsetx+1, j*HEIGHT_BOX+1+HEIGHT_FACE,
|
DrawDIB(hdc, i*WIDTH_BOX+offsetx+1, j*HEIGHT_BOX+1+HEIGHT_FACE,
|
&image_minehitfalse);
|
&image_minehitfalse);
|
bom[i][j].error = TRUE;
|
bom[i][j].error = TRUE;
|
|
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
DrawDIB(hdc, x_face, 0, &image_minefacelost);
|
DrawDIB(hdc, x_face, 0, &image_minefacelost);
|
flag_bombout = 1;
|
flag_bombout = 1;
|
bTimer = FALSE;
|
bTimer = FALSE;
|
ReleaseDC(hWnd, hdc);
|
ReleaseDC(hWnd, hdc);
|
}
|
}
|
|
|
void Finished(HWND hWnd)
|
void Finished(HWND hWnd)
|
{
|
{
|
int i,j;
|
int i,j;
|
HDC hdc;
|
HDC hdc;
|
RECT bombnumber;
|
RECT bombnumber;
|
MAINWINCREATE CreateInfo;
|
MAINWINCREATE CreateInfo;
|
|
|
hdc = GetDC(hWnd);
|
hdc = GetDC(hWnd);
|
|
|
for (i = 0; i < sg_boxnumx; i++) {
|
for (i = 0; i < sg_boxnumx; i++) {
|
for (j = 0; j < sg_boxnumy; j++) {
|
for (j = 0; j < sg_boxnumy; j++) {
|
if (bom[i][j].flag && !bom[i][j].hit) {
|
if (bom[i][j].flag && !bom[i][j].hit) {
|
|
|
DrawDIB(hdc, i*WIDTH_BOX+offsetx+3, j*HEIGHT_BOX+3+HEIGHT_FACE,
|
DrawDIB(hdc, i*WIDTH_BOX+offsetx+3, j*HEIGHT_BOX+3+HEIGHT_FACE,
|
&image_mineflag);
|
&image_mineflag);
|
bom[i][j].hit = TRUE;
|
bom[i][j].hit = TRUE;
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
DrawDIB(hdc, x_face+1, 1, &image_minedone);
|
DrawDIB(hdc, x_face+1, 1, &image_minedone);
|
flag_finished = 1;
|
flag_finished = 1;
|
bTimer = FALSE;
|
bTimer = FALSE;
|
ReleaseDC(hWnd, hdc);
|
ReleaseDC(hWnd, hdc);
|
|
|
leftbombnum = 0;
|
leftbombnum = 0;
|
|
|
SetRect (&bombnumber, x_bomnum, 0,
|
SetRect (&bombnumber, x_bomnum, 0,
|
x_bomnum + WIDTH_BOMNUM, HEIGHT_BOMNUM);
|
x_bomnum + WIDTH_BOMNUM, HEIGHT_BOMNUM);
|
InvalidateRect (hWnd, &bombnumber, FALSE);
|
InvalidateRect (hWnd, &bombnumber, FALSE);
|
|
|
if (second < score[flag_size].highscore){
|
if (second < score[flag_size].highscore){
|
InitCongratulationCreateInfo(hWnd, &CreateInfo);
|
InitCongratulationCreateInfo(hWnd, &CreateInfo);
|
hCongratulate = CreateMainWindow (&CreateInfo);
|
hCongratulate = CreateMainWindow (&CreateInfo);
|
}
|
}
|
}
|
}
|
|
|
#if 0
|
#if 0
|
HMENU createpmenuabout()
|
HMENU createpmenuabout()
|
{
|
{
|
HMENU hmnu;
|
HMENU hmnu;
|
MENUITEMINFO mii;
|
MENUITEMINFO mii;
|
memset (&mii, 0, sizeof(MENUITEMINFO));
|
memset (&mii, 0, sizeof(MENUITEMINFO));
|
mii.type = MFT_STRING;
|
mii.type = MFT_STRING;
|
mii.id = 0;
|
mii.id = 0;
|
mii.typedata = (DWORD)"About";
|
mii.typedata = (DWORD)"About";
|
hmnu = CreatePopupMenu (&mii);
|
hmnu = CreatePopupMenu (&mii);
|
|
|
memset (&mii, 0, sizeof(MENUITEMINFO));
|
memset (&mii, 0, sizeof(MENUITEMINFO));
|
mii.type = MFT_STRING ;
|
mii.type = MFT_STRING ;
|
mii.state = 0;
|
mii.state = 0;
|
mii.id = ID_ABOUT;
|
mii.id = ID_ABOUT;
|
mii.typedata = (DWORD)"About Bomb Game";
|
mii.typedata = (DWORD)"About Bomb Game";
|
InsertMenuItem(hmnu, 3, TRUE, &mii);
|
InsertMenuItem(hmnu, 3, TRUE, &mii);
|
|
|
return hmnu;
|
return hmnu;
|
}
|
}
|
|
|
HMENU createpmenustart()
|
HMENU createpmenustart()
|
{
|
{
|
HMENU hmnu;
|
HMENU hmnu;
|
MENUITEMINFO mii;
|
MENUITEMINFO mii;
|
memset (&mii, 0, sizeof(MENUITEMINFO));
|
memset (&mii, 0, sizeof(MENUITEMINFO));
|
mii.type = MFT_STRING;
|
mii.type = MFT_STRING;
|
mii.id = 0;
|
mii.id = 0;
|
mii.typedata = (DWORD)"Start";
|
mii.typedata = (DWORD)"Start";
|
hmnu = CreatePopupMenu (&mii);
|
hmnu = CreatePopupMenu (&mii);
|
|
|
memset (&mii, 0, sizeof(MENUITEMINFO));
|
memset (&mii, 0, sizeof(MENUITEMINFO));
|
mii.type = MFT_STRING ;
|
mii.type = MFT_STRING ;
|
mii.state = 0;
|
mii.state = 0;
|
mii.id = ID_NEW;
|
mii.id = ID_NEW;
|
mii.typedata = (DWORD)"New Game";
|
mii.typedata = (DWORD)"New Game";
|
InsertMenuItem(hmnu, 0, TRUE, &mii);
|
InsertMenuItem(hmnu, 0, TRUE, &mii);
|
|
|
mii.type = MFT_STRING ;
|
mii.type = MFT_STRING ;
|
mii.state = 0;
|
mii.state = 0;
|
mii.id = ID_HIGHSCORE;
|
mii.id = ID_HIGHSCORE;
|
mii.typedata = (DWORD)"High Score";
|
mii.typedata = (DWORD)"High Score";
|
InsertMenuItem(hmnu, 1, TRUE, &mii);
|
InsertMenuItem(hmnu, 1, TRUE, &mii);
|
|
|
mii.type = MFT_STRING ;
|
mii.type = MFT_STRING ;
|
mii.state = 0;
|
mii.state = 0;
|
mii.id = ID_CLOSE;
|
mii.id = ID_CLOSE;
|
mii.typedata = (DWORD)"Quit Game";
|
mii.typedata = (DWORD)"Quit Game";
|
InsertMenuItem(hmnu, 2, TRUE, &mii);
|
InsertMenuItem(hmnu, 2, TRUE, &mii);
|
|
|
return hmnu;
|
return hmnu;
|
}
|
}
|
|
|
HMENU createpmenulevel()
|
HMENU createpmenulevel()
|
{
|
{
|
HMENU hmnu;
|
HMENU hmnu;
|
MENUITEMINFO mii;
|
MENUITEMINFO mii;
|
memset (&mii, 0, sizeof(MENUITEMINFO));
|
memset (&mii, 0, sizeof(MENUITEMINFO));
|
mii.type = MFT_STRING;
|
mii.type = MFT_STRING;
|
mii.id = 0;
|
mii.id = 0;
|
mii.typedata = (DWORD)"Level";
|
mii.typedata = (DWORD)"Level";
|
hmnu = CreatePopupMenu (&mii);
|
hmnu = CreatePopupMenu (&mii);
|
|
|
mii.type = MFT_STRING ;
|
mii.type = MFT_STRING ;
|
mii.state = 0;
|
mii.state = 0;
|
mii.id = ID_LARGE;
|
mii.id = ID_LARGE;
|
mii.typedata = (DWORD)"Large";
|
mii.typedata = (DWORD)"Large";
|
InsertMenuItem(hmnu, 0, TRUE, &mii);
|
InsertMenuItem(hmnu, 0, TRUE, &mii);
|
|
|
mii.type = MFT_STRING ;
|
mii.type = MFT_STRING ;
|
mii.state = 0;
|
mii.state = 0;
|
mii.id = ID_MIDDLE;
|
mii.id = ID_MIDDLE;
|
mii.typedata = (DWORD)"Middle";
|
mii.typedata = (DWORD)"Middle";
|
InsertMenuItem(hmnu, 1, TRUE, &mii);
|
InsertMenuItem(hmnu, 1, TRUE, &mii);
|
|
|
mii.type = MFT_STRING ;
|
mii.type = MFT_STRING ;
|
mii.state = 0;
|
mii.state = 0;
|
mii.id = ID_SMALL;
|
mii.id = ID_SMALL;
|
mii.typedata = (DWORD)"Small";
|
mii.typedata = (DWORD)"Small";
|
InsertMenuItem(hmnu, 2, TRUE, &mii);
|
InsertMenuItem(hmnu, 2, TRUE, &mii);
|
|
|
return hmnu;
|
return hmnu;
|
}
|
}
|
|
|
HMENU createmenu1()
|
HMENU createmenu1()
|
{
|
{
|
HMENU hmnu;
|
HMENU hmnu;
|
MENUITEMINFO mii;
|
MENUITEMINFO mii;
|
|
|
hmnu = CreateMenu();
|
hmnu = CreateMenu();
|
|
|
memset (&mii, 0, sizeof(MENUITEMINFO));
|
memset (&mii, 0, sizeof(MENUITEMINFO));
|
mii.type = MFT_STRING;
|
mii.type = MFT_STRING;
|
mii.id = 100;
|
mii.id = 100;
|
mii.typedata = (DWORD)"Start";
|
mii.typedata = (DWORD)"Start";
|
mii.hsubmenu = createpmenustart();
|
mii.hsubmenu = createpmenustart();
|
|
|
InsertMenuItem(hmnu, 0, TRUE, &mii);
|
InsertMenuItem(hmnu, 0, TRUE, &mii);
|
|
|
mii.type = MFT_STRING;
|
mii.type = MFT_STRING;
|
mii.id = 110;
|
mii.id = 110;
|
mii.typedata = (DWORD)"Level";
|
mii.typedata = (DWORD)"Level";
|
mii.hsubmenu = createpmenulevel();
|
mii.hsubmenu = createpmenulevel();
|
InsertMenuItem(hmnu, 1, TRUE, &mii);
|
InsertMenuItem(hmnu, 1, TRUE, &mii);
|
|
|
mii.type = MFT_STRING;
|
mii.type = MFT_STRING;
|
mii.id = 120;
|
mii.id = 120;
|
mii.typedata = (DWORD)"About";
|
mii.typedata = (DWORD)"About";
|
mii.hsubmenu = createpmenuabout();
|
mii.hsubmenu = createpmenuabout();
|
InsertMenuItem(hmnu, 2, TRUE, &mii);
|
InsertMenuItem(hmnu, 2, TRUE, &mii);
|
|
|
return hmnu;
|
return hmnu;
|
}
|
}
|
#endif
|
#endif
|
|
|
void BothButtonDownProc(HWND hWnd,int adrx,int adry)
|
void BothButtonDownProc(HWND hWnd,int adrx,int adry)
|
{
|
{
|
int test_open = 0;
|
int test_open = 0;
|
int i = 1;
|
int i = 1;
|
int adrx1 = 0, adry1 = 0;
|
int adrx1 = 0, adry1 = 0;
|
int flag_opened = 1;
|
int flag_opened = 1;
|
|
|
if (!bom[adrx][adry].test)
|
if (!bom[adrx][adry].test)
|
return;
|
return;
|
if (!bom[adrx][adry].value)
|
if (!bom[adrx][adry].value)
|
return;
|
return;
|
if (bom[adrx][adry].hit)
|
if (bom[adrx][adry].hit)
|
return;
|
return;
|
while (i <= 8)
|
while (i <= 8)
|
{
|
{
|
switch (i)
|
switch (i)
|
{
|
{
|
case 1:
|
case 1:
|
adrx1 = adrx-1;
|
adrx1 = adrx-1;
|
adry1 = adry;
|
adry1 = adry;
|
break;
|
break;
|
|
|
case 2:
|
case 2:
|
adrx1 = adrx-1;
|
adrx1 = adrx-1;
|
adry1 = adry-1;
|
adry1 = adry-1;
|
break;
|
break;
|
|
|
case 3:
|
case 3:
|
adrx1 = adrx-1;
|
adrx1 = adrx-1;
|
adry1 = adry+1;
|
adry1 = adry+1;
|
break;
|
break;
|
|
|
case 4:
|
case 4:
|
adrx1 = adrx;
|
adrx1 = adrx;
|
adry1 = adry-1;
|
adry1 = adry-1;
|
break;
|
break;
|
|
|
case 5:
|
case 5:
|
adrx1 = adrx;
|
adrx1 = adrx;
|
adry1 = adry+1;
|
adry1 = adry+1;
|
break;
|
break;
|
|
|
case 6:
|
case 6:
|
adrx1 = adrx+1;
|
adrx1 = adrx+1;
|
adry1 = adry;
|
adry1 = adry;
|
break;
|
break;
|
|
|
case 7:
|
case 7:
|
adrx1 = adrx+1;
|
adrx1 = adrx+1;
|
adry1 = adry+1;
|
adry1 = adry+1;
|
break;
|
break;
|
|
|
case 8:
|
case 8:
|
adrx1 = adrx+1;
|
adrx1 = adrx+1;
|
adry1 = adry-1;
|
adry1 = adry-1;
|
break;
|
break;
|
}
|
}
|
|
|
if (adrx1>=0 && adry1>=0 && adrx1<sg_boxnumx && adry1<sg_boxnumy
|
if (adrx1>=0 && adry1>=0 && adrx1<sg_boxnumx && adry1<sg_boxnumy
|
&& bom[adrx1][adry1].hit)
|
&& bom[adrx1][adry1].hit)
|
test_open++;
|
test_open++;
|
else
|
else
|
if(adrx>=0 && adry1>=0 && adrx1<sg_boxnumx && adry1<sg_boxnumy
|
if(adrx>=0 && adry1>=0 && adrx1<sg_boxnumx && adry1<sg_boxnumy
|
&& !bom[adrx1][adry1].test)
|
&& !bom[adrx1][adry1].test)
|
flag_opened = 0;
|
flag_opened = 0;
|
i++;
|
i++;
|
}
|
}
|
if ((test_open == bom[adrx][adry].value) && !flag_opened)
|
if ((test_open == bom[adrx][adry].value) && !flag_opened)
|
{
|
{
|
if (!Open (hWnd, adrx, adry))
|
if (!Open (hWnd, adrx, adry))
|
BombOut (hWnd);
|
BombOut (hWnd);
|
if (itime == (sg_boxnumx*sg_boxnumy-bombnum))
|
if (itime == (sg_boxnumx*sg_boxnumy-bombnum))
|
Finished(hWnd);
|
Finished(hWnd);
|
|
|
}
|
}
|
|
|
}
|
}
|
|
|
void DrawDigit(HDC hdc, char* buffer, int CLOCK)
|
void DrawDigit(HDC hdc, char* buffer, int CLOCK)
|
{
|
{
|
int x;
|
int x;
|
|
|
if (CLOCK)
|
if (CLOCK)
|
x = x_clock;
|
x = x_clock;
|
else
|
else
|
x = x_bomnum;
|
x = x_bomnum;
|
|
|
SetBkMode(hdc, OPAQUE);
|
SetBkMode(hdc, OPAQUE);
|
SetBkColor(hdc, LTGRAY);
|
SetBkColor(hdc, LTGRAY);
|
TextOut(hdc, x, 0, buffer, -1);
|
TextOut(hdc, x, 0, buffer, -1);
|
return;
|
return;
|
}
|
}
|
|
|
LRESULT TestMyWinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
LRESULT TestMyWinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
{
|
{
|
HDC hdc;
|
HDC hdc;
|
char bomn[30], seconds[30];
|
char bomn[30], seconds[30];
|
int i, j;
|
int i, j;
|
int ran1, ran2;
|
int ran1, ran2;
|
static RECT bombregion, face, onerect, bombnumber, clock;
|
static RECT bombregion, face, onerect, bombnumber, clock;
|
static RECT winposition;
|
static RECT winposition;
|
MAINWINCREATE CreateInfo;
|
MAINWINCREATE CreateInfo;
|
|
|
PAINTSTRUCT ps;
|
PAINTSTRUCT ps;
|
switch (message) {
|
switch (message) {
|
|
|
case WM_CREATE:
|
case WM_CREATE:
|
#if 0
|
#if 0
|
FILE* pHighscore;
|
FILE* pHighscore;
|
char buffer[256];
|
char buffer[256];
|
if( LoadBitmap(&bmpbom,"res/lei.bmp")<0)
|
if( LoadBitmap(&bmpbom,"res/lei.bmp")<0)
|
fprintf(stderr,"bitmap error");
|
fprintf(stderr,"bitmap error");
|
else
|
else
|
fValidbom = TRUE;
|
fValidbom = TRUE;
|
|
|
if( LoadBitmap(&bmpface,"res/face1.bmp")<0)
|
if( LoadBitmap(&bmpface,"res/face1.bmp")<0)
|
fprintf(stderr,"bitmap error");
|
fprintf(stderr,"bitmap error");
|
else
|
else
|
fValidface = TRUE;
|
fValidface = TRUE;
|
|
|
if( LoadBitmap(&bitmap1,"res/face.bmp")<0)
|
if( LoadBitmap(&bitmap1,"res/face.bmp")<0)
|
fprintf(stderr,"bitmap error");
|
fprintf(stderr,"bitmap error");
|
else
|
else
|
fValid1 = TRUE;
|
fValid1 = TRUE;
|
|
|
if( LoadBitmap(&bmpflag,"res/flag.bmp")<0)
|
if( LoadBitmap(&bmpflag,"res/flag.bmp")<0)
|
fprintf(stderr,"bitmap error");
|
fprintf(stderr,"bitmap error");
|
else
|
else
|
fValidflag = TRUE;
|
fValidflag = TRUE;
|
|
|
if( LoadBitmap(&bmpfinalface,"res/finished.bmp")<0)
|
if( LoadBitmap(&bmpfinalface,"res/finished.bmp")<0)
|
fprintf(stderr,"bitmap error");
|
fprintf(stderr,"bitmap error");
|
else
|
else
|
fValidfinalface = TRUE;
|
fValidfinalface = TRUE;
|
|
|
if( LoadBitmap(&bmphitfalse,"res/hitfalse.bmp")<0)
|
if( LoadBitmap(&bmphitfalse,"res/hitfalse.bmp")<0)
|
fprintf(stderr,"bitmap error");
|
fprintf(stderr,"bitmap error");
|
else
|
else
|
fValidhitfalse = TRUE;
|
fValidhitfalse = TRUE;
|
|
|
for (i = 0; i < 10; i++){
|
for (i = 0; i < 10; i++){
|
sprintf(buffer, "res/%d.bmp", i);
|
sprintf(buffer, "res/%d.bmp", i);
|
LoadBitmap(sg_bmpDigit + i, buffer);
|
LoadBitmap(sg_bmpDigit + i, buffer);
|
}
|
}
|
|
|
if ((pHighscore = fopen("res/.highscore.bomb","r"))){
|
if ((pHighscore = fopen("res/.highscore.bomb","r"))){
|
for (i = 0; i < 3; i++)
|
for (i = 0; i < 3; i++)
|
fscanf(pHighscore, "%d, %s",
|
fscanf(pHighscore, "%d, %s",
|
&score[i].highscore, score[i].name);
|
&score[i].highscore, score[i].name);
|
fclose(pHighscore);
|
fclose(pHighscore);
|
}
|
}
|
else
|
else
|
for (i = 0; i < 3; i++){
|
for (i = 0; i < 3; i++){
|
score[i].highscore = 999;
|
score[i].highscore = 999;
|
strcpy(score[i].name, "unknown");
|
strcpy(score[i].name, "unknown");
|
}
|
}
|
#endif
|
#endif
|
SetTimer(hWnd, ID_CLOCK, FREQ_CLOCK, NULL);
|
SetTimer(hWnd, ID_CLOCK, FREQ_CLOCK, NULL);
|
|
|
PostMessage(hWnd,WM_COMMAND,ID_NEW,0);
|
PostMessage(hWnd,WM_COMMAND,ID_NEW,0);
|
break;
|
break;
|
|
|
case WM_COMMAND:
|
case WM_COMMAND:
|
if (LOWORD(wParam) == ID_ABOUT)
|
if (LOWORD(wParam) == ID_ABOUT)
|
{
|
{
|
InitAbHostedCreateInfo(hWnd,&CreateInfo);
|
InitAbHostedCreateInfo(hWnd,&CreateInfo);
|
CreateMainWindow(&CreateInfo);
|
CreateMainWindow(&CreateInfo);
|
}
|
}
|
|
|
if (LOWORD(wParam) == ID_CLOSE)
|
if (LOWORD(wParam) == ID_CLOSE)
|
{
|
{
|
PostMessage(hWnd, WM_CLOSE, 0, 0);
|
PostMessage(hWnd, WM_CLOSE, 0, 0);
|
}
|
}
|
|
|
if (LOWORD(wParam) == ID_HIGHSCORE)
|
if (LOWORD(wParam) == ID_HIGHSCORE)
|
{
|
{
|
InitHighScoreCreateInfo(hWnd,&CreateInfo);
|
InitHighScoreCreateInfo(hWnd,&CreateInfo);
|
hHighscore = CreateMainWindow(&CreateInfo);
|
hHighscore = CreateMainWindow(&CreateInfo);
|
ShowWindow(hHighscore,SW_SHOW);
|
ShowWindow(hHighscore,SW_SHOW);
|
}
|
}
|
|
|
if (LOWORD(wParam) == ID_LARGE)
|
if (LOWORD(wParam) == ID_LARGE)
|
{
|
{
|
bombnum = 99;
|
bombnum = 99;
|
sg_boxnumx = 30;
|
sg_boxnumx = 30;
|
sg_boxnumy = 18;
|
sg_boxnumy = 18;
|
winwidth = WIDTH_LARGEWIN;
|
winwidth = WIDTH_LARGEWIN;
|
flag_size = 2;
|
flag_size = 2;
|
GetWindowRect(hWnd, &winposition);
|
GetWindowRect(hWnd, &winposition);
|
MoveWindow(hWnd, winposition.left, winposition.top,
|
MoveWindow(hWnd, winposition.left, winposition.top,
|
WIDTH_LARGEWIN, HEIGHT_LARGEWIN, FALSE);
|
WIDTH_LARGEWIN, HEIGHT_LARGEWIN, FALSE);
|
PostMessage(hWnd, WM_COMMAND, ID_NEW, 0);
|
PostMessage(hWnd, WM_COMMAND, ID_NEW, 0);
|
}
|
}
|
if (LOWORD(wParam) == ID_MIDDLE)
|
if (LOWORD(wParam) == ID_MIDDLE)
|
{
|
{
|
bombnum = 40;
|
bombnum = 40;
|
sg_boxnumx = 16;
|
sg_boxnumx = 16;
|
sg_boxnumy = 16;
|
sg_boxnumy = 16;
|
winwidth = WIDTH_MIDDLEWIN;
|
winwidth = WIDTH_MIDDLEWIN;
|
flag_size = 1;
|
flag_size = 1;
|
GetWindowRect(hWnd, &winposition);
|
GetWindowRect(hWnd, &winposition);
|
MoveWindow(hWnd, winposition.left, winposition.top,
|
MoveWindow(hWnd, winposition.left, winposition.top,
|
WIDTH_MIDDLEWIN, HEIGHT_MIDDLEWIN, FALSE);
|
WIDTH_MIDDLEWIN, HEIGHT_MIDDLEWIN, FALSE);
|
PostMessage(hWnd, WM_COMMAND, ID_NEW, 0);
|
PostMessage(hWnd, WM_COMMAND, ID_NEW, 0);
|
}
|
}
|
|
|
if (LOWORD(wParam) == ID_SMALL)
|
if (LOWORD(wParam) == ID_SMALL)
|
{
|
{
|
bombnum = 10;
|
bombnum = 10;
|
sg_boxnumx = 8;
|
sg_boxnumx = 8;
|
sg_boxnumy = 8;
|
sg_boxnumy = 8;
|
winwidth = WIDTH_SMALLWIN;
|
winwidth = WIDTH_SMALLWIN;
|
flag_size = 0;
|
flag_size = 0;
|
GetWindowRect(hWnd, &winposition);
|
GetWindowRect(hWnd, &winposition);
|
MoveWindow(hWnd, winposition.left, winposition.top,
|
MoveWindow(hWnd, winposition.left, winposition.top,
|
WIDTH_SMALLWIN, HEIGHT_SMALLWIN, FALSE);
|
WIDTH_SMALLWIN, HEIGHT_SMALLWIN, FALSE);
|
PostMessage(hWnd, WM_COMMAND, ID_NEW, 0);
|
PostMessage(hWnd, WM_COMMAND, ID_NEW, 0);
|
}
|
}
|
|
|
if (LOWORD(wParam) == ID_NEW)
|
if (LOWORD(wParam) == ID_NEW)
|
{
|
{
|
bTimer = FALSE;
|
bTimer = FALSE;
|
second = 0;
|
second = 0;
|
itime = 0;
|
itime = 0;
|
leftbombnum = bombnum;
|
leftbombnum = bombnum;
|
flag_bombout = 0;
|
flag_bombout = 0;
|
flag_finished = 0;
|
flag_finished = 0;
|
x_bomnum = winwidth / 6;
|
x_bomnum = winwidth / 6;
|
x_face = (winwidth*2) / 5;
|
x_face = (winwidth*2) / 5;
|
x_clock = (winwidth*3) / 5;
|
x_clock = (winwidth*3) / 5;
|
offsetx = (winwidth - WIDTH_BOX*sg_boxnumx)/2-2;
|
offsetx = (winwidth - WIDTH_BOX*sg_boxnumx)/2-2;
|
SetRect (&clock, x_clock, 0,
|
SetRect (&clock, x_clock, 0,
|
x_clock + WIDTH_CLOCK, HEIGHT_CLOCK);
|
x_clock + WIDTH_CLOCK, HEIGHT_CLOCK);
|
|
|
SetRect (&face, x_face, 0,
|
SetRect (&face, x_face, 0,
|
x_face + WIDTH_FACE, HEIGHT_FACE);
|
x_face + WIDTH_FACE, HEIGHT_FACE);
|
|
|
SetRect (&bombregion, offsetx, HEIGHT_FACE,
|
SetRect (&bombregion, offsetx, HEIGHT_FACE,
|
WIDTH_BOX*sg_boxnumx+offsetx,
|
WIDTH_BOX*sg_boxnumx+offsetx,
|
HEIGHT_BOX*sg_boxnumy+HEIGHT_FACE);
|
HEIGHT_BOX*sg_boxnumy+HEIGHT_FACE);
|
|
|
SetRect (&bombnumber, x_bomnum, 0,
|
SetRect (&bombnumber, x_bomnum, 0,
|
x_bomnum + WIDTH_BOMNUM, HEIGHT_BOMNUM);
|
x_bomnum + WIDTH_BOMNUM, HEIGHT_BOMNUM);
|
|
|
/**************initial bomb value************** */
|
/**************initial bomb value************** */
|
|
|
for (i = 0; i < sg_boxnumx; i++)
|
for (i = 0; i < sg_boxnumx; i++)
|
for (j = 0; j < sg_boxnumy; j++)
|
for (j = 0; j < sg_boxnumy; j++)
|
{ bom[i][j].flag = 0;
|
{ bom[i][j].flag = 0;
|
bom[i][j].hit = FALSE;
|
bom[i][j].hit = FALSE;
|
bom[i][j].value = 0;
|
bom[i][j].value = 0;
|
bom[i][j].test = FALSE;
|
bom[i][j].test = FALSE;
|
bom[i][j].bombout = FALSE;
|
bom[i][j].bombout = FALSE;
|
bom[i][j].error = FALSE;
|
bom[i][j].error = FALSE;
|
};
|
};
|
for (i = 0; i < (sg_boxnumx*sg_boxnumy); i++)
|
for (i = 0; i < (sg_boxnumx*sg_boxnumy); i++)
|
NoAdr[i].NY = FALSE;
|
NoAdr[i].NY = FALSE;
|
|
|
srandom( time(NULL));
|
srandom( time(NULL));
|
i = 0;
|
i = 0;
|
while( i < bombnum )
|
while( i < bombnum )
|
{
|
{
|
ran1 = random()%sg_boxnumx;
|
ran1 = random()%sg_boxnumx;
|
ran2 = random()%sg_boxnumy;
|
ran2 = random()%sg_boxnumy;
|
if(!bom[ran1][ran2].flag)
|
if(!bom[ran1][ran2].flag)
|
{
|
{
|
bom[ran1][ran2].flag = 1;
|
bom[ran1][ran2].flag = 1;
|
i++;
|
i++;
|
}
|
}
|
#ifdef __rtems__
|
#ifdef __rtems__
|
else i++; /* bad rtems random function*/
|
else i++; /* bad rtems random function*/
|
#endif
|
#endif
|
}
|
}
|
|
|
for (i = 0; i < sg_boxnumx; i++)
|
for (i = 0; i < sg_boxnumx; i++)
|
for (j = 0; j < sg_boxnumy; j++)
|
for (j = 0; j < sg_boxnumy; j++)
|
{
|
{
|
if (!bom[i][j].flag) {
|
if (!bom[i][j].flag) {
|
if(i-1>=0&&j-1>=0&&bom[i-1][j-1].flag)
|
if(i-1>=0&&j-1>=0&&bom[i-1][j-1].flag)
|
bom[i][j].value++;
|
bom[i][j].value++;
|
|
|
if(i-1>=0&&bom[i-1][j].flag)
|
if(i-1>=0&&bom[i-1][j].flag)
|
bom[i][j].value++;
|
bom[i][j].value++;
|
|
|
if(i-1>=0&&j+1<sg_boxnumy&&bom[i-1][j+1].flag)
|
if(i-1>=0&&j+1<sg_boxnumy&&bom[i-1][j+1].flag)
|
bom[i][j].value++;
|
bom[i][j].value++;
|
|
|
if(j-1>=0&&bom[i][j-1].flag)
|
if(j-1>=0&&bom[i][j-1].flag)
|
bom[i][j].value++;
|
bom[i][j].value++;
|
|
|
if(j+1<sg_boxnumy&&bom[i][j+1].flag)
|
if(j+1<sg_boxnumy&&bom[i][j+1].flag)
|
bom[i][j].value++;
|
bom[i][j].value++;
|
|
|
if(i+1<sg_boxnumx&&j+1<sg_boxnumy&&bom[i+1][j+1].flag)
|
if(i+1<sg_boxnumx&&j+1<sg_boxnumy&&bom[i+1][j+1].flag)
|
bom[i][j].value++;
|
bom[i][j].value++;
|
|
|
if(i+1<sg_boxnumx&&bom[i+1][j].flag)
|
if(i+1<sg_boxnumx&&bom[i+1][j].flag)
|
bom[i][j].value++;
|
bom[i][j].value++;
|
|
|
if(i+1<sg_boxnumx&&j-1>=0&&bom[i+1][j-1].flag)
|
if(i+1<sg_boxnumx&&j-1>=0&&bom[i+1][j-1].flag)
|
bom[i][j].value++;
|
bom[i][j].value++;
|
}
|
}
|
}
|
}
|
InvalidateRect (hWnd, NULL, TRUE);
|
InvalidateRect (hWnd, NULL, TRUE);
|
}
|
}
|
break;
|
break;
|
|
|
case WM_TIMER:
|
case WM_TIMER:
|
if (wParam == ID_CLOCK)
|
if (wParam == ID_CLOCK)
|
if (bTimer){
|
if (bTimer){
|
if (second < 1000){
|
if (second < 1000){
|
second++;
|
second++;
|
InvalidateRect(hWnd, &clock, FALSE);
|
InvalidateRect(hWnd, &clock, FALSE);
|
}
|
}
|
}
|
}
|
break;
|
break;
|
|
|
case WM_LBUTTONDOWN:
|
case WM_LBUTTONDOWN:
|
|
|
oldx = LOWORD (lParam);
|
oldx = LOWORD (lParam);
|
oldy = HIWORD (lParam);
|
oldy = HIWORD (lParam);
|
|
|
adrx = (oldx-offsetx)/WIDTH_BOX;
|
adrx = (oldx-offsetx)/WIDTH_BOX;
|
adry = (oldy-HEIGHT_FACE)/HEIGHT_BOX;
|
adry = (oldy-HEIGHT_FACE)/HEIGHT_BOX;
|
|
|
if (hCongratulate || hHighscore)
|
if (hCongratulate || hHighscore)
|
break;
|
break;
|
|
|
if (!PtInRect2 (&bombregion, oldx, oldy)) {
|
if (!PtInRect2 (&bombregion, oldx, oldy)) {
|
if (PtInRect2 (&face, oldx, oldy)){
|
if (PtInRect2 (&face, oldx, oldy)){
|
PostMessage (hWnd, WM_COMMAND, ID_NEW, 0);
|
PostMessage (hWnd, WM_COMMAND, ID_NEW, 0);
|
break;
|
break;
|
}
|
}
|
else
|
else
|
break;
|
break;
|
}
|
}
|
if (flag_bombout)
|
if (flag_bombout)
|
break;
|
break;
|
if (flag_finished)
|
if (flag_finished)
|
break;
|
break;
|
if (!bTimer)
|
if (!bTimer)
|
bTimer = TRUE;
|
bTimer = TRUE;
|
|
|
if (bom[adrx][adry].hit)
|
if (bom[adrx][adry].hit)
|
break;
|
break;
|
|
|
#if 0
|
#if 0
|
if (GetShiftKeyStatus() & 0x00000200) {
|
if (GetShiftKeyStatus() & 0x00000200) {
|
#endif
|
#endif
|
if(mwCurrentButtons & MWBUTTON_R) {
|
if(mwCurrentButtons & MWBUTTON_R) {
|
BothButtonDownProc(hWnd,adrx,adry);
|
BothButtonDownProc(hWnd,adrx,adry);
|
break;
|
break;
|
}
|
}
|
|
|
|
|
if (bom[adrx][adry].test)
|
if (bom[adrx][adry].test)
|
break;
|
break;
|
|
|
if (bom[adrx][adry].flag) {
|
if (bom[adrx][adry].flag) {
|
BombOut(hWnd);
|
BombOut(hWnd);
|
break;
|
break;
|
}
|
}
|
if (bom[adrx][adry].value != 0)
|
if (bom[adrx][adry].value != 0)
|
{
|
{
|
NoAdr[itime].x = adrx;
|
NoAdr[itime].x = adrx;
|
NoAdr[itime].y = adry;
|
NoAdr[itime].y = adry;
|
NoAdr[itime].NY = TRUE;
|
NoAdr[itime].NY = TRUE;
|
itime++;
|
itime++;
|
bom[adrx][adry].test = TRUE;
|
bom[adrx][adry].test = TRUE;
|
|
|
SetRect (&onerect, adrx*WIDTH_BOX+offsetx,
|
SetRect (&onerect, adrx*WIDTH_BOX+offsetx,
|
adry*HEIGHT_BOX+HEIGHT_FACE,
|
adry*HEIGHT_BOX+HEIGHT_FACE,
|
(adrx+1)*WIDTH_BOX+offsetx,
|
(adrx+1)*WIDTH_BOX+offsetx,
|
(adry+1)*HEIGHT_BOX+HEIGHT_FACE);
|
(adry+1)*HEIGHT_BOX+HEIGHT_FACE);
|
InvalidateRect (hWnd, &onerect, FALSE);
|
InvalidateRect (hWnd, &onerect, FALSE);
|
}
|
}
|
else {
|
else {
|
hdc = GetDC(hWnd);
|
hdc = GetDC(hWnd);
|
SearchGround (hdc, adrx, adry);
|
SearchGround (hdc, adrx, adry);
|
ReleaseDC(hWnd, hdc);
|
ReleaseDC(hWnd, hdc);
|
}
|
}
|
|
|
if (itime == (sg_boxnumx*sg_boxnumy - bombnum))
|
if (itime == (sg_boxnumx*sg_boxnumy - bombnum))
|
Finished(hWnd);
|
Finished(hWnd);
|
|
|
break;
|
break;
|
|
|
case WM_MBUTTONDOWN:
|
case WM_MBUTTONDOWN:
|
oldx = LOWORD (lParam);
|
oldx = LOWORD (lParam);
|
oldy = HIWORD (lParam);
|
oldy = HIWORD (lParam);
|
adrx = (oldx-offsetx)/WIDTH_BOX;
|
adrx = (oldx-offsetx)/WIDTH_BOX;
|
adry = (oldy-HEIGHT_FACE)/HEIGHT_BOX;
|
adry = (oldy-HEIGHT_FACE)/HEIGHT_BOX;
|
|
|
if (!PtInRect2 (&bombregion, oldx, oldy))
|
if (!PtInRect2 (&bombregion, oldx, oldy))
|
break;
|
break;
|
if (flag_bombout)
|
if (flag_bombout)
|
break;
|
break;
|
if (flag_finished)
|
if (flag_finished)
|
break;
|
break;
|
|
|
if (!bTimer)
|
if (!bTimer)
|
bTimer = TRUE;
|
bTimer = TRUE;
|
|
|
/*****RBUTTONDOWN & LBUTTONDOWN******/
|
/*****RBUTTONDOWN & LBUTTONDOWN******/
|
|
|
BothButtonDownProc(hWnd,adrx,adry);
|
BothButtonDownProc(hWnd,adrx,adry);
|
break;
|
break;
|
|
|
case WM_RBUTTONDOWN:
|
case WM_RBUTTONDOWN:
|
#if 0
|
#if 0
|
SetCapture (hWnd);
|
SetCapture (hWnd);
|
#endif
|
#endif
|
oldx = LOWORD (lParam);
|
oldx = LOWORD (lParam);
|
oldy = HIWORD (lParam);
|
oldy = HIWORD (lParam);
|
adrx = (oldx-offsetx)/WIDTH_BOX;
|
adrx = (oldx-offsetx)/WIDTH_BOX;
|
adry = (oldy-HEIGHT_FACE)/HEIGHT_BOX;
|
adry = (oldy-HEIGHT_FACE)/HEIGHT_BOX;
|
|
|
if (!PtInRect2 (&bombregion, oldx, oldy))
|
if (!PtInRect2 (&bombregion, oldx, oldy))
|
break;
|
break;
|
if (flag_bombout)
|
if (flag_bombout)
|
break;
|
break;
|
if (flag_finished)
|
if (flag_finished)
|
break;
|
break;
|
|
|
if (!bTimer)
|
if (!bTimer)
|
bTimer = TRUE;
|
bTimer = TRUE;
|
|
|
/*****RBUTTONDOWN & LBUTTONDOWN******/
|
/*****RBUTTONDOWN & LBUTTONDOWN******/
|
|
|
#if 0
|
#if 0
|
if (GetShiftKeyStatus() & 0x00000100){
|
if (GetShiftKeyStatus() & 0x00000100){
|
#endif
|
#endif
|
if(mwCurrentButtons & MWBUTTON_L) {
|
if(mwCurrentButtons & MWBUTTON_L) {
|
BothButtonDownProc(hWnd,adrx,adry);
|
BothButtonDownProc(hWnd,adrx,adry);
|
break;
|
break;
|
}
|
}
|
/******* only rbuttondown *******/
|
/******* only rbuttondown *******/
|
|
|
if (bom[adrx][adry].test)
|
if (bom[adrx][adry].test)
|
break;
|
break;
|
if (!bom[adrx][adry].hit )
|
if (!bom[adrx][adry].hit )
|
{
|
{
|
bom[adrx][adry].hit = TRUE;
|
bom[adrx][adry].hit = TRUE;
|
leftbombnum--;
|
leftbombnum--;
|
}
|
}
|
else
|
else
|
{ bom[adrx][adry].hit = FALSE;
|
{ bom[adrx][adry].hit = FALSE;
|
leftbombnum++;
|
leftbombnum++;
|
}
|
}
|
SetRect (&onerect, adrx*WIDTH_BOX+offsetx,
|
SetRect (&onerect, adrx*WIDTH_BOX+offsetx,
|
adry*HEIGHT_BOX+HEIGHT_FACE,
|
adry*HEIGHT_BOX+HEIGHT_FACE,
|
(adrx+1)*WIDTH_BOX+offsetx,
|
(adrx+1)*WIDTH_BOX+offsetx,
|
(adry+1)*HEIGHT_BOX+HEIGHT_FACE);
|
(adry+1)*HEIGHT_BOX+HEIGHT_FACE);
|
InvalidateRect (hWnd, &onerect, FALSE);
|
InvalidateRect (hWnd, &onerect, FALSE);
|
InvalidateRect (hWnd, &bombnumber, FALSE);
|
InvalidateRect (hWnd, &bombnumber, FALSE);
|
break;
|
break;
|
|
|
case WM_PAINT:
|
case WM_PAINT:
|
hdc = BeginPaint (hWnd, &ps);
|
hdc = BeginPaint (hWnd, &ps);
|
|
|
sprintf(seconds, "%03d", second);
|
sprintf(seconds, "%03d", second);
|
DrawDigit(hdc, seconds, TRUE);
|
DrawDigit(hdc, seconds, TRUE);
|
|
|
if (leftbombnum >= 0){
|
if (leftbombnum >= 0){
|
sprintf(bomn,"%02d",leftbombnum);
|
sprintf(bomn,"%02d",leftbombnum);
|
DrawDigit(hdc, bomn, FALSE);
|
DrawDigit(hdc, bomn, FALSE);
|
}
|
}
|
|
|
if (flag_finished)
|
if (flag_finished)
|
DrawDIB(hdc, x_face+1, 1, &image_minedone);
|
DrawDIB(hdc, x_face+1, 1, &image_minedone);
|
#if 0
|
#if 0
|
DrawMyBitmap (hdc, fValidfinalface?&bmpfinalface:NULL,
|
DrawMyBitmap (hdc, fValidfinalface?&bmpfinalface:NULL,
|
#endif
|
#endif
|
else
|
else
|
if (flag_bombout)
|
if (flag_bombout)
|
DrawDIB(hdc, x_face, 0, &image_minefacelost);
|
DrawDIB(hdc, x_face, 0, &image_minefacelost);
|
else
|
else
|
DrawDIB(hdc, x_face, 0, &image_mineface);
|
DrawDIB(hdc, x_face, 0, &image_mineface);
|
|
|
for (i = 0; i < sg_boxnumx; i++)
|
for (i = 0; i < sg_boxnumx; i++)
|
for (j = 0; j < sg_boxnumy; j++)
|
for (j = 0; j < sg_boxnumy; j++)
|
{
|
{
|
if (!bom[i][j].test && !bom[i][j].bombout){
|
if (!bom[i][j].test && !bom[i][j].bombout){
|
SetTextColor (hdc,BLACK);
|
SetTextColor (hdc,BLACK);
|
SelectObject(hdc, GetStockObject(NULL_BRUSH));
|
SelectObject(hdc, GetStockObject(NULL_BRUSH));
|
Draw3DUpFrame(hdc,
|
Draw3DUpFrame(hdc,
|
i*WIDTH_BOX+offsetx,
|
i*WIDTH_BOX+offsetx,
|
j*HEIGHT_BOX+HEIGHT_FACE,
|
j*HEIGHT_BOX+HEIGHT_FACE,
|
(i+1)*WIDTH_BOX+offsetx,
|
(i+1)*WIDTH_BOX+offsetx,
|
(j+1)*HEIGHT_BOX+HEIGHT_FACE,
|
(j+1)*HEIGHT_BOX+HEIGHT_FACE,
|
LTGRAY);
|
LTGRAY);
|
}
|
}
|
|
|
|
|
if ( bom[i][j].hit)
|
if ( bom[i][j].hit)
|
DrawDIB(hdc, i*WIDTH_BOX+offsetx+3, j*HEIGHT_BOX+3+HEIGHT_FACE,
|
DrawDIB(hdc, i*WIDTH_BOX+offsetx+3, j*HEIGHT_BOX+3+HEIGHT_FACE,
|
&image_mineflag);
|
&image_mineflag);
|
|
|
if (bom[i][j].error) {
|
if (bom[i][j].error) {
|
Cancel3DFrame(hdc,i*WIDTH_BOX+offsetx,
|
Cancel3DFrame(hdc,i*WIDTH_BOX+offsetx,
|
j*HEIGHT_BOX+HEIGHT_FACE,
|
j*HEIGHT_BOX+HEIGHT_FACE,
|
WIDTH_BOX,HEIGHT_BOX);
|
WIDTH_BOX,HEIGHT_BOX);
|
|
|
DrawDIB(hdc, i*WIDTH_BOX+offsetx+1, j*HEIGHT_BOX+1+HEIGHT_FACE,
|
DrawDIB(hdc, i*WIDTH_BOX+offsetx+1, j*HEIGHT_BOX+1+HEIGHT_FACE,
|
&image_minehitfalse);
|
&image_minehitfalse);
|
}
|
}
|
|
|
if (bom[i][j].bombout) {
|
if (bom[i][j].bombout) {
|
Cancel3DFrame(hdc,i*WIDTH_BOX+offsetx,
|
Cancel3DFrame(hdc,i*WIDTH_BOX+offsetx,
|
j*HEIGHT_BOX+HEIGHT_FACE,
|
j*HEIGHT_BOX+HEIGHT_FACE,
|
WIDTH_BOX,HEIGHT_BOX);
|
WIDTH_BOX,HEIGHT_BOX);
|
|
|
DrawDIB(hdc, i*WIDTH_BOX+offsetx+1, j*HEIGHT_BOX+1+HEIGHT_FACE,
|
DrawDIB(hdc, i*WIDTH_BOX+offsetx+1, j*HEIGHT_BOX+1+HEIGHT_FACE,
|
&image_minebomb);
|
&image_minebomb);
|
}
|
}
|
}
|
}
|
|
|
for ( i = 0; i < itime; i++ )
|
for ( i = 0; i < itime; i++ )
|
{
|
{
|
Cancel3DFrame(hdc,(NoAdr[i].x)*WIDTH_BOX+offsetx,
|
Cancel3DFrame(hdc,(NoAdr[i].x)*WIDTH_BOX+offsetx,
|
(NoAdr[i].y)*HEIGHT_BOX+HEIGHT_FACE,
|
(NoAdr[i].y)*HEIGHT_BOX+HEIGHT_FACE,
|
WIDTH_BOX, HEIGHT_BOX);
|
WIDTH_BOX, HEIGHT_BOX);
|
if(NoAdr[i].NY)
|
if(NoAdr[i].NY)
|
TextValue(hdc,(NoAdr[i].x)*WIDTH_BOX+offsetx,
|
TextValue(hdc,(NoAdr[i].x)*WIDTH_BOX+offsetx,
|
(NoAdr[i].y)*HEIGHT_BOX+HEIGHT_FACE,
|
(NoAdr[i].y)*HEIGHT_BOX+HEIGHT_FACE,
|
bom[NoAdr[i].x][NoAdr[i].y].value);
|
bom[NoAdr[i].x][NoAdr[i].y].value);
|
}
|
}
|
EndPaint (hWnd, &ps);
|
EndPaint (hWnd, &ps);
|
break;
|
break;
|
|
|
case WM_CLOSE:
|
case WM_CLOSE:
|
KillTimer(hWnd, ID_CLOCK);
|
KillTimer(hWnd, ID_CLOCK);
|
DestroyWindow (hWnd);
|
DestroyWindow (hWnd);
|
PostQuitMessage (0);
|
PostQuitMessage (0);
|
return 0;
|
return 0;
|
}
|
}
|
return DefWindowProc(hWnd, message, wParam, lParam);
|
return DefWindowProc(hWnd, message, wParam, lParam);
|
}
|
}
|
|
|
void InitMyWinCreateInfo(PMAINWINCREATE pCreateInfo)
|
void InitMyWinCreateInfo(PMAINWINCREATE pCreateInfo)
|
{
|
{
|
pCreateInfo->dwStyle = WS_CAPTION | WS_BORDER | WS_SYSMENU | WS_VISIBLE;
|
pCreateInfo->dwStyle = WS_CAPTION | WS_BORDER | WS_SYSMENU | WS_VISIBLE;
|
pCreateInfo->spCaption="Microwindows Minesweeper";
|
pCreateInfo->spCaption="Microwindows Minesweeper";
|
pCreateInfo->hMenu = 0; /* createmenu1(); */
|
pCreateInfo->hMenu = 0; /* createmenu1(); */
|
pCreateInfo->hCursor = 0; /* GetSystemCursor(0); */
|
pCreateInfo->hCursor = 0; /* GetSystemCursor(0); */
|
pCreateInfo->hIcon = 0;
|
pCreateInfo->hIcon = 0;
|
pCreateInfo->MainWindowProc = TestMyWinProc;
|
pCreateInfo->MainWindowProc = TestMyWinProc;
|
pCreateInfo->lx = 0;
|
pCreateInfo->lx = 0;
|
pCreateInfo->ty = 0;
|
pCreateInfo->ty = 0;
|
pCreateInfo->rx = winwidth;
|
pCreateInfo->rx = winwidth;
|
pCreateInfo->by = winheight;
|
pCreateInfo->by = winheight;
|
pCreateInfo->iBkColor = LTGRAY;
|
pCreateInfo->iBkColor = LTGRAY;
|
pCreateInfo->dwAddData = 0;
|
pCreateInfo->dwAddData = 0;
|
pCreateInfo->hHosting = HWND_DESKTOP;
|
pCreateInfo->hHosting = HWND_DESKTOP;
|
}
|
}
|
|
|
void* TestMyWindow(void* data)
|
void* TestMyWindow(void* data)
|
{
|
{
|
MSG Msg;
|
MSG Msg;
|
MAINWINCREATE CreateInfo;
|
MAINWINCREATE CreateInfo;
|
HWND hMainWnd;
|
HWND hMainWnd;
|
|
|
InitMyWinCreateInfo(&CreateInfo);
|
InitMyWinCreateInfo(&CreateInfo);
|
|
|
hMainWnd = CreateMainWindow(&CreateInfo);
|
hMainWnd = CreateMainWindow(&CreateInfo);
|
|
|
if (hMainWnd == 0)
|
if (hMainWnd == 0)
|
return NULL;
|
return NULL;
|
|
|
ShowWindow(hMainWnd,SW_SHOWNORMAL);
|
ShowWindow(hMainWnd,SW_SHOWNORMAL);
|
while( GetMessage(&Msg, NULL, 0, 0) ) {
|
while( GetMessage(&Msg, NULL, 0, 0) ) {
|
TranslateMessage (&Msg);
|
TranslateMessage (&Msg);
|
DispatchMessage(&Msg);
|
DispatchMessage(&Msg);
|
}
|
}
|
|
|
return NULL;
|
return NULL;
|
}
|
}
|
|
|
int WINAPI
|
int WINAPI
|
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
|
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
|
int nShowCmd)
|
int nShowCmd)
|
{
|
{
|
TestMyWindow (NULL);
|
TestMyWindow (NULL);
|
return 0;
|
return 0;
|
}
|
}
|
|
|
/********** create a hosted about window****/
|
/********** create a hosted about window****/
|
LRESULT AbHostedWinProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
LRESULT AbHostedWinProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
{
|
{
|
PAINTSTRUCT ps;
|
PAINTSTRUCT ps;
|
|
|
switch (message) {
|
switch (message) {
|
case WM_CREATE:
|
case WM_CREATE:
|
break;
|
break;
|
|
|
case WM_PAINT:
|
case WM_PAINT:
|
{
|
{
|
HDC hdc;
|
HDC hdc;
|
|
|
hdc = BeginPaint (hWnd, &ps);
|
hdc = BeginPaint (hWnd, &ps);
|
SetBkColor(hdc,LTGRAY);
|
SetBkColor(hdc,LTGRAY);
|
TextOut (hdc, 10, 25, "Minesweeper Ver 0.9 (1999/08/27)", -1);
|
TextOut (hdc, 10, 25, "Minesweeper Ver 0.9 (1999/08/27)", -1);
|
TextOut (hdc, 10, 55,
|
TextOut (hdc, 10, 55,
|
"Author: Mis. Zheng Xiang (xiang_zi@263.net).", -1);
|
"Author: Mis. Zheng Xiang (xiang_zi@263.net).", -1);
|
TextOut (hdc, 10, 75,
|
TextOut (hdc, 10, 75,
|
" Mis. Glory (glory@263.net).", -1);
|
" Mis. Glory (glory@263.net).", -1);
|
EndPaint (hWnd, &ps);
|
EndPaint (hWnd, &ps);
|
}
|
}
|
return 0;
|
return 0;
|
|
|
case WM_CLOSE:
|
case WM_CLOSE:
|
DestroyWindow (hWnd);
|
DestroyWindow (hWnd);
|
return 0;
|
return 0;
|
}
|
}
|
|
|
return DefWindowProc(hWnd, message, wParam, lParam);
|
return DefWindowProc(hWnd, message, wParam, lParam);
|
}
|
}
|
void InitAbHostedCreateInfo (HWND hHosting, PMAINWINCREATE pCreateInfo)
|
void InitAbHostedCreateInfo (HWND hHosting, PMAINWINCREATE pCreateInfo)
|
{
|
{
|
pCreateInfo->dwStyle = WS_BORDER | WS_CAPTION | WS_VISIBLE;
|
pCreateInfo->dwStyle = WS_BORDER | WS_CAPTION | WS_VISIBLE;
|
pCreateInfo->spCaption = "The about window" ;
|
pCreateInfo->spCaption = "The about window" ;
|
pCreateInfo->hMenu = 0;
|
pCreateInfo->hMenu = 0;
|
pCreateInfo->hCursor = 0; /* GetSystemCursor(0); */
|
pCreateInfo->hCursor = 0; /* GetSystemCursor(0); */
|
pCreateInfo->hIcon = 0;
|
pCreateInfo->hIcon = 0;
|
pCreateInfo->MainWindowProc = AbHostedWinProc;
|
pCreateInfo->MainWindowProc = AbHostedWinProc;
|
pCreateInfo->lx = 100;
|
pCreateInfo->lx = 100;
|
pCreateInfo->ty = 200;
|
pCreateInfo->ty = 200;
|
pCreateInfo->rx = 540;
|
pCreateInfo->rx = 540;
|
pCreateInfo->by = 390;
|
pCreateInfo->by = 390;
|
pCreateInfo->iBkColor = LTGRAY;
|
pCreateInfo->iBkColor = LTGRAY;
|
pCreateInfo->dwAddData = 0;
|
pCreateInfo->dwAddData = 0;
|
pCreateInfo->hHosting = hHosting;
|
pCreateInfo->hHosting = hHosting;
|
}
|
}
|
|
|
/*************************** High Scores Window ******************************/
|
/*************************** High Scores Window ******************************/
|
#define IDC_RESET 110
|
#define IDC_RESET 110
|
LRESULT HighScoreWinProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
LRESULT HighScoreWinProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
{
|
{
|
PAINTSTRUCT ps;
|
PAINTSTRUCT ps;
|
static HWND hRESET, hOK;
|
static HWND hRESET, hOK;
|
|
|
switch (message) {
|
switch (message) {
|
case WM_CREATE:
|
case WM_CREATE:
|
hRESET = CreateWindowEx (0L, "button",
|
hRESET = CreateWindowEx (0L, "button",
|
"ÖØÖÃ",
|
"ÖØÖÃ",
|
WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
|
WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
|
100, 145, 60, 26,
|
100, 145, 60, 26,
|
hWnd, (HMENU)IDC_RESET, 0, 0L);
|
hWnd, (HMENU)IDC_RESET, 0, 0L);
|
|
|
hOK = CreateWindowEx (0L, "button",
|
hOK = CreateWindowEx (0L, "button",
|
"È·¶¨",
|
"È·¶¨",
|
WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
|
WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
|
220, 145, 60, 26,
|
220, 145, 60, 26,
|
hWnd, (HMENU)IDOK, 0, 0L);
|
hWnd, (HMENU)IDOK, 0, 0L);
|
break;
|
break;
|
|
|
case WM_COMMAND:
|
case WM_COMMAND:
|
{
|
{
|
int id = LOWORD(wParam);
|
int id = LOWORD(wParam);
|
int i;
|
int i;
|
|
|
if (id == IDC_RESET && HIWORD(wParam) == BN_CLICKED) {
|
if (id == IDC_RESET && HIWORD(wParam) == BN_CLICKED) {
|
for (i = 0; i < 3; i++){
|
for (i = 0; i < 3; i++){
|
score[i].highscore = 999;
|
score[i].highscore = 999;
|
strcpy(score[i].name, "unknown");
|
strcpy(score[i].name, "unknown");
|
}
|
}
|
|
|
#if 0
|
#if 0
|
FILE* pHighscore;
|
FILE* pHighscore;
|
if ((pHighscore = fopen("res/.highscore.bomb", "w+"))){
|
if ((pHighscore = fopen("res/.highscore.bomb", "w+"))){
|
for (i = 0; i < 3; i++)
|
for (i = 0; i < 3; i++)
|
fprintf(pHighscore, "%d, %s\n",
|
fprintf(pHighscore, "%d, %s\n",
|
score[i].highscore,score[i].name);
|
score[i].highscore,score[i].name);
|
fclose(pHighscore);
|
fclose(pHighscore);
|
}
|
}
|
#endif
|
#endif
|
InvalidateRect(hWnd, NULL, TRUE);
|
InvalidateRect(hWnd, NULL, TRUE);
|
}
|
}
|
if (id == IDOK && HIWORD(wParam) == BN_CLICKED)
|
if (id == IDOK && HIWORD(wParam) == BN_CLICKED)
|
PostMessage(hWnd, WM_CLOSE, 0, 0);
|
PostMessage(hWnd, WM_CLOSE, 0, 0);
|
}
|
}
|
break;
|
break;
|
|
|
case WM_PAINT:
|
case WM_PAINT:
|
{
|
{
|
HDC hdc;
|
HDC hdc;
|
char buffer[50];
|
char buffer[50];
|
int i;
|
int i;
|
|
|
hdc = BeginPaint (hWnd, &ps);
|
hdc = BeginPaint (hWnd, &ps);
|
SetBkColor(hdc,LTGRAY);
|
SetBkColor(hdc,LTGRAY);
|
TextOut(hdc, 130, 15, "Ó¢ÐÛ°ñ", -1);
|
TextOut(hdc, 130, 15, "Ó¢ÐÛ°ñ", -1);
|
TextOut(hdc, 15, 45, "SMALL" , -1);
|
TextOut(hdc, 15, 45, "SMALL" , -1);
|
TextOut(hdc, 15, 75, "MIDDLE", -1 );
|
TextOut(hdc, 15, 75, "MIDDLE", -1 );
|
TextOut(hdc, 15, 105, "LARGE", -1 );
|
TextOut(hdc, 15, 105, "LARGE", -1 );
|
for (i = 0; i < 3; i++){
|
for (i = 0; i < 3; i++){
|
sprintf(buffer, "%3d %s",
|
sprintf(buffer, "%3d %s",
|
score[i].highscore, score[i].name);
|
score[i].highscore, score[i].name);
|
TextOut(hdc, 150, 45+i*30, buffer, -1);
|
TextOut(hdc, 150, 45+i*30, buffer, -1);
|
}
|
}
|
EndPaint (hWnd, &ps);
|
EndPaint (hWnd, &ps);
|
}
|
}
|
return 0;
|
return 0;
|
|
|
case WM_CLOSE:
|
case WM_CLOSE:
|
DestroyWindow (hRESET);
|
DestroyWindow (hRESET);
|
DestroyWindow (hOK);
|
DestroyWindow (hOK);
|
DestroyWindow (hWnd);
|
DestroyWindow (hWnd);
|
hHighscore = HWND_DESKTOP;
|
hHighscore = HWND_DESKTOP;
|
return 0;
|
return 0;
|
}
|
}
|
|
|
return DefWindowProc(hWnd, message, wParam, lParam);
|
return DefWindowProc(hWnd, message, wParam, lParam);
|
}
|
}
|
|
|
void InitHighScoreCreateInfo (HWND hHosting, PMAINWINCREATE pCreateInfo)
|
void InitHighScoreCreateInfo (HWND hHosting, PMAINWINCREATE pCreateInfo)
|
{
|
{
|
pCreateInfo->dwStyle = WS_BORDER | WS_CAPTION;
|
pCreateInfo->dwStyle = WS_BORDER | WS_CAPTION;
|
pCreateInfo->spCaption = "High Score" ;
|
pCreateInfo->spCaption = "High Score" ;
|
pCreateInfo->hMenu = 0;
|
pCreateInfo->hMenu = 0;
|
pCreateInfo->hCursor = 0; /* GetSystemCursor(0); */
|
pCreateInfo->hCursor = 0; /* GetSystemCursor(0); */
|
pCreateInfo->hIcon = 0;
|
pCreateInfo->hIcon = 0;
|
pCreateInfo->MainWindowProc = HighScoreWinProc;
|
pCreateInfo->MainWindowProc = HighScoreWinProc;
|
pCreateInfo->lx = 100;
|
pCreateInfo->lx = 100;
|
pCreateInfo->ty = 200;
|
pCreateInfo->ty = 200;
|
pCreateInfo->rx = 470;
|
pCreateInfo->rx = 470;
|
pCreateInfo->by = 410;
|
pCreateInfo->by = 410;
|
pCreateInfo->iBkColor = LTGRAY;
|
pCreateInfo->iBkColor = LTGRAY;
|
pCreateInfo->dwAddData = 0;
|
pCreateInfo->dwAddData = 0;
|
pCreateInfo->hHosting = hHosting;
|
pCreateInfo->hHosting = hHosting;
|
}
|
}
|
|
|
/************************* Congratulation Window *****************************/
|
/************************* Congratulation Window *****************************/
|
|
|
#define IDC_CTRL_NAME 100
|
#define IDC_CTRL_NAME 100
|
|
|
LRESULT CongratulationWinProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
LRESULT CongratulationWinProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
{
|
{
|
static HWND hPrompt, hName, hOK;
|
static HWND hPrompt, hName, hOK;
|
|
|
switch (message) {
|
switch (message) {
|
case WM_CREATE:
|
case WM_CREATE:
|
#if 0
|
#if 0
|
hPrompt = CreateWindow ("static",
|
hPrompt = CreateWindow ("static",
|
"ÇëÊäÈë´óϺ×ðÐÕ´óÃû: ",
|
"ÇëÊäÈë´óϺ×ðÐÕ´óÃû: ",
|
SS_SIMPLE | WS_VISIBLE,
|
SS_SIMPLE | WS_VISIBLE,
|
IDC_STATIC,
|
IDC_STATIC,
|
10, 10, 185, 24, hWnd, 0);
|
10, 10, 185, 24, hWnd, 0);
|
hName = CreateWindow ("edit",
|
hName = CreateWindow ("edit",
|
getlogin(),
|
getlogin(),
|
WS_CHILD | WS_VISIBLE | WS_BORDER,
|
WS_CHILD | WS_VISIBLE | WS_BORDER,
|
IDC_CTRL_NAME,
|
IDC_CTRL_NAME,
|
10, 40, 175, 26, hWnd, 0);
|
10, 40, 175, 26, hWnd, 0);
|
#endif
|
#endif
|
hOK = CreateWindow ("button",
|
hOK = CreateWindow ("button",
|
"È·¶¨",
|
"È·¶¨",
|
WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
|
WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
|
110, 75, 75, 26,
|
110, 75, 75, 26,
|
hWnd, (HMENU)IDOK, 0, 0L);
|
hWnd, (HMENU)IDOK, 0, 0L);
|
break;
|
break;
|
|
|
case WM_COMMAND:
|
case WM_COMMAND:
|
{
|
{
|
int id = LOWORD(wParam);
|
int id = LOWORD(wParam);
|
|
|
if (id == IDOK && HIWORD(wParam) == BN_CLICKED) {
|
if (id == IDOK && HIWORD(wParam) == BN_CLICKED) {
|
score[flag_size].highscore = second;
|
score[flag_size].highscore = second;
|
SendMessage (hName, WM_GETTEXT,
|
SendMessage (hName, WM_GETTEXT,
|
19, (LPARAM)score[flag_size].name);
|
19, (LPARAM)score[flag_size].name);
|
#if 0
|
#if 0
|
FILE* pHighscore;
|
FILE* pHighscore;
|
int i;
|
int i;
|
if ((pHighscore = fopen("res/.highscore.bomb", "w+"))){
|
if ((pHighscore = fopen("res/.highscore.bomb", "w+"))){
|
for (i = 0; i < 3; i++)
|
for (i = 0; i < 3; i++)
|
fprintf(pHighscore, "%d, %s\n",
|
fprintf(pHighscore, "%d, %s\n",
|
score[i].highscore,score[i].name);
|
score[i].highscore,score[i].name);
|
fclose(pHighscore);
|
fclose(pHighscore);
|
}
|
}
|
#endif
|
#endif
|
PostMessage (hWnd, WM_CLOSE, 0, 0);
|
PostMessage (hWnd, WM_CLOSE, 0, 0);
|
}
|
}
|
}
|
}
|
break;
|
break;
|
case WM_CLOSE:
|
case WM_CLOSE:
|
DestroyWindow (hPrompt);
|
DestroyWindow (hPrompt);
|
DestroyWindow (hName);
|
DestroyWindow (hName);
|
DestroyWindow (hOK);
|
DestroyWindow (hOK);
|
DestroyWindow (hWnd);
|
DestroyWindow (hWnd);
|
hCongratulate = HWND_DESKTOP;
|
hCongratulate = HWND_DESKTOP;
|
return 0;
|
return 0;
|
}
|
}
|
|
|
return DefWindowProc(hWnd, message, wParam, lParam);
|
return DefWindowProc(hWnd, message, wParam, lParam);
|
}
|
}
|
|
|
void InitCongratulationCreateInfo (HWND hHosting, PMAINWINCREATE pCreateInfo)
|
void InitCongratulationCreateInfo (HWND hHosting, PMAINWINCREATE pCreateInfo)
|
{
|
{
|
pCreateInfo->dwStyle = WS_BORDER | WS_CAPTION | WS_VISIBLE;
|
pCreateInfo->dwStyle = WS_BORDER | WS_CAPTION | WS_VISIBLE;
|
pCreateInfo->spCaption = "Congratulation" ;
|
pCreateInfo->spCaption = "Congratulation" ;
|
pCreateInfo->hMenu = 0;
|
pCreateInfo->hMenu = 0;
|
pCreateInfo->hCursor = 0; /* GetSystemCursor(0); */
|
pCreateInfo->hCursor = 0; /* GetSystemCursor(0); */
|
pCreateInfo->hIcon = 0;
|
pCreateInfo->hIcon = 0;
|
pCreateInfo->MainWindowProc = CongratulationWinProc;
|
pCreateInfo->MainWindowProc = CongratulationWinProc;
|
pCreateInfo->lx = 50;
|
pCreateInfo->lx = 50;
|
pCreateInfo->ty = 60;
|
pCreateInfo->ty = 60;
|
pCreateInfo->rx = 255;
|
pCreateInfo->rx = 255;
|
pCreateInfo->by = 200;
|
pCreateInfo->by = 200;
|
pCreateInfo->iBkColor = LTGRAY;
|
pCreateInfo->iBkColor = LTGRAY;
|
pCreateInfo->dwAddData = 0;
|
pCreateInfo->dwAddData = 0;
|
pCreateInfo->hHosting = hHosting;
|
pCreateInfo->hHosting = hHosting;
|
}
|
}
|
|
|
HWND
|
HWND
|
CreateMainWindow(PMAINWINCREATE pCreateInfo)
|
CreateMainWindow(PMAINWINCREATE pCreateInfo)
|
{
|
{
|
HWND hwnd;
|
HWND hwnd;
|
RECT rc;
|
RECT rc;
|
WNDCLASS wc;
|
WNDCLASS wc;
|
|
|
wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
|
wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
|
wc.lpfnWndProc = (WNDPROC)pCreateInfo->MainWindowProc;
|
wc.lpfnWndProc = (WNDPROC)pCreateInfo->MainWindowProc;
|
wc.cbClsExtra = 0;
|
wc.cbClsExtra = 0;
|
wc.cbWndExtra = 0;
|
wc.cbWndExtra = 0;
|
wc.hInstance = 0;
|
wc.hInstance = 0;
|
wc.hIcon = pCreateInfo->hIcon;
|
wc.hIcon = pCreateInfo->hIcon;
|
wc.hCursor = pCreateInfo->hCursor;
|
wc.hCursor = pCreateInfo->hCursor;
|
wc.hbrBackground = (HBRUSH)CreateSolidBrush(pCreateInfo->iBkColor);
|
wc.hbrBackground = (HBRUSH)CreateSolidBrush(pCreateInfo->iBkColor);
|
wc.lpszMenuName = 0;
|
wc.lpszMenuName = 0;
|
wc.lpszClassName = pCreateInfo->spCaption;
|
wc.lpszClassName = pCreateInfo->spCaption;
|
RegisterClass(&wc);
|
RegisterClass(&wc);
|
|
|
SetRect(&rc, pCreateInfo->lx, pCreateInfo->ty, pCreateInfo->rx,
|
SetRect(&rc, pCreateInfo->lx, pCreateInfo->ty, pCreateInfo->rx,
|
pCreateInfo->by);
|
pCreateInfo->by);
|
AdjustWindowRectEx(&rc, pCreateInfo->dwStyle, FALSE, 0L);
|
AdjustWindowRectEx(&rc, pCreateInfo->dwStyle, FALSE, 0L);
|
|
|
hwnd = CreateWindowEx(0L, pCreateInfo->spCaption,
|
hwnd = CreateWindowEx(0L, pCreateInfo->spCaption,
|
pCreateInfo->spCaption,
|
pCreateInfo->spCaption,
|
pCreateInfo->dwStyle,
|
pCreateInfo->dwStyle,
|
rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
|
rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
|
pCreateInfo->hHosting,
|
pCreateInfo->hHosting,
|
(HMENU)0, (HINSTANCE)0,
|
(HMENU)0, (HINSTANCE)0,
|
(PVOID)pCreateInfo->dwAddData);
|
(PVOID)pCreateInfo->dwAddData);
|
return hwnd;
|
return hwnd;
|
}
|
}
|
|
|
BOOL
|
BOOL
|
PtInRect2(const RECT *lprc, int x, int y)
|
PtInRect2(const RECT *lprc, int x, int y)
|
{
|
{
|
POINT p;
|
POINT p;
|
|
|
p.x = x;
|
p.x = x;
|
p.y = y;
|
p.y = y;
|
return PtInRect(lprc, p);
|
return PtInRect(lprc, p);
|
}
|
}
|
|
|
void
|
void
|
Draw3DUpFrame(HDC hDC, int l, int t, int r, int b, int fillc)
|
Draw3DUpFrame(HDC hDC, int l, int t, int r, int b, int fillc)
|
{
|
{
|
RECT rc;
|
RECT rc;
|
HBRUSH hbr;
|
HBRUSH hbr;
|
|
|
SetRect(&rc, l, t, r, b);
|
SetRect(&rc, l, t, r, b);
|
Draw3dBox(hDC, rc.left, rc.top,
|
Draw3dBox(hDC, rc.left, rc.top,
|
rc.right-rc.left, rc.bottom-rc.top,
|
rc.right-rc.left, rc.bottom-rc.top,
|
GetSysColor(COLOR_3DLIGHT),
|
GetSysColor(COLOR_3DLIGHT),
|
GetSysColor(COLOR_WINDOWFRAME));
|
GetSysColor(COLOR_WINDOWFRAME));
|
InflateRect(&rc, -1, -1);
|
InflateRect(&rc, -1, -1);
|
Draw3dBox(hDC, rc.left, rc.top,
|
Draw3dBox(hDC, rc.left, rc.top,
|
rc.right-rc.left, rc.bottom-rc.top,
|
rc.right-rc.left, rc.bottom-rc.top,
|
GetSysColor(COLOR_BTNHIGHLIGHT),
|
GetSysColor(COLOR_BTNHIGHLIGHT),
|
GetSysColor(COLOR_BTNSHADOW));
|
GetSysColor(COLOR_BTNSHADOW));
|
InflateRect(&rc, -1, -1);
|
InflateRect(&rc, -1, -1);
|
|
|
hbr = CreateSolidBrush(LTGRAY);
|
hbr = CreateSolidBrush(LTGRAY);
|
FillRect(hDC, &rc, hbr);
|
FillRect(hDC, &rc, hbr);
|
DeleteObject(hbr);
|
DeleteObject(hbr);
|
}
|
}
|
|
|