linux使用gcc实现扫雷,基于linux环境下扫雷应用程序

本文档详细介绍了如何在Linux平台的GCC环境下开发一款扫雷应用程序。内容涵盖程序的功能、硬件和软件需求,以及核心的C语言代码实现。程序包括初始化游戏池、绘制游戏界面、获取用户输入及判断游戏状态等功能。
摘要由CSDN通过智能技术生成

62e50291a81fc54b507f33cb80033297.gif 基于linux环境下扫雷应用程序

(16页)

136a6413f69409938a3d164cedef685f.gif

本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦!

19.90 积分

《网络操作系统》报告(应用程序开发)题 目: 基于linux平台GCC环境下扫雷应用程 序开发 姓 名: 李磊 学 院: 理学院 专 业: 网络工程 班 级: 092 学 号: 1887090211 2012 年 01月 01 日基于Linux平台GCC环境下扫雷应用程序开发1 应用程序功能 通过模拟windows系统中的扫雷应用程序,在linux平台gcc环境下实现C语言扫雷应用程序。2 硬件平台内存2.0G,硬盘320G,CPU Pentium 4以上PC机一台3 软件平台 3.1 操作系统平台linux cygwin环境3.2 应用软件平台(黑体小四号) Visual C++ 6.0或其他C语言编译程序,linux cygwin环境,GCC编译条件3.3 应用程序// header file#include #include #include #include #include // defines#define KEY_UP 0xE048#define KEY_DOWN 0xE050#define KEY_LEFT 0xE04B#define KEY_RIGHT 0xE04D#define KEY_ESC 0x001B#define KEY_1 '1'#define KEY_2 '2'#define KEY_3 '3'#define GAME_MAX_WIDTH 100#define GAME_MAX_HEIGHT 100// Strings Resource#define STR_GAMETITLE "程序说明: 数字键1打开 \数字键2标记 数字键3打开附近盒子"#define STR_GAMEWIN "亲,祝贺你赢了哦,再接再厉哦!\n"#define STR_GAMEOVER "亲,你咋那么笨呢?挂了吧!\n"#define STR_GAMEEND " 亲,按 ESC 键退出程序\n"//-------------------------------------------------------------// Base classclass CConsoleWnd{ public: static int TextOut(const char*); static int GotoXY(int, int); static int CharOut(int, int, const int); static int TextOut(int, int, const char*); static int GetKey(); public:};//{{// class CConsoleWnd // // int CConsoleWnd::GetKey() // Wait for standard input and return the KeyCode // 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) // Move cursor to (x,y) // Only Console Application // 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) // Output a string at current position // int CConsoleWnd::TextOut(const char* pstr) { for(;*pstr;++pstr)putchar(*pstr); return 0; } // // int CConsoleWnd::CharOut(int x, int y, const int pstr) // Output a char at (x,y) // int CConsoleWnd::CharOut(int x, int y, const int pstr) { GotoXY(x, y); return putchar(pstr); } // // int CConsoleWnd::TextOut(const char* pstr) // Output a string at (x,y) // int CConsoleWnd::TextOut(int x, int y, const char* pstr) { GotoXY(x, y); return TextOut(pstr); }//}}//-------------------------------------------------------------//Application classclass CSLGame:public CConsoleWnd{ private: private: int curX,curY; int poolWidth,poolHeight; int bm_gamepool[GAME_MAX_HEIGHT+2][GAME_MAX_WIDTH+2]; public: CSLGame():curX(0),curY(0){poolWidth=poolHeight=0;} int InitPool(int, int, int); int MoveCursor(){return CConsoleWnd::GotoXY(curX, curY);} int DrawPool(int); int WaitMessage(); int GetShowNum(int, int); int TryOpen(int, int); private: int DFSShowNum(int, int); private: const static int GMARK_BOOM; const static int GMARK_EMPTY; const static int GMARK_MARK;};const int CSLGame::GMARK_BOOM = 0x10;const int CSLGame::GMARK_EMPTY= 0x100;const int CSLGame::GMARK_MARK = 0x200;//{{// class CSLGame:public CConsoleWnd // // int CSLGame::InitPool(int Width, int Height, int nBoom) // Initialize the game pool. // If Width*Height <= nBoom, or nBoom<=0, // or Width and Height exceed limit , then return 1 // otherwise return 0 // int CSLGame::InitPool(int Width, int Height, int nBoom) { poolWidth = Width; poolHeight = Height; if(nBoom<=0 || nBoom>=Width*Height || Width <=0 || Width >GAME_MAX_WIDTH || Height<=0 || Height>GAME_MAX_HEIGHT ){ return 1; } // zero memory for(int y=0; y<=Height+1; ++y) { for(int x=0; x<=Width+1; ++x) { bm_gamepool[y][x]=0; } } // init seed srand(time(NULL)); // init Booms while(nBoom) { int x = rand()%Width + 1, y = rand()%Height + 1; if(bm_gamepool[y][x]==0) { bm_gamepool[y][x] = GMARK_BOOM; --nBoom; } } // init cursor position curX = curY = 1; MoveCursor(); return 0; } // // int CSLGame::DrawPool(int bDrawBoom = 0) // Draw game pool to Console window // int CSLGame::DrawPool(int bDrawBoom = 0) { for(int y=1;y<=poolHeight;++y) { CConsoleWnd::GotoXY(1, y); for(int x=1;x<=poolWidth;++x) { if(bm_gamepool[y][x]==0) { putchar('.'); } else if(bm_gamepool[y][x]==GMARK_EMPTY) { putchar(' '); } else if(bm_gamepool[y][x]>0 && bm_gamepool[y][x]<=8) { putchar('0'+bm_gamepool[y][x]); } else if(bDrawBoom==0 && (bm_gamepool[y][x] & GMARK_MARK)) { putchar('#'); } else if(bm_gamepool[y][x] & GMARK_BOOM) { if(bDrawBoom) putchar('*'); else putchar('.'); } } } return 0; } // // int CSLGame::GetShowNum(int x, int y) // return ShowNum at (x, y) // int CSLGame::GetShowNum(int x, int y) { int nCount = 0; for(int Y=-1;Y<=1;++Y) for(int X=-1;X<=1;++X) { if(bm_gamepool[y+Y][x+X] & GMARK_BOOM)++nCount; } return nCount; } // // int CSLGame::TryOpen(int x, int y) // Try open (x, y) and show the number // If there is a boom, then return EOF // int CSLGame::TryOpen(int x, int y) { int nRT = 0; if(bm_gamepool[y][x] & GMARK_BOOM) { nRT = EOF; } else { int nCount = GetShowNum(x,y); if(nCount==0) { DFSShowNum(x, y); } else bm_gamepool[y][x] = nCount; } return nRT; } // // int CSLGame::DFSShowNum(int x, int y) // Private function, no comment // int CSLGame::DFSShowNum(int x, int y) { if((01)--curY; nArrow=1; }break; case KEY_DOWN: { if(curY1)--curX; nArrow=1; }break; case KEY_RIGHT: { if(curX

524d6daf746efaa52c3c71bbfe7ba172.gif  天天文库所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值