扫雷游戏代码Word格式文档下载.docx

上传人:b****6 文档编号:17495723 上传时间:2022-12-06 格式:DOCX 页数:16 大小:19.62KB
下载 相关 举报
扫雷游戏代码Word格式文档下载.docx_第1页
第1页 / 共16页
扫雷游戏代码Word格式文档下载.docx_第2页
第2页 / 共16页
扫雷游戏代码Word格式文档下载.docx_第3页
第3页 / 共16页
扫雷游戏代码Word格式文档下载.docx_第4页
第4页 / 共16页
扫雷游戏代码Word格式文档下载.docx_第5页
第5页 / 共16页
点击查看更多>>
下载资源
资源描述

扫雷游戏代码Word格式文档下载.docx

《扫雷游戏代码Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《扫雷游戏代码Word格式文档下载.docx(16页珍藏版)》请在冰豆网上搜索。

扫雷游戏代码Word格式文档下载.docx

QWidget>

Block:

:

Block(boolmine_flag,QWidget*parent)

:

QLabel(parent)

mine_flag_=mine_flag;

mark_flag_=false;

turn_over_flag_=false;

number_=-1;

setPixmap(QPixmap("

/images/"

));

}

voidBlock:

set_number(intnumber)

number_=number;

turn_over()

if(!

turn_over_flag_){

turn_over_flag_=true;

if(mine_flag_)

setPixmap(QPixmap("

else

/images/mine_"

+QString("

%1"

).arg(number_)+"

.png"

update();

}

boolBlock:

is_mine()const

returnmine_flag_;

is_turn_over()const

returnturn_over_flag_;

/*鼠标事件的实现*/

mousePressEvent(QMouseEvent*event)

if(event->

button()==Qt:

LeftButton){

if(!

turn_over_flag_&

&

!

mark_flag_){

turn_over_flag_=true;

if(mine_flag_==true){

setPixmap(QPixmap("

update();

emitturn_over(true);

}else{

emitturn_over(false);

}

}

}elseif(event->

RightButton){

if(!

mark_flag_=true;

mark_flag_=false;

update();

}

QLabel:

mousePressEvent(event);

#ifndefBLOCK_AREA_H_

#defineBLOCK_AREA_H_

classQEvent;

classQGridLayout;

classQObject;

classBlockArea:

publicQWidget

BlockArea(introw,intcolumn,intmine_number,QWidget*parent=0);

voidset_block_area(introw,intcolumn,intmine_number,intinit_flag=false);

voidgame_over(boolis_win);

booleventFilter(QObject*watched,QEvent*event);

privateslots:

voidslot_turn_over(boolis_mine);

intcalculate_mines(intx,inty)const;

rg(easy_record_time_)),1,1);

up_layout->

addWidget(newQLabel(easy_record_name_),1,2);

addWidget(newQLabel(tr("

Middle"

)),2,0);

addWidget(newQLabel(QString("

).arg(middle_record_time_)),2,1);

addWidget(newQLabel(middle_record_name_),2,2);

Hard"

)),3,0);

).arg(hard_record_time_)),3,1);

addWidget(newQLabel(hard_record_name_),3,2);

QPushButton*recount_button=newQPushButton(tr("

recount"

QPushButton*close_button=newQPushButton(tr("

close"

close_button->

setDefault(true);

connect(recount_button,SIGNAL(clicked()),&

dialog,SLOT(accept()));

connect(close_button,SIGNAL(clicked()),&

dialog,SLOT(reject()));

QHBoxLayout*bottom_layout=newQHBoxLayout;

bottom_layout->

addStretch();

addWidget(recount_button);

addWidget(close_button);

QVBoxLayout*main_layout=newQVBoxLayout(&

dialog);

main_layout->

addLayout(up_layout);

addLayout(bottom_layout);

if()==QDialog:

Accepted){

easy_record_time_=middle_record_time_=hard_record_time_=g_no_record_time;

easy_record_name_=middle_record_name_=hard_record_name_=g_no_record_name;

voidMainWindow:

slot_show_game_toolBar(boolshow)

if(show)

game_toolBar->

show();

else

hide();

slot_show_statusBar(boolshow)

statusBar()->

/*游戏的设置容易、中等、困难及自定义*/

slot_standard(QAction*standard_action)

if(standard_action==easy_standard_action){

current_standard_=0;

row_=9;

column_=9;

mine_number_=10;

}elseif(standard_action==middle_standard_action){

current_standard_=1;

row_=16;

column_=16;

mine_number_=40;

}elseif(standard_action==hard_standard_action){

current_standard_=2;

column_=30;

mine_number_=99;

}elseif(standard_action==custom_standard_action){

QDialogdialog;

(tr("

setstandard"

QSpinBox*row_spinBox=newQSpinBox;

row_spinBox->

setRange(5,50);

setValue(row_);

QSpinBox*column_spinBox=newQSpinBox;

column_spinBox->

setValue(column_);

QSpinBox*mine_spinBox=newQSpinBox;

mine_spinBox->

setValue(mine_number_);

QHBoxLayout*up_layout=newQHBoxLayout;

up_layout->

addWidget(row_spinBox);

addWidget(column_spinBox);

addWidget(mine_spinBox);

QDialogButtonBox*dialog_buttonBox=newQDialogButtonBox;

dialog_buttonBox->

addButton(QDialogButtonBox:

Ok);

Cancel);

connect(dialog_buttonBox,SIGNAL(accepted()),&

connect(dialog_buttonBox,SIGNAL(rejected()),&

QHBoxLayout*bottom_layout=newQHBoxLayout;

bottom_layout->

addWidget(dialog_buttonBox);

QVBoxLayout*main_layout=newQVBoxLayout(&

main_layout->

if()==QDialog:

Accepted)

if(row_spinBox->

value()*column_spinBox->

value()>

mine_spinBox->

value()){

current_standard_=3;

row_=row_spinBox->

value();

column_=column_spinBox->

mine_number_=mine_spinBox->

slot_new_game();

/*实现帮助菜单中的关于游戏,及功能*/

slot_about_game()

QStringintroduction(

"

<

h2>

+tr("

AboutMineSweepr"

)+"

/h2>

+"

p>

Thisgameisplayedbyrevealingsquaresofthegrid,typicallybyclickingthemwithamouse.Ifasquarecontainingamineisrevealed,theplayerlosesthegame.Otherwise,adigitisrevealedinthesquare,indicatingthenumberofadjacentsquares(outofthepossibleeight)thatcontainthisnumberiszerothenthesquareappearsblank,andthesurroundingsquaresareautomaticallyalsorevealed.Byusinglogic,theplayercaninmanyinstancesusethisinformationtodeducethatcertainothersquaresaremine-free,inwhichcasetheymaybesafelyrevealed,ormine-filled,inwhichtheycanbemarkedassuch(whichiseffectedbyright-clickingthesquareandindicatedbyaflaggraphic)."

/p>

Thisprogramisfreesoftware;

youcanredistributeitand/orunderthetermsoftheGNUGeneralPublicLicenseaspublishedbytheSoftwareFoundation;

eitherversion3oftheLicense,or(atyouroption)anylaterversion."

Pleasesee"

ahref="

foranoverviewofGPLv3licensing"

br>

Version:

)+g_software_version+"

/br>

Author:

"

)+g_software_author+"

);

QMessageBoxmessageBox(QMessageBox:

Information,tr("

AboutMineSweeper"

),introduction,QMessageBox:

();

/*游戏的判断,及所给出的提示做出判断*/

slot_game_over(boolis_win)

QStringname;

if(is_win){

switch(current_standard_){

case0:

if(time_label->

text().toInt()<

easy_record_time_){

name=QInputDialog:

getText(this,tr("

Pleaseenteryourname"

),tr("

Youcreatearecord.Pleaseenteryourname"

if(!

()){

easy_record_time_=time_label->

text().toInt();

easy_record_name_=name;

}

}else

QMessageBox:

information(this,tr("

Result"

Youwin"

break;

case1:

middle_record_time_){

middle_record_time_=time_label->

middle_record_name_=name;

case2:

hard_record_time_){

hard_record_time_=time_label->

hard_record_name_=name;

default:

QMessageBox:

}else{

QMessageBox:

Youlose"

/*定时器的设置*/

slot_timer()

time_label->

setText(QString("

).arg()/1000));

/*关于菜单栏的设置是否显示游戏工具栏和状态栏*/

read_settings()

QSettingssettings;

("

MainWindow"

);

resize("

size"

).toSize());

move("

pos"

).toPoint());

boolshow_game_toolBar=("

showGameToolBar"

).toBool();

show_game_toolBar_action->

setChecked(show_game_toolBar);

slot_show_game_toolBar(show_game_toolBar);

boolshow_statusBar=("

showStatusBar"

show_statusBar_action->

setChecked(show_statusBar);

slot_show_statusBar(show_statusBar);

GameSetting"

current_standard_=("

current_standard"

).toInt();

switch(current_standard_){

case0:

easy_standard_action->

setChecked(true);

break;

case1:

middle_standard_action->

case2:

hard_standard_action->

case3:

custom_standard_action->

default:

;

row_=("

row"

).toInt()==09:

("

column_=("

column"

mine_number_=("

mine_number"

).toInt()==010:

Rank"

easy_record_time_=("

easy_record_time"

).toInt()==0g_no_record_time:

middle_record_time_=("

middle_record_time"

).toInt()==0g_n

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

当前位置:首页 > 高中教育 > 高中教育

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

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