linux使用gcc实现扫雷,基于linux环境下扫雷应用程序
基于linux环境下扫雷应用程序
(16页)
本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦!
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
天天文库所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。
linux使用gcc实现扫雷,基于linux环境下扫雷应用程序相关推荐
- 基于VB环境下的语音识别程序开发方法
摘要:语音识别技术的发展和广泛应用,使用户与计算机的对话方式不再仅仅局限在使用键盘或鼠标发送指令的方式.本文在visual basic 编程环境下使用Microsoft Speech SDK中的语音接 ...
- Linux上运行扫雷,基于linux环境下扫雷应用程序.docx
总俶斜技誓魄 <网络操作糸统>掖告 (应用程序开发丿 题 目: 基于I inux平台GCC环境下扫雷应用程 序开发 姓 名: 李磊 学 院: 理学院 专 业: 网络工程 班 级: 092 ...
- 基于linux的驱动设计,《基于LINUX的虚拟驱动设计》-毕业论文.doc
PAGE 40 l 摘 要 驱动程序是当前最热门.最有发展前途的IT应用技术之一.目前的驱动程序的开发主要应用在包括键盘 .鼠标.扫描仪.打印机以及存储设备等日益普及的设备之间的通讯上.但是要使这些设 ...
- 计算机网络环境中学科教学,浅谈基于计算机网络环境下的农村小学的科学学科教育...
浅谈基于计算机网络环境下的农村小学的科学学科教育 [内容摘要] <国家中长期教育改革和发展规划纲要(2010-2020年)>明确提出:加快教育信息化进程.重点加强农村学校信息基础建设,缩小 ...
- 基于Windows环境下cmd/编译器无法输入中文,显示中文乱码解决方案
基于Windows环境下cmd/编译器无法输入中文,显示中文乱码解决方案 参考文章: (1)基于Windows环境下cmd/编译器无法输入中文,显示中文乱码解决方案 (2)https://www.cn ...
- 基于SDN环境下的DDoS异常攻击的检测与缓解--实验
基于SDN环境下的DDoS异常攻击的检测与缓解--实验 基于SDN环境下的DDoS异常攻击的检测与缓解--实验 1.安装floodlight 2.安装sFlow-RT流量监控设备 3.命令行安装cur ...
- 基于keil环境下mm32f327单片机rtthread的移植
基于keil环境下mm32f327单片机rtthread的移植 文章目录 基于keil环境下mm32f327单片机rtthread的移植 前言 一.所需资源 二.创建工程目录 三.复制所需文件到相应文 ...
- python商品打折问题_基于Python环境下打折力度对营业额和利润率影响的研究
龙源期刊网 http://www.qikan.com.cn 基于 Python 环境下打折力度对营业额和利 润率影响的研究 作者:吴生根 来源:<读天下> 2020 年第 01 期 摘 要 ...
- 基于Windows环境下CPU和GPU版本Tensorflow详细安装过程
基于Windows环境下CPU和GPU版本Tensorflow详细安装过程 一.Tensorflow简介 TensorFlow 是一个开源的.基于 Python 的机器学习框架,它由 Google 开 ...
最新文章
- 使用PowerDesigner做数据库设计(二)
- HTML期末学生大作业-乒乓球网页作业html+css+javascript
- php curl cookie 读写
- 在Gilt使用Scala、Docker和AWS演化微服务
- 浙大 pat 1023题解
- UVa 642 - Word Amalgamation
- 销售行业转行软件测试,这是我成功的感受...
- 【English】十六、时间相关
- react-native学习小结
- 惩罚函数将有约束优化转化为无约束优化问题
- deb包一般放在linux的哪个目录下,deb包安装目录详解
- python中quadratic_python 练习题:定义一个函数quadratic(a, b, c),接收3个参数,返回一元二次方程ax^2+bx+c=0的两个解...
- 6种自动化测试框架(总有一款适合你)
- Android高版本联网失败报错:Cleartext HTTP traffic to xxx not permitted解决方法
- 通过.git/info/exclude文件配置忽略文件
- 有关tty hangup
- 【代码解析】mmaction2: SlowFast
- 软件测试培训之bug管理
- 芭芭拉--金字塔原理——读后感
- 第二届全国大学生算法设计与编程挑战赛(冬季赛)题解