1、QWidgetBlock:Block(bool mine_flag,QWidget* parent) :QLabel(parent) mine_flag_=mine_flag; mark_flag_=false; turn_over_flag_=false; number_=-1; setPixmap(QPixmap(/images/);void Block:set_number(int number) number_=number;turn_over() if(!turn_over_flag_) turn_over_flag_=true; if(mine_flag_) setPixmap(Q
2、Pixmap( else/images/mine_+QString(%1).arg(number_)+.png update(); bool Block:is_mine()const return mine_flag_;is_turn_over()const return turn_over_flag_;/*鼠标事件的实现*/mousePressEvent(QMouseEvent* event) if(event-button()=Qt:LeftButton) if(!turn_over_flag_&!mark_flag_) turn_over_flag_=true; if(mine_flag
3、_=true) setPixmap(QPixmap( update(); emit turn_over(true); else emit turn_over(false); else if(event-RightButton) if(! mark_flag_=true; mark_flag_=false; update(); QLabel:mousePressEvent(event);#ifndef BLOCK_AREA_H_#define BLOCK_AREA_H_class QEvent;class QGridLayout;class QObject;class BlockArea:pub
4、lic QWidget BlockArea(int row,int column,int mine_number,QWidget* parent=0); void set_block_area(int row,int column,int mine_number,int init_flag=false); void game_over(bool is_win); bool eventFilter(QObject* watched, QEvent* event);private slots: void slot_turn_over(bool is_mine); int calculate_min
5、es(int x,int y)const; rg(easy_record_time_),1,1); up_layout-addWidget(new QLabel(easy_record_name_),1,2);addWidget(new QLabel(tr(Middle),2,0);addWidget(new QLabel(QString().arg(middle_record_time_),2,1);addWidget(new QLabel(middle_record_name_),2,2);Hard),3,0);).arg(hard_record_time_),3,1);addWidget
6、(new QLabel(hard_record_name_),3,2); QPushButton* recount_button=new QPushButton(tr(recount QPushButton* close_button=new QPushButton(tr(close close_button-setDefault(true); connect(recount_button,SIGNAL(clicked(),&dialog,SLOT(accept(); connect(close_button,SIGNAL(clicked(),&dialog,SLOT(reject(); QH
7、BoxLayout* bottom_layout=new QHBoxLayout; bottom_layout-addStretch();addWidget(recount_button);addWidget(close_button); QVBoxLayout* main_layout=new QVBoxLayout(&dialog); main_layout-addLayout(up_layout);addLayout(bottom_layout); if()=QDialog:Accepted) easy_record_time_=middle_record_time_=hard_reco
8、rd_time_=g_no_record_time; easy_record_name_=middle_record_name_=hard_record_name_=g_no_record_name;void MainWindow:slot_show_game_toolBar(bool show) if(show) game_toolBar-show(); elsehide();slot_show_statusBar(bool show) statusBar()-/*游戏的设置容易、中等、困难及自定义*/slot_standard(QAction* standard_action) if(st
9、andard_action=easy_standard_action) current_standard_=0; row_=9; column_=9; mine_number_=10; else if(standard_action=middle_standard_action) current_standard_=1; row_=16; column_=16; mine_number_=40; else if(standard_action=hard_standard_action) current_standard_=2; column_=30; mine_number_=99; else
10、 if(standard_action=custom_standard_action) QDialog dialog; (tr(set standard QSpinBox* row_spinBox=new QSpinBox; row_spinBox-setRange(5,50);setValue(row_); QSpinBox* column_spinBox=new QSpinBox; column_spinBox-setValue(column_); QSpinBox* mine_spinBox=new QSpinBox; mine_spinBox-setValue(mine_number_
11、); QHBoxLayout* up_layout=new QHBoxLayout; up_layout-addWidget(row_spinBox);addWidget(column_spinBox);addWidget(mine_spinBox); QDialogButtonBox* dialog_buttonBox=new QDialogButtonBox; dialog_buttonBox-addButton(QDialogButtonBox:Ok);Cancel); connect(dialog_buttonBox,SIGNAL(accepted(),& connect(dialog
12、_buttonBox,SIGNAL(rejected(),& QHBoxLayout* bottom_layout=new QHBoxLayout; bottom_layout-addWidget(dialog_buttonBox); QVBoxLayout* main_layout=new QVBoxLayout(& main_layout- if()=QDialog:Accepted) if(row_spinBox-value()*column_spinBox-value()mine_spinBox-value() current_standard_=3; row_=row_spinBox
13、-value(); column_=column_spinBox- mine_number_=mine_spinBox- slot_new_game();/*实现帮助菜单中的关于游戏,及功能*/slot_about_game() QString introduction( +tr(About Mine Sweepr)+/h2 +pThis game is played by revealing squares of the grid, typically by clicking them with a mouse. If a square containing a mine is reveal
14、ed, the player loses the game. Otherwise, a digit is revealed in the square, indicating the number of adjacent squares (out of the possible eight) that contain this number is zero then the square appears blank, and the surrounding squares are automatically also revealed. By using logic, the player c
15、an in many instances use this information to deduce that certain other squares are mine-free, in which case they may be safely revealed, or mine-filled, in which they can be marked as such (which is effected by right-clicking the square and indicated by a flag graphic)./pThis program is free softwar
16、e; you can redistribute it and/or under the terms of the GNU General Public License as published by the Software Foundation; either version 3 of the License, or (at your option) any later version.Please see a href= for an overview of GPLv3 licensingbrVersion:)+g_software_version+/brAuthor: )+g_softw
17、are_author+ ); QMessageBox messageBox(QMessageBox:Information,tr(About Mine Sweeper),introduction,QMessageBox: ();/*游戏的判断,及所给出的提示做出判断*/slot_game_over(bool is_win) QString name; if(is_win) switch(current_standard_) case 0: if(time_label-text().toInt()text().toInt(); easy_record_name_=name; else QMess
18、ageBox:information(this,tr(ResultYou win break; case 1:middle_record_time_) middle_record_time_=time_label- middle_record_name_=name; case 2:hard_record_time_) hard_record_time_=time_label- hard_record_name_=name; default:QMessageBox: else QMessageBox:You lose/*定时器的设置*/slot_timer() time_label-setTex
19、t(QString().arg()/1000);/*关于菜单栏的设置是否显示游戏工具栏和状态栏*/read_settings() QSettings settings; (MainWindow); resize(size).toSize(); move(pos).toPoint(); bool show_game_toolBar=(showGameToolBar).toBool(); show_game_toolBar_action-setChecked(show_game_toolBar); slot_show_game_toolBar(show_game_toolBar); bool sh
20、ow_statusBar=(showStatusBar show_statusBar_action-setChecked(show_statusBar); slot_show_statusBar(show_statusBar);GameSetting current_standard_=(current_standard).toInt(); switch(current_standard_) case 0:easy_standard_action-setChecked(true);break; case 1:middle_standard_action- case 2:hard_standard_action- case 3: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