内容发布更新时间 : 2024/9/12 22:34:08星期一 下面是文章的全部内容请认真阅读。
void MainWindow::slot_rank() { QDialog dialog; dialog.setWindowTitle(tr(\)); QGridLayout* up_layout=new QGridLayout; up_layout->addWidget(new QLabel(tr(\)),0,0); up_layout->addWidget(new QLabel(tr(\)),0,1); up_layout->addWidget(new QLabel(tr(\)),0,2); up_layout->addWidget(new QLabel(tr(\)),1,0); up_layout->addWidget(new
QLabel(QString(\).arg(easy_record_time_)),1,1); up_layout->addWidget(new QLabel(easy_record_name_),1,2); up_layout->addWidget(new QLabel(tr(\)),2,0); up_layout->addWidget(new
QLabel(QString(\).arg(middle_record_time_)),2,1); up_layout->addWidget(new QLabel(middle_record_name_),2,2); up_layout->addWidget(new QLabel(tr(\)),3,0); up_layout->addWidget(new
QLabel(QString(\).arg(hard_record_time_)),3,1); up_layout->addWidget(new QLabel(hard_record_name_),3,2); QPushButton* recount_button=new QPushButton(tr(\)); QPushButton* close_button=new QPushButton(tr(\)); close_button->setDefault(true); connect(recount_button,SIGNAL(clicked()),&dialog,SLOT(accept())); connect(close_button,SIGNAL(clicked()),&dialog,SLOT(reject())); QHBoxLayout* bottom_layout=new QHBoxLayout; bottom_layout->addStretch(); bottom_layout->addWidget(recount_button); bottom_layout->addWidget(close_button); QVBoxLayout* main_layout=new QVBoxLayout(&dialog); main_layout->addLayout(up_layout); main_layout->addLayout(bottom_layout); if(dialog.exec()==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; } }
void MainWindow::slot_show_game_toolBar(bool show) { if(show) game_toolBar->show(); else game_toolBar->hide(); }
void MainWindow::slot_show_statusBar(bool show) { if(show) statusBar()->show(); else statusBar()->hide(); }
/*游戏的设置容易、中等、困难及自定义*/
void MainWindow::slot_standard(QAction* standard_action) { if(standard_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; row_=16; column_=30; mine_number_=99; }else if(standard_action==custom_standard_action){ QDialog dialog; dialog.setWindowTitle(tr(\ standard\)); QSpinBox* row_spinBox=new QSpinBox; row_spinBox->setRange(5,50); row_spinBox->setValue(row_);
QSpinBox* column_spinBox=new QSpinBox; column_spinBox->setRange(5,50); column_spinBox->setValue(column_); QSpinBox* mine_spinBox=new QSpinBox; mine_spinBox->setValue(mine_number_); QHBoxLayout* up_layout=new QHBoxLayout; up_layout->addWidget(row_spinBox); up_layout->addWidget(column_spinBox); up_layout->addWidget(mine_spinBox); QDialogButtonBox* dialog_buttonBox=new QDialogButtonBox; dialog_buttonBox->addButton(QDialogButtonBox::Ok); dialog_buttonBox->addButton(QDialogButtonBox::Cancel); connect(dialog_buttonBox,SIGNAL(accepted()),&dialog,SLOT(accept())); connect(dialog_buttonBox,SIGNAL(rejected()),&dialog,SLOT(reject())); QHBoxLayout* bottom_layout=new QHBoxLayout; bottom_layout->addStretch(); bottom_layout->addWidget(dialog_buttonBox); QVBoxLayout* main_layout=new QVBoxLayout(&dialog); main_layout->addLayout(up_layout); main_layout->addLayout(bottom_layout); if(dialog.exec()==QDialog::Accepted) if(row_spinBox->value()*column_spinBox->value()>mine_spinBox->value()){ current_standard_=3; row_=row_spinBox->value(); column_=column_spinBox->value(); mine_number_=mine_spinBox->value(); } } slot_new_game(); }
/*实现帮助菜单中的关于游戏,及功能*/ void MainWindow::slot_about_game()
{ QString introduction( \+tr(\ Mine Sweepr\)+\ +\+tr(\ game is played by revealing squares of the grid, typically by clicking them with a mouse. If a square containing a mine is revealed, 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 mines.if this number is zero then the square appears blank, and the surrounding squares are automatically also revealed. By using logic, the player can 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).\)+\ +\+tr(\ program is free software; you can redistribute it and/or modify.it 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.\)+\ +\+tr(\ see \)+\
href=http://www.gnu.org/licenses/gpl-3.0.html>http://www.gnu.org/licenses/gpl-3.0.html\+tr(\ for an overview of GPLv3 licensing\)+\ +\+tr(\)+g_software_version+\ +\+tr(\ \)+g_software_author+\ ); QMessageBox messageBox(QMessageBox::Information,tr(\ Mine Sweeper\),introduction,QMessageBox::Ok); messageBox.exec(); }
/*游戏的判断,及所给出的提示做出判断*/
void MainWindow::slot_game_over(bool is_win) { timer.stop(); QString name; if(is_win){ switch(current_standard_){ case 0: if(time_label->text().toInt()
easy_record_name_=name; } }else QMessageBox::information(this,tr(\),tr(\ win\)); break; case 1: if(time_label->text().toInt()