作者:清潇静凌 | 来源:互联网 | 2023-10-11 20:08
C++实战–QT实现扫雷 效果 mainwindow.h #ifndef MAINWINDOW_H #define MAINWINDOW_H #include #include QT_BEGIN_NAMESPACEnamespace Ui { class MainWindow ; } QT_END_NAMESPACEclass MainWindow : public QMainWindow{ Q_OBJECTpublic : MainWindow ( QWidget * parent = nullptr ) ; ~ MainWindow ( ) ; Cmine* cmine; private : Ui:: MainWindow * ui; int difficulty; private slots: void slot_lost ( ) ; void slot_count ( ) ; void on_pushButton_clicked ( ) ; void on_pushButton_2_clicked ( ) ; } ; #endif
#ifndef CMINE_H #define CMINE_H #include #include #include class Cmine : public QWidget{ Q_OBJECTpublic : explicit Cmine ( QWidget * parent = nullptr , int row= 9 , int col= 9 , int num_mine= 10 , int d= 20 ) ; QVector< QVector< char >> board; QVector< QVector< char >> _board; int row; int col; int mousemove_row; int mousemove_col; int d; int count; double offset= 0.5 ; int num_mine; bool draw_mousemove; bool gameover; QPainter* painter; void calculateMineAround ( ) ; void paintEvent ( QPaintEvent * event) override; void mouseMoveEvent ( QMouseEvent * event) override; void mousePressEvent ( QMouseEvent * event) override; void draw_Board ( ) ; void draw_None ( int , int ) ; void draw_Ques ( int , int ) ; void draw_Flag ( int , int ) ; void draw_Open ( int , int ) ; void draw_Mousemove ( int , int ) ; QImage getTransparentImage ( QImage image, QPoint point) ; signals: void sig_lost ( ) ; void sig_count ( ) ; } ; #endif