-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgamewidget.h
95 lines (73 loc) · 2.11 KB
/
gamewidget.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef GAMEWIDGET_H
#define GAMEWIDGET_H
#include "chessAI.h"
#include "zobrist.h"
#include <QWidget>
#include <QPainter>
#include <QMouseEvent>
#include <QMessageBox>
#include <QMap>
#include <String>
#include <QTimer>
#include <QTime>
#include <sys/time.h>
#include <QDebug>
#include <iostream>
using namespace std;
namespace Ui {
class gameWidget;
}
class gameWidget : public QWidget
{
Q_OBJECT
public:
explicit gameWidget(QWidget *parent = nullptr);
~gameWidget();
void oneChessMove(int row,int col);// 根据落子坐标更新棋局状态
bool chessOneByPlayer();
void initializeGame(); // 重新开始
bool isDeadGame();//判断是否是僵局
bool deadWindow(QMessageBox *msg);
QMessageBox msg;
void setGameMode(gameMode m){mode=m;}
bool isLegalMove(int row,int col);//判断下子位置是否合法
void exRegret();
bool reIsLegalMove(int row,int col);
private:
Ui::gameWidget *ui;
QPoint chessboard[15][15];// 记录棋盘角点坐标,方便绘制棋盘,第一个下标是列,第二个是行
chessAI ai;//棋盘放在ai当中
int cursorRow;// 获取当前光标位置,用于落子定位
int cursorCol;
int lastRow;
int lastCol;
// 记录已经下过的子的位置,便于悔棋
int usedChesses[15][15];
gameMode mode =NONE;
gameTurn turn;
gameStatus status;
bool is_in_chessboard = false; // 优化点,增加一个属性,与鼠标事件结合实时检测鼠标是否在棋盘内
int score_black;
int score_white;
int numOfChess;
QPixmap background;
protected:
void paintEvent(QPaintEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;// 检测玩家选择的实际落子
private slots:
void on_restartButton_clicked();
void on_returnButton_clicked();
void on_remindButton_clicked();
public slots:
// 返回
void returnPush();
void chessOneByAi();
// 重新开始
void initializeGame1();
// 悔棋
void regret();
signals:
void returnSignal();
};
#endif // GAMEWIDGET_H