forked from XMuli/ChineseChess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChessBoard.h
executable file
·131 lines (115 loc) · 4.71 KB
/
ChessBoard.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* Copyright (C) 2019~2020 偕臧 All rights reserved.
*
* Author: xmuli(偕臧) [email protected]
*
* github: https://github.com/xmuli
* blogs: https://xmuli.tech
*
* This 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 Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://touwoyimuli.github.io/>.
*/
#ifndef CHESSBOARD_H
#define CHESSBOARD_H
/***
* ┌─┐ ┌─┐ + +
* ┌──┘ ┴───────┘ ┴──┐++
* │ │
* │ ─── │++ + + +
* ███████───███████ │+
* │ │+
* │ ─┴─ │
* │ │
* └───┐ ┌───┘
* │ │
* │ │ + +
* │ │
* │ └──────────────┐
* │ │
* │ ├─┐
* │ ┌─┘
* │ │
* └─┐ ┐ ┌───────┬──┐ ┌──┘ + + + +
* │ ─┤ ─┤ │ ─┤ ─┤
* └──┴──┘ └──┴──┘ + + + +
* 神兽保佑
* 代码无BUG!
*/
#include <QMainWindow>
#include <QFrame>
#include "ChessPieces.h"
#include <QPainter>
#include <QPoint>
#include <QMouseEvent>
#include <QTimer>
#include <QTime>
#include <QMessageBox>
#include <QtGlobal>
#include "AboutAuthor.h"
namespace Ui {
class ChessBoard;
}
class ChessBoard : public QMainWindow
{
Q_OBJECT
public:
explicit ChessBoard(QWidget *parent = 0);
~ChessBoard();
bool isDead(int id);
int getStoneId(int row, int col);
// 车、炮的功能辅助函数 判断两个点是否在一个直线上面,且返回直线之间的棋子个数
int getStoneCountAtLine(int row1, int col1, int row2, int col2);
void whoWin(); //谁胜谁负
bool isChecked(QPoint pt, int& row, int& col); //是否选中该枚棋子。pt为输入参数; row, col为输出参数
QPoint getRealPoint(QPoint pt); // 使mouseMoveEvent取得的坐标同Painter的坐标一致
//virtual void whoPlay(int slelsctID); //判断是谁正在 选择棋子
public:
QPoint center(int row, int col); //象棋的棋盘的坐标转换成界面坐标
QPoint center(int id);
virtual void paintEvent(QPaintEvent *); //绘画棋盘
void drawChessPieces(QPainter& painter, int id); //绘画单个具体的棋子
virtual void mousePressEvent(QMouseEvent *); //鼠标点击事件
virtual void clickPieces(int checkedID, int& row, int& col);
//象棋移动的规则[将 士 象 马 车 炮 兵]
bool canMove(int moveId, int killId, int row, int col);
bool canMoveJIANG(int moveId, int killId, int row, int col);
bool canMoveSHI(int moveId, int killId, int row, int col);
bool canMoveXIANG(int moveId, int killId, int row, int col);
bool canMoveMA(int moveId, int killId, int row, int col);
bool canMoveCHE(int moveId, int killId, int row, int col);
bool canMovePAO(int moveId, int killId, int row, int col);
bool canMoveBING(int moveId, int killId, int row, int col);
void init();
ChessPieces m_ChessPieces[32]; //所有棋子
int m_nR; //棋子半径
int m_nOffSet; //距离界面的边距
int m_nD; //间距为50px
int m_nSelectID; //选中棋子[-1:选棋子 || 非-1:走棋子]
int m_nCheckedID; //将要被击杀的棋子ID
bool m_bIsRed; //是否是红棋
bool m_bIsTcpServer;
bool m_bIsOver; //是否已经游戏结束
private slots:
void updateTime();
void on_pushButton_start_clicked();
void on_pushButton_reset_clicked();
void on_pushButton_about_clicked();
void on_pushButton_restart_clicked();
private:
Ui::ChessBoard *ui;
QTimer * m_timer; //定时器 每秒更新时间
QTime * m_timeRecord; //记录时间
bool m_bIsStart; //记录是否已经开始计时
AboutAuthor* m_pAbout;
};
#endif // CHESSBOARD_H