資源描述:
《C編寫的“掃雷”源程序》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫。
1、//headerfile#include#inelude#inelude#inelude#ineludevconio.h>//defines#defineKEY_UP0xE048#defineKEY_DOWN0xE050#defineKEY_LEFT0xE04B#defineKEY_RIGHT0xE04D#defineKEY_ESCOxOOlB#defineKEY_1*1'#defineKEY_22#defineKEY_33#defineGAMEMAXWIDTH100#defineGAME_MA
2、X_HEIGHT100//StringsResource#defineSTR_GAMETITLEHArrowKey:MoveCursorKeyl:OpenKey2:MarkKey3:OpenNeighborsH#defineSTR_GAMEWIN"Congratulations!YouWin!Thankyouforplaying!"#defineSTR_GAMEOVER"GameOver,thankyouforplaying!"#defineSTR_GAMEEND"Presentedbyyzfy.PressESCtoexit"http:////Baseclassc
3、lassCConsoleWnd{public:staticintTextOut(constchar*);staticintGotoXY(intzint);staticintCharOut(int,int,constint);staticintTextOutfint,int,constchar*);staticintGetKey();public:};//{{//classCConsoleWnd////intCConsoleWnd::GetKey()//WaitforstandardinputandreturntheKeyCode//intCConsoleWnd::Ge
4、tKey()intnkey=getch(),nk=O;if(nkey>=12811nkey==O)nk=getch();returnnk>0?nkey*256+nk:nkey;}////intCConsoleWnd::GotoXY(intx,inty)//Movecursorto(x,y)//OnlyConsoleApplication//intCConsoleWnd::GotoXY(intx,inty){COORDcd;cd.X=x;cd.Y=y;returnSetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDL
5、E),cd);}////intCConsoleWnd::TextOut(constchar*pstr)//Outputastringatcurrentposition//intCConsoleWnd::TextOut(constchar*pstr){for(;*pstr;++pstr)putchar(*pstr);return0;}////intCConsoleWnd::CharOut(intx,inty,constintpstr)//Outputacharat(x,y)//intCConsoleWnd::CharOut(intx,inty,constintpstr)
6、{GotoXY(x,y);returnputchar(pstr);}////intCConsoleWnd::TextOut(constchar*pstr)//Outputastringat(x,y)//intCConsoleWnd::TextOut(intx,inty,constchar*pstr){GotoXY(x,y);returnTextOut(pstr);}//}}////ApplicationclassclassCSLGame:publicCConsoleWndprivate:private:intcurX,curY;intpoolWidth,poolHei
7、ght;intbm_gamepool[GAME_MAX_HEIGHT+2][GAME_MAX_WIDTH+2];public:CSLGame():curX(0)zcurY(0){poolWidth=poolHeight=0;}intlnitPool(int,int,int);intMoveCursor(){returnCConsoleWnd::GotoXY(curX,curY);}intDrawPool(int);intWaitMessagef);intGetShowNum(int,int);intTryOpen(int,int);private:i