-
大小: 15KB文件類型: .cpp金幣: 1下載: 0 次發(fā)布日期: 2021-05-07
- 語(yǔ)言: C/C++
- 標(biāo)簽: 掃雷??c++課設(shè)??VC6.0??控制臺(tái)??
資源簡(jiǎn)介
用VC6.0寫的一款在控制臺(tái)里玩的掃雷游戲
代碼片段和文件信息
#include?
#include?
#include?
#include?
#include?
using?namespace?std;
//?宏定義
#define?KEY_UP????0xE048?????????????//↑鍵
#define?KEY_DOWN??0xE050?????????????//↓鍵
#define?KEY_LEFT??0xE04B?????????????//←鍵
#define?KEY_RIGHT?0xE04D?????????????//→鍵
#define?KEY_ESC???0x001B?????????????//ECS鍵
#define?KEY_1?????‘1‘????????????????//字符1
#define?KEY_2?????‘2‘????????????????//字符2
#define?KEY_3?????‘3‘????????????????//字符3
#define?KEY_4?????‘4‘????????????????//字符4
#define?GAME_MAX_WIDTH???50?????????//最大寬度?x
#define?GAME_MAX_HEIGHT??50?????????//最大高度?y
//宏定義顏色
#define?LIGHTBLUE??????9?//????1????藍(lán)色
#define?LAKEBLUE???????3?//????2????湖藍(lán)色
#define?LIGHTGREEN?????11?//????3????黃色
#define?PURPLE?????????5?//????4????紫色
#define?LIGHTPURPLE????13?//?5678?淡紫色
#define?WHITE??????????7?//???方塊??白色
#define?GREEN??????????2?//???標(biāo)記??綠色
#define?LIGHTRED???????12?//???雷區(qū)??淡紅色
#define?YELLOW?????????6?//??誤掃????黃色
//?字符串宏定義,用于游戲結(jié)束后的不同使用
#define?STR_GAMEtitle?“\t游戲指南:1?=?使勁.踩;2?=?我.掃...;3?=?AOE群**?;ESC?=?返回主菜單“
#define?STR_GAMEWIN???“\t祝賀你!掃雷成功!\n“
#define?STR_GAMEOVER??“\t踩到地雷!對(duì)不起你輸了!\n“
#define?STR_GAMEEND???“\n\t\t感謝使用~!歡迎下次再來O(∩_∩)O~~\n“
static?int?BoomNum;
static?int?NowBoomNum;
//-------------------------------------------------------------
//?控制臺(tái)類---指示光標(biāo)等控制臺(tái)操作
class?CConsoleWnd
{
????public:
????????static?int?TextOut(const?char*);?????????????//輸出字符串
????????static?int?GotoXY(int?int);?????????????????//光標(biāo)指向(x,y)
????????static?int?CharOut(int?int?const?int);?????//輸出位于(x,y)上的字符
????????static?int?TextOut(int?int?const?char*);???//輸出位于(x,y)上的字符串
????????static?int?GetKey();?????????????????????????//獲取鍵入的ASCII碼
};
//
//??int?CConsoleWnd::GetKey()
//??等待標(biāo)準(zhǔn)輸入,返回鍵碼
//
int?CConsoleWnd::GetKey()
{
int?nkey=getch()nk=0;
if(nkey>=128||nkey==0)nk=getch();
return?nk>0?nkey*256+nk:nkey;
}
//
//??int?CConsoleWnd::GotoXY(int?x?int?y)
//??將控制臺(tái)光標(biāo)移至(x,y)點(diǎn)
//
int?CConsoleWnd::GotoXY(int?x?int?y)
{
COORD?cd;
cd.X?=?x;cd.Y?=?y;
return?SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE)cd);
}
//
//??int?CConsoleWnd::TextOut(const?char*?pstr)
//??在當(dāng)前位置輸出字符串
//
int?CConsoleWnd::TextOut(const?char*?pstr)
{
for(;*pstr;++pstr)putchar(*pstr);
return?0;
}
//
//??int?CConsoleWnd::CharOut(int?x?int?y?const?int?pstr)
//??輸出在(x,y)上的字符
//
int?CConsoleWnd::CharOut(int?x?int?y?const?int?pstr)
{
GotoXY(x?y);
return?putchar(pstr);
}
//
//??int?CConsoleWnd::TextOut(const?char*?pstr)
//??輸出在(x,y)上的字符串
//
int?CConsoleWnd::TextOut(int?x?int?y?const?char*?pstr)
{
GotoXY(x?y);
return?TextOut(pstr);
}
//
//-------------------------------------------------------------
//應(yīng)用類---正式玩游戲??控制臺(tái)類的派生類
class?CSLGame:public?CConsoleWnd
{
private:
private:
int?curXcurY;?????????//當(dāng)前x,y
int?poolWidthpoolHeight;?????//當(dāng)前寬度和高度
int?bm_gamepool[GAME_MAX_HEIGHT+2][GAME_MAX_WIDTH+2];????//游戲存放字符的二維數(shù)組
public:
CSLGame():curX(
評(píng)論
共有 條評(píng)論