基于C控制台扫雷游戏Word文档格式.docx

上传人:b****4 文档编号:16053595 上传时间:2022-11-18 格式:DOCX 页数:12 大小:16.47KB
下载 相关 举报
基于C控制台扫雷游戏Word文档格式.docx_第1页
第1页 / 共12页
基于C控制台扫雷游戏Word文档格式.docx_第2页
第2页 / 共12页
基于C控制台扫雷游戏Word文档格式.docx_第3页
第3页 / 共12页
基于C控制台扫雷游戏Word文档格式.docx_第4页
第4页 / 共12页
基于C控制台扫雷游戏Word文档格式.docx_第5页
第5页 / 共12页
点击查看更多>>
下载资源
资源描述

基于C控制台扫雷游戏Word文档格式.docx

《基于C控制台扫雷游戏Word文档格式.docx》由会员分享,可在线阅读,更多相关《基于C控制台扫雷游戏Word文档格式.docx(12页珍藏版)》请在冰豆网上搜索。

基于C控制台扫雷游戏Word文档格式.docx

voidtoLeft();

voidtoRight();

voidtoTop();

voidtoBottom();

};

#endif

2)实现

#include"

Button.h"

voidButton:

:

initButton(intirow,inticolumn){

row=irow;

column=icolumn;

posX=0;

posY=0;

}

toLeft()

if(posY-1>

=0)

posY--;

toRight(){

if(posY+1<

column)

posY++;

toTop(){

if(posX-1>

posX--;

toBottom(){

if(posX+1<

row)

posX++;

intButton:

getPosX(){

returnposX;

getPosY()

returnposY;

二、Map类(存在空地和雷区)

#ifndefMAP_H_

#defineMAP_H_

classMap

int**map;

//地图指针

//行;

//列;

intnum;

//布雷数;

public:

Map();

voidnewMap();

//申请存储地图空间

voiddeleteMap();

//释放地图内存

voidinitMap();

//初始化地图

voidprintMap(Button&

);

//打印地图

voidprintMine();

//打印雷

intgetRow();

//得到行数;

voidsetRow(int);

//设置行数;

intgetColumn();

//得到列数;

voidsetColumn(int);

//设置列数;

intgetNum();

//得到布雷数;

voidsetNum(int);

//设置布雷数;

intgetVal(intx,inty);

voidsetVal(intx,inty,intval);

boolis_win();

voidOpen(int,int,Map&

//打开选取位置voidSwap(int&

int&

Map.h"

#include<

iostream>

time.h>

stdlib.h>

usingnamespacestd;

Map:

Map()

column=row=num=10;

voidMap:

newMap()

map=newint*[row];

for(inti=0;

i<

row;

i++)

*(map+i)=newint[column];

}

deleteMap()

i++)delete[]*(map+i);

delete[]map;

initMap()

intk=0;

for(intj=0;

j<

column;

j++){

if(k<

num)

*(*(map+i)+j)=-1;

k++;

else

*(*(map+i)+j)=0;

srand(time(NULL));

intrandX1,randY1;

intrandX2,randY2;

1000;

randX1=rand()%row;

randY1=rand()%column;

randX2=rand()%row;

randY2=rand()%column;

Swap(*(*(map+randX1)+randY1),*(*(map+randX2)+randY2));

printMap(Button&

button)

j++)

if(i==button.getPosX()&

&

j==button.getPosY())

cout<

<

"

☆"

;

▉"

elseif(*(*(map+i)+j)==0)

█"

elseif(*(*(map+i)+j)==1)

□"

<

*(*(map+i)+j)-1;

endl;

printMine()

if(*(*(map+i)+j)==-1)

●"

*(*(map+i)+j)-1;

boolMap:

is_win()

if(*(*(map+i)+j)==0)

returnfalse;

returntrue;

intMap:

getRow()

returnrow;

setRow(intn){

row=n;

getColumn()

returncolumn;

setColumn(intn){

column=n;

getNum()

setNum(intn)

num=n;

getVal(intx,inty)

return*(*(map+x)+y);

setVal(intx,inty,intval)

*(*(map+x)+y)=val;

voidOpen(intx,inty,Map&

myMap)

if(x<

0||y<

0||x>

=myMap.getRow()||y>

=myMap.getColumn())//访问越界

intcount=0;

if(myMap.getVal(x,y)==0)

if((x-1>

=0)&

(y-1>

myMap.getVal(x-1,y-1)==-1)//左上

count++;

myMap.getVal(x-1,y)==-1)//上

(y+1<

myMap.getColumn())&

myMap.getVal(x-1,y+1)==-1)//右上

if((y-1>

myMap.getVal(x,y-1)==-1)//左

if((y+1<

myMap.getVal(x,y+1)==

-1)//右

if((x+1<

myMap.getRow())&

myMap.getVal(x+1,y-1)==-1)//左下

myMap.getVal(x+1,y)==-1)//下

myMap.getVal(x+1,y+1)==-1)//右下

myMap.setVal(x,y,count+1);

if(myMap.getVal(x,y)==1)//若未访问且四周无雷

myMap.getVal(x-1,y-1)==0)//左上

Open(x-1,y-1,myMap);

myMap.getVal(x-1,y)==0)//上

Open(x-1,y,myMap);

myMap.getVal(x-1,y+1)==0)//右上

Open(x-1,y+1,myMap);

myMap.getVal(x,y-1)==0)//左

Open(x,y-1,myMap);

myMap.getVal(x,y+1)==0)//右

Open(x,y+1,myMap);

myMap.getVal(x+1,y-1)==0)//左下

Open(x+1,y-1,myMap);

myMap.getVal(x+1,y)==0)//下

Open(x+1,y,myMap);

(y+1

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 商务科技

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1