怎么用c 制作扫雷游戏
本篇内容主要讲解“怎么用c 制作扫雷游戏”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“怎么用c 制作扫雷游戏”吧!
具体代码如下
#ifndefsaolei_h#definesaolei_hclassblock{friendclasssaoleigame;public:block();boolisshown();voidsetnum(int);intgetnum();boolisbomb();protected:intnum;boolflag_show;intx;inty;};classsaoleigame{public:saoleigame();~saoleigame();void_init_();voidgamestart();voidreflash();voidcheck(intx,inty);voidclick(intx,inty);voidgameover();private:blockjuzheng[100];boolflag;intb[10];unsignedintscore;};#endif
以上是编写的头文件
#include#include#include#include"saolei.h"usingnamespacestd;saoleigame::saoleigame(){_init_();flag=true;score=0;}saoleigame::~saoleigame(){}voidsaoleigame::_init_(){srand(time(null));for(inti=0;i<10;i ){b[i]=-1;}for(inti=0;i<10;i ){booltemp_flag=false;do{inttemp=(unsignedint)rand()0;for(intj=0;j=10||j y<=0&&y j>=10)){if(juzheng[(x i-1)*10 (y j-1)].num==-1)number ;}}}juzheng[(x-1)*10 (y-1)].setnum(number);}voidsaoleigame::click(intx,inty){if(juzheng[(x-1)*10 (y-1)].num==0){for(inti=-1;i<2;i ){for(intj=-1;j<2;j ){if(!((x i<=0||x i>10)||(j y<=0||y j>10))&&!(i==0&&j==0)&&!juzheng[(x i-1)*10 (y j-1)].flag_show){juzheng[(x i-1)*10 (y j-1)].flag_show=true;click(x i,y j);}}}}juzheng[(x-1)*10 (y-1)].flag_show=true;return;}voidsaoleigame::gamestart(){do{reflash();intx,y;cout<<"inputtheposition:";cin>>x>>y;if(juzheng[(x-1)*10 (y-1)].isbomb()){gameover();return;}else{click(x,y);}}while(flag);}voidsaoleigame::reflash(){system("cls");score=0;cout<<"扫雷"<
到此,相信大家对“怎么用c 制作扫雷游戏”有了更深的了解,不妨来实际操作一番吧!这里是恰卡编程网网站,更多相关内容可以进入相关频道进行查询,关注亚博电竞手机版,继续学习!
展开全文