📄 bomb.c
字号:
/*** $Id: bomb.c,v 1.7 2006-03-02 05:28:15 xgwang Exp $**** bomb.c: The MineSweeper game.**** Copyright (C) 1999~ 2002 Zheng Xiang and others.** Copyright (C) 2003 Feynman Software.*//*** This source is free software; you can redistribute it and/or** modify it under the terms of the GNU General Public** License as published by the Free Software Foundation; either** version 2 of the License, or (at your option) any later version.**** This software is distributed in the hope that it will be useful,** but WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU** General Public License for more details.**** You should have received a copy of the GNU General Public** License along with this library; if not, write to the Free** Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,** MA 02111-1307, USA*/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#include <unistd.h>#include <pwd.h>#include <minigui/common.h>#include <minigui/minigui.h>#include <minigui/gdi.h>#include <minigui/window.h>#include <minigui/control.h>static const char* lang= "en";static const char**pmain_menu =NULL;static const char**pstart_menu =NULL;static const char**pabout_menu =NULL;static const char**plevel_menu =NULL;static const char**pmessagebox =NULL;static const char* messagebox_cn[] ={ "扫雷-1.0\n\nCopyright (C) 2003 ~ 2008 北京飞漫软件技术有限公司\n\n 保留所有权利", "扫雷", "扫雷游戏 1.0 (2000/04/11)", "作者: Mis. Zheng Xiang (xiang_zi@263.net).", " Mis. Glory (glory@263.net).", "关于", "重置", "确定", "英雄榜", "低", "中", "高", "高分", "请输入您的名字", "恭喜"};static const char* messagebox_tw[] ={ "掃雷-1.0\n\nCopyright (C) 2003 ~ 2008 北京飛漫軟件技術有限公司\n\n 保留所有權利", "掃雷", "掃雷游戲 1.0 (2000/04/11)", "作者: Mis. Zheng Xiang (xiang_zi@263.net).", " Mis. Glory (glory@263.net).", "關於", "重置", "確定", "英雄榜", "低", "中", "高", "高分", "請輸入您的名字", "恭喜"};static const char* messagebox_en[] ={ "Mine Sweeper -- Version 1.0\n\nCopyright (C) 2003 ~ 2008 Beijing Feynman Software Technology Co., Ltd.\nAll rights reserved.", //0 "Mine Sweeper", //1 "Mine Sweeper Game Ver 1.0 (2000/04/11)", //2 "Author: Mis. Zheng Xiang (xiang_zi@263.net).", //3 " Mis. Glory (glory@263.net).", //4 "The about window", //5 "Reset", //6 "OK", //7 "Heroes", //8 "SMALL", //9 "MIDDLE", //10 "LARGE", //11 "High Score", //12 "Please input your name:", //13 "Congratulation" //14};static const char* level_menu_cn[] ={ "级別", "高", "中", "低"};static const char* level_menu_tw[] ={ "級別", "高", "中", "低"};static const char* level_menu_en[] ={ "Level", "Large", "Middle", "Small"};static const char* about_menu_cn[] ={ "关于", "关于扫雷游戏"};static const char* about_menu_tw[] ={ "關於", "關於掃雷游戲"};static const char* about_menu_en[] ={ "About", "About Mine Sweeper"};static const char* start_menu_cn[] ={ "开始", "新游戏", "高分", "退出"};static const char* start_menu_tw[] ={ "開始", "新游戲", "高分", "退出"};static const char* start_menu_en[] ={ "Start", //0 "New Game", //1 "High Score", //2 "Quit Game" //3};static const char* main_menu_cn[] ={ "开始", "级别", "关于"};static const char* main_menu_tw[] ={ "開始", "級別", "關於"};static const char* main_menu_en[] ={ "Start", "Level", "About"};static PLOGFONT cap_font = NULL;static PLOGFONT ctrl_font = NULL;static PLOGFONT menu_font = NULL;static PLOGFONT utf8_font = NULL;static void init_minesweeper(void){ cap_font = g_SysLogFont[SYSLOGFONT_CAPTION]; ctrl_font = g_SysLogFont[SYSLOGFONT_CONTROL]; menu_font = g_SysLogFont[SYSLOGFONT_MENU]; utf8_font = CreateLogFontByName("*-fmsong-rrncnn-*-12-UTF-8"); g_SysLogFont[SYSLOGFONT_CAPTION] = utf8_font; g_SysLogFont[SYSLOGFONT_CONTROL] = utf8_font; g_SysLogFont[SYSLOGFONT_MENU] = utf8_font; if(strcasecmp(lang,"zh_cn")==0){ local_SysText = GetSysTextInUTF8("zh_CN"); } else if(strcasecmp(lang,"zh_tw")==0){ local_SysText = GetSysTextInUTF8("zh_TW"); } else local_SysText = GetSysTextInUTF8("EN");}static void release_minesweeper(void){ g_SysLogFont[SYSLOGFONT_CAPTION] = cap_font; g_SysLogFont[SYSLOGFONT_CONTROL] = ctrl_font; g_SysLogFont[SYSLOGFONT_MENU] = menu_font; DestroyLogFont(utf8_font);}typedef struct { int flag; int value; BOOL test; BOOL hit; BOOL bombout; BOOL error;}BOM;typedef struct { int x; int y; BOOL NY;}NO;typedef struct{ int highscore; char name[20];}SCORE;static BOM bom[30][16];static NO NoAdr[540];static SCORE score[3];static int itime, leftbombnum;static int bombnum = 99;void SearchGround(HWND hWnd,int x,int y);int Open(HWND hWnd,int x,int y);int TestMyWinProc(HWND hWnd,int message,WPARAM wParam,LPARAM lParam);void InitMyWinCreateInfo(PMAINWINCREATE pCreateInfo);void InitAbHostedCreateInfo(HWND hHosting, PMAINWINCREATE pCreateInfo); void InitHighScoreCreateInfo (HWND hHosting, PMAINWINCREATE pCreateInfo);void InitCongratulationCreateInfo (HWND hHosting, PMAINWINCREATE pCreateInfo);void* TestMyWindow(void* data);void BombGame(HWND hWnd, int x, int y);void Finished(HWND hWnd);void Cancel3DFrame(HDC hdc, int l,int t,int r,int b);void TextValue(HDC hdc, int x,int y,int value);void BombOut(HWND hWnd);void BothButtonDownProc(HWND hWnd, int x, int y);void DrawDigit(HDC hdc, char* buffer, int CLOCK);#define ID_ABOUT 300#define ID_NEW 301 #define ID_LARGE 302#define ID_MIDDLE 303#define ID_SMALL 304#define ID_CLOSE 305#define ID_HIGHSCORE 306#define ID_CLOCK 400#define WIDTH_LARGEWIN 544#define HEIGHT_LARGEWIN 470#define WIDTH_MIDDLEWIN 292#define HEIGHT_MIDDLEWIN 430#define WIDTH_SMALLWIN 178#define HEIGHT_SMALLWIN 270#define WIDTH_FACE 30#define HEIGHT_FACE 30#define WIDTH_DIGIT 14#define WIDTH_BOMNUM (2*WIDTH_DIGIT)#define HEIGHT_BOMNUM 30#define WIDTH_CLOCK (3*WIDTH_DIGIT)#define HEIGHT_CLOCK 30#define FREQ_CLOCK 10#define WIDTH_BOX 18#define HEIGHT_BOX 18static int sg_boxnumx = 30;static int sg_boxnumy = 16;static BITMAP sg_bmpDigit[10];static int oldx, oldy, adrx, adry;static int flag_bombout, flag_finished, flag_size = 2;static int second = 0;static BITMAP bitmap1, bmpflag;static BOOL fValid1 = FALSE;static BOOL fValidflag = FALSE;static BOOL bTimer;static HWND hHighscore,hCongratuate; static int winwidth = WIDTH_LARGEWIN;static int offsetx;static int x_face, x_bomnum, x_clock;void DrawMyBitmap(HDC hdc, PBITMAP bmp, int x, int y, int w, int h){ if (bmp) FillBoxWithBitmap(hdc, x, y, w, h, bmp); else TextOut (hdc, x, y, "a");}void Cancel3DFrame(HDC hdc, int l, int t, int w, int h){ SetPenColor (hdc,COLOR_darkgray); Rectangle(hdc, l, t, l + w, t + h); SetBrushColor(hdc,COLOR_lightgray); FillBox(hdc, l+1, t+1, w-1, h-1); } void TextValue(HDC hdc, int x, int y, int value) { int color = 0; char va[20]; switch(value) { case 1: color=COLOR_blue; break; case 2: color=COLOR_green; break; case 3: color=COLOR_red; break; case 4: color=COLOR_magenta; break; case 5: color=COLOR_yellow; break; case 6: color=COLOR_cyan; break; case 7: color=COLOR_darkred; break; case 8: color=COLOR_darkgreen; break; } SetBkColor(hdc,COLOR_lightgray); SetTextColor(hdc,color); sprintf(va,"%d",value); TextOut(hdc, x + ((WIDTH_BOX - GetSysCharWidth ()) >> 1), y + ((HEIGHT_BOX - GetSysCharHeight ()) >> 1), va);} void SearchGround(HDC hdc,int x,int y){ int x1=0,y1=0; int i=1; bom[x][y].test=TRUE; NoAdr[itime].x=x; NoAdr[itime].y=y; NoAdr[itime].NY=FALSE; itime++; Cancel3DFrame(hdc,x*WIDTH_BOX+offsetx, y*HEIGHT_BOX+HEIGHT_FACE, WIDTH_BOX, HEIGHT_BOX); while( i <= 8 ) { switch(i) { case 1: x1=x-1; y1=y; break; case 2: 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 5: 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 8: y1=y+1; x1=x; break; } if( x1>=0 && y1>=0 && x1<sg_boxnumx && y1<sg_boxnumy &&!bom[x1][y1].hit&& !bom[x1][y1].test && !bom[x1][y1].value ) SearchGround(hdc,x1,y1); if( x1>=0 && y1>=0 && x1<sg_boxnumx && y1<sg_boxnumy &&!bom[x1][y1].hit &&!bom[x1][y1].test && bom[x1][y1].value!=0 ) { bom[x1][y1].test=TRUE; NoAdr[itime].x=x1; NoAdr[itime].y=y1; NoAdr[itime].NY=TRUE; itime++; Cancel3DFrame(hdc, x1*WIDTH_BOX+offsetx, y1*HEIGHT_BOX+HEIGHT_FACE, WIDTH_BOX, HEIGHT_BOX); TextValue(hdc, x1*WIDTH_BOX+offsetx, y1*HEIGHT_BOX+HEIGHT_FACE, bom[x1][y1].value); } i++; } } BOOL Open(HWND hWnd,int x,int y){ int x1=0,y1=0; int i=1; HDC hdc; hdc = GetClientDC(hWnd); while( i <= 8 ) { switch( i ) { case 1: x1=x-1; y1=y; break; case 2: 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 5: 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 8: y1=y+1; x1=x; break; } if( x1>=0 && y1>=0 && x1<sg_boxnumx && y1<sg_boxnumy && !bom[x1][y1].hit && bom[x1][y1].flag) { ReleaseDC(hdc); return FALSE; } if( x1>=0 && y1>=0 && x1<sg_boxnumx && y1<sg_boxnumy && !bom[x1][y1].test && !bom[x1][y1].value && !bom[x1][y1].flag ){ SearchGround(hdc,x1,y1); } if( x1>=0 && y1>=0 && x1<sg_boxnumx && y1<sg_boxnumy && !bom[x1][y1].test && bom[x1][y1].value!=0 ) { bom[x1][y1].test=TRUE; NoAdr[itime].x=x1; NoAdr[itime].y=y1; NoAdr[itime].NY=TRUE; itime++; Cancel3DFrame(hdc, x1*WIDTH_BOX+offsetx, y1*HEIGHT_BOX+HEIGHT_FACE, WIDTH_BOX, HEIGHT_BOX); TextValue(hdc, x1*WIDTH_BOX+offsetx, y1*HEIGHT_BOX+HEIGHT_FACE, bom[x1][y1].value); } i++; } ReleaseDC(hdc); return TRUE; }static BITMAP bmpbom, bmpface, bmphitfalse;static BOOL fValidbom = FALSE,fValidface = FALSE, fValidhitfalse = FALSE;void BombOut(HWND hWnd){ int i,j; HDC hdc; hdc=GetClientDC(hWnd); for (i = 0; i < sg_boxnumx; i++) { for (j = 0; j < sg_boxnumy; j++) { if (bom[i][j].flag && !bom[i][j].hit) { Cancel3DFrame(hdc,i*WIDTH_BOX+offsetx,j*HEIGHT_BOX+HEIGHT_FACE, WIDTH_BOX,HEIGHT_BOX); DrawMyBitmap(hdc, fValidbom?&bmpbom:NULL, i*WIDTH_BOX+offsetx+1, j*HEIGHT_BOX+1+HEIGHT_FACE, 0, 0); bom[i][j].bombout = TRUE; } if (!bom[i][j].flag && bom[i][j].hit){ Cancel3DFrame(hdc,i*WIDTH_BOX+offsetx,j*HEIGHT_BOX+HEIGHT_FACE, WIDTH_BOX,HEIGHT_BOX); DrawMyBitmap(hdc, fValidhitfalse?&bmphitfalse:NULL, i*WIDTH_BOX+offsetx+1, j*HEIGHT_BOX+1+HEIGHT_FACE, 0, 0); bom[i][j].error = TRUE; } } } DrawMyBitmap (hdc, fValidface?&bmpface:NULL, x_face, 0, 0, 0); flag_bombout = 1; bTimer = FALSE; ReleaseDC(hdc);}static BITMAP bmpfinalface;static BOOL fValidfinalface = FALSE;void Finished(HWND hWnd){ int i,j; HDC hdc; RECT bombnumber; MAINWINCREATE CreateInfo; hdc = GetClientDC(hWnd); for (i = 0; i < sg_boxnumx; i++) { for (j = 0; j < sg_boxnumy; j++) { if (bom[i][j].flag && !bom[i][j].hit) { DrawMyBitmap(hdc, fValidflag?&bmpflag:NULL, i*WIDTH_BOX+offsetx+3, j*HEIGHT_BOX+3+HEIGHT_FACE, WIDTH_BOX - 5, HEIGHT_BOX - 5); bom[i][j].hit = TRUE; } } } DrawMyBitmap (hdc, fValidfinalface?&bmpfinalface:NULL, x_face+1, 1, 0, 0); flag_finished = 1; bTimer = FALSE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -