-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chroe: Clean up the code after the function is completed
- Loading branch information
Showing
16 changed files
with
98 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2019~2020 偕臧 All rights reserved. | ||
* Copyright (C) 2019~2024 偕臧 All rights reserved. | ||
* | ||
* Author: xmuli(偕臧) [email protected] | ||
* | ||
|
@@ -26,8 +26,8 @@ | |
#include <QPalette> | ||
|
||
AboutAuthor::AboutAuthor(QWidget *parent) : | ||
ui(new Ui::AboutAuthor), | ||
QDialog(parent) | ||
QDialog(parent), | ||
ui(new Ui::AboutAuthor) | ||
{ | ||
this->setWindowIcon(QIcon(":/images/chess.svg")); | ||
ui->setupUi(this); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2019~2020 偕臧 All rights reserved. | ||
* Copyright (C) 2019~2024 偕臧 All rights reserved. | ||
* | ||
* Author: xmuli(偕臧) [email protected] | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2019~2020 偕臧 All rights reserved. | ||
* Copyright (C) 2019~2024 偕臧 All rights reserved. | ||
* | ||
* Author: xmuli(偕臧) [email protected] | ||
* | ||
|
@@ -20,9 +20,8 @@ | |
* along with this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.html>. | ||
*/ | ||
#include "ChessBoard.h" | ||
|
||
#include <mutex> | ||
#include "ui_ChessBoard.h" | ||
#include <mutex> | ||
|
||
ChessBoard::ChessBoard(QWidget *parent) : | ||
QMainWindow(parent), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2019~2020 偕臧 All rights reserved. | ||
* Copyright (C) 2019~2024 偕臧 All rights reserved. | ||
* | ||
* Author: xmuli(偕臧) [email protected] | ||
* | ||
|
@@ -75,38 +75,38 @@ class ChessBoard : public QMainWindow | |
|
||
bool isRed(int id); | ||
bool isDead(int id); | ||
void killStone(int id); //吃子 | ||
void reliveStone(int id); //死者苏生 | ||
void moveStone(int moveid, int row, int col); //移动棋子 | ||
bool sameColor(int moveId, int killId); //棋子是否同色 | ||
void killStone(int id); // 吃子 | ||
void reliveStone(int id); // 死者苏生 | ||
void moveStone(int moveid, int row, int col); // 移动棋子 | ||
bool sameColor(int moveId, int killId); // 棋子是否同色 | ||
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为输出参数 | ||
int relation(int row1, int col1, int row2, int col2); //计算选中的棋子的位置和要移动的位置之间的位置关系 | ||
QPoint getRealPoint(QPoint pt); // 使mouseMoveEvent取得的坐标同Painter的坐标一致 | ||
bool isGeneral(); //校验将移动后位置是否将死 | ||
void whoWin(); // 谁胜谁负 | ||
bool isChecked(QPoint pt, int& row, int& col); // 是否选中该枚棋子。pt为输入参数; row, col为输出参数 | ||
int relation(int row1, int col1, int row2, int col2); // 计算选中的棋子的位置和要移动的位置之间的位置关系 | ||
QPoint getRealPoint(QPoint pt); // 使mouseMoveEvent取得的坐标同Painter的坐标一致 | ||
bool isGeneral(); // 校验将移动后位置是否将死 | ||
void showNetworkGui(const bool& show = false); | ||
|
||
private: | ||
bool hongMenFeast(); // 鸿门宴:对将 | ||
bool havePieces(int row, int col); // 判断某一格子,是否有棋子 | ||
void reset(); // 胜负已分,重置 | ||
bool hongMenFeast(); // 鸿门宴:对将 | ||
bool havePieces(int row, int col); // 判断某一格子,是否有棋子 | ||
void reset(); // 胜负已分,重置 | ||
void winMessageBox(QString title, QString msg); | ||
|
||
public: | ||
//视图相关 | ||
QPoint center(int row, int col); //象棋的棋盘的坐标转换成界面坐标 | ||
QPoint center(int row, int col); // 象棋的棋盘的坐标转换成界面坐标 | ||
QPoint center(int id); | ||
virtual void paintEvent(QPaintEvent *); //绘画棋盘 | ||
void drawChessPieces(QPainter& painter, int id); //绘画单个具体的棋子 | ||
void drawLastStep(QPainter &painter, QVector<ChessStep*>& steps); //绘制上次移动棋子的起止位置 | ||
void drawTextStep(); //绘制文本棋谱 | ||
// virtual void mousePressEvent(QMouseEvent *); //鼠标点击事件 | ||
virtual void paintEvent(QPaintEvent *); // 绘画棋盘 | ||
void drawChessPieces(QPainter& painter, int id); // 绘画单个具体的棋子 | ||
void drawLastStep(QPainter &painter, QVector<ChessStep*>& steps); // 绘制上次移动棋子的起止位置 | ||
void drawTextStep(); // 绘制文本棋谱 | ||
// 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); | ||
|
@@ -115,38 +115,39 @@ class ChessBoard : public QMainWindow | |
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); | ||
bool canSelect(int id); //是否允许红方或黑方选棋 | ||
|
||
bool canSelect(int id); | ||
void init(); | ||
|
||
//移动相关 | ||
virtual void mouseReleaseEvent(QMouseEvent *ev); // 鼠标释放事件 | ||
void click(QPoint pt); //点击转换像素 | ||
virtual void clickPieces(int id, int& row, int& col); //点击选棋 | ||
void trySelectStone(int id); //尝试选棋 | ||
void tryMoveStone(int killid, int row, int col); //尝试移动 | ||
void doMoveStone(int moveid, int killid, int row, int col); //执行移动棋子 | ||
void saveStep(int moveid, int killid, int row, int col, QVector<ChessStep*>& steps); //保存步数 | ||
QString textStep(int moveid, int row, int col); //文本棋谱 | ||
|
||
void backOne(); //悔棋一子 | ||
void back(ChessStep* step); //悔棋到指定步数 | ||
virtual void back(); //悔棋 | ||
|
||
ChessPieces m_ChessPieces[32]; //所有棋子 | ||
QVector<ChessStep*> m_ChessSteps; // 悔棋步数 | ||
ChessVoice m_Chessvoice; //下棋音效 | ||
int m_nR; //棋子半径 | ||
int m_nOffSet; //距离界面的边距 | ||
int m_nD; //间距为50px | ||
int m_nSelectID; //选中棋子[-1:选棋子 || 非-1:走棋子] | ||
int m_nCheckedID; //将要被击杀的棋子ID | ||
bool m_bIsRed; //是否是红方回合 | ||
virtual void mouseReleaseEvent(QMouseEvent *ev); // 鼠标释放事件 | ||
void click(QPoint pt); // 点击转换像素 | ||
virtual void clickPieces(int id, int& row, int& col); // 点击选棋 | ||
void trySelectStone(int id); // 尝试选棋 | ||
void tryMoveStone(int killid, int row, int col); // 尝试移动 | ||
void doMoveStone(int moveid, int killid, int row, int col); // 执行移动棋子 | ||
void saveStep(int moveid, int killid, int row, int col, QVector<ChessStep*>& steps); // 保存步数 | ||
QString textStep(int moveid, int row, int col); // 文本棋谱 | ||
|
||
void backOne(); // 悔棋一子 | ||
void back(ChessStep* step); // 悔棋到指定步数 | ||
virtual void back(); // 悔棋 | ||
|
||
ChessPieces m_ChessPieces[32]; // 所有棋子 | ||
QVector<ChessStep*> m_ChessSteps; // 悔棋步数 | ||
ChessVoice m_Chessvoice; // 下棋音效 | ||
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; //是否已经游戏结束 | ||
bool m_bIsShowStep; //是否显示步数 | ||
QString textStepRecord; //文本棋谱字符串 | ||
bool m_bIsOver; // 是否已经游戏结束 | ||
bool m_bIsShowStep; // 是否显示步数 | ||
QString textStepRecord; // 文本棋谱字符串 | ||
|
||
signals: | ||
void toMenu(); | ||
|
||
private slots: | ||
void updateTime(); | ||
|
@@ -162,13 +163,10 @@ private slots: | |
Ui::ChessBoard *ui; | ||
|
||
private: | ||
QTimer * m_timer; //定时器 每秒更新时间 | ||
QTime * m_timeRecord; //记录时间 | ||
bool m_bIsStart; //记录是否已经开始计时 | ||
QTimer* m_timer; // 定时器 每秒更新时间 | ||
QTime* m_timeRecord; // 记录时间 | ||
bool m_bIsStart; // 记录是否已经开始计时 | ||
AboutAuthor* m_pAbout; | ||
|
||
signals: | ||
void toMenu(); | ||
}; | ||
|
||
#endif // CHESSBOARD_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2019~2020 偕臧 All rights reserved. | ||
* Copyright (C) 2019~2024 偕臧 All rights reserved. | ||
* | ||
* Author: xmuli(偕臧) [email protected] | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2019~2020 偕臧 All rights reserved. | ||
* Copyright (C) 2019~2024 偕臧 All rights reserved. | ||
* | ||
* Author: xmuli(偕臧) [email protected] | ||
* | ||
|
@@ -30,20 +30,20 @@ class ChessPieces | |
ChessPieces(); | ||
~ChessPieces(); | ||
|
||
void init(int id); //初始化 | ||
void init(int id); //初始化 | ||
QString getnName(bool isRedSide); //棋子对应的汉字 | ||
QString getColText(int col); | ||
QString getRowText(int rowTo); | ||
QString getMoveText(int rowFrom, int rowTo); | ||
|
||
enum m_emTYPE{JIANG, SHI, XIANG, MA, CHE, PAO, BING}; | ||
|
||
int m_nRow; //行 | ||
int m_nCol; //列 | ||
int m_nID; //ID号 | ||
bool m_bDead; //死亡状态 | ||
bool m_bRed; //是否是红方 | ||
m_emTYPE m_emType; //具体哪一个棋子 | ||
int m_nRow; // 行 | ||
int m_nCol; // 列 | ||
int m_nID; // ID号 | ||
bool m_bDead; // 死亡状态 | ||
bool m_bRed; // 是否是红方 | ||
m_emTYPE m_emType; // 具体哪一个棋子 | ||
|
||
QString colTextRed[9]={"九", "八", "七", "六", "五", "四", "三", "二", "一"}; | ||
QString colTextBlack[9]={"1", "2", "3", "4", "5", "6", "7", "8", "9"}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2019~2020 偕臧 All rights reserved. | ||
* Copyright (C) 2019~2024 偕臧 All rights reserved. | ||
* | ||
* Author: xmuli(偕臧) [email protected] | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2019~2020 偕臧 All rights reserved. | ||
* Copyright (C) 2019~2024 偕臧 All rights reserved. | ||
* | ||
* Author: xmuli(偕臧) [email protected] | ||
* | ||
|
@@ -31,12 +31,12 @@ class ChessStep : public QObject | |
explicit ChessStep(QObject *parent = 0); | ||
~ChessStep(); | ||
|
||
int m_nMoveID; //移动棋子ID | ||
int m_nKillID; //将要被击杀的棋子ID | ||
int m_nRowFrom; //原位置的行 | ||
int m_nColFrom; //原位置的列 | ||
int m_nRowTo; //目的位置的行 | ||
int m_nnColTo; //目的位置的列 | ||
int m_nMoveID; // 移动棋子ID | ||
int m_nKillID; // 将要被击杀的棋子ID | ||
int m_nRowFrom; // 原位置的行 | ||
int m_nColFrom; // 原位置的列 | ||
int m_nRowTo; // 目的位置的行 | ||
int m_nnColTo; // 目的位置的列 | ||
}; | ||
|
||
#endif // CHESSSTEP_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2019~2020 偕臧 All rights reserved. | ||
* Copyright (C) 2019~2024 偕臧 All rights reserved. | ||
* | ||
* Author: xmuli(偕臧) [email protected] | ||
* | ||
|
@@ -81,7 +81,7 @@ ChooseMainWindow::ChooseMainWindow(QWidget *parent) : QDialog(parent) | |
"是否作为[服务器]启动?<br>" | ||
"- Yes: 服务器, 属红方<br>" | ||
"- No: 客户端, 属黑方<br><br>" | ||
"<a href=\"https://github.com/XMuli/ChineseChess/wiki/%E7%BD%91%E7%BB%9C%E5%AF%B9%E6%88%98%E6%A8%A1%E5%BC%8F%E8%AE%BE%E7%BD%AE\">📢: 📖Wiki</a>", | ||
"<a href=\"https://github.com/XMuli/ChineseChess/wiki/%E7%BD%91%E7%BB%9C%E5%AF%B9%E6%88%98%E6%A8%A1%E5%BC%8F%E8%AE%BE%E7%BD%AE\">📢: 📖 Wiki</a>", | ||
QMessageBox::Yes | QMessageBox::No | ||
); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2019~2020 偕臧 All rights reserved. | ||
* Copyright (C) 2019~2024 偕臧 All rights reserved. | ||
* | ||
* Author: xmuli(偕臧) [email protected] | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2019~2020 偕臧 All rights reserved. | ||
* Copyright (C) 2019~2024 偕臧 All rights reserved. | ||
* | ||
* Author: xmuli(偕臧) [email protected] | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2019~2020 偕臧 All rights reserved. | ||
* Copyright (C) 2019~2024 偕臧 All rights reserved. | ||
* | ||
* Author: xmuli(偕臧) [email protected] | ||
* | ||
|
@@ -32,21 +32,19 @@ class MachineGame : public ChessBoard | |
MachineGame(); | ||
~MachineGame(); | ||
|
||
void chooseOrMovePieces(int tempID, int& row, int& col); //辅助函: 选棋或移动棋子 | ||
void chooseOrMovePieces(int tempID, int& row, int& col); // 辅助函: 选棋或移动棋子 | ||
void saveStep(int moveID, int checkedID, int row, int col, QVector<ChessStep*>& steps); // 保存棋子步骤 | ||
void getAllPossibleMoveStep(QVector<ChessStep*>& steps); // 获得所有可能的移动步骤(击杀) | ||
void getAllPossibleMoveStepAndNoKill(QVector<ChessStep*>& steps); // 获得所有可能的移动步骤(不击杀) | ||
|
||
void saveStep(int moveID, int checkedID, int row, int col, QVector<ChessStep*>& steps); //保存棋子步骤 | ||
void getAllPossibleMoveStep(QVector<ChessStep*>& steps); //获得所有可能的移动步骤(击杀) | ||
void getAllPossibleMoveStepAndNoKill(QVector<ChessStep*>& steps); //获得所有可能的移动步骤(不击杀) | ||
|
||
virtual void mousePressEvent(QMouseEvent *); //鼠标点击事件 | ||
virtual void mousePressEvent(QMouseEvent *); // 鼠标点击事件 | ||
void clickPieces(int checkedID, int& row, int& col); | ||
|
||
void fakeMove(ChessStep* step); //假装移动棋子 | ||
void unFakeMove(ChessStep* step); //撤回先前假装移动棋子的步骤 | ||
int calcScore(); //计算最好的局面分 | ||
ChessStep* getBestMove(); //获得最好的移动步骤 | ||
|
||
void machineChooseAndMovePieces(); //机器 黑方时间: 进行选棋+下棋 | ||
void fakeMove(ChessStep* step); // 假装移动棋子 | ||
void unFakeMove(ChessStep* step); // 撤回先前假装移动棋子的步骤 | ||
int calcScore(); // 计算最好的局面分 | ||
ChessStep* getBestMove(); // 获得最好的移动步骤 | ||
void machineChooseAndMovePieces(); // 机器 黑方时间: 进行选棋+下棋 | ||
}; | ||
|
||
#endif // MACHINEGAME_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2019~2020 偕臧 All rights reserved. | ||
* Copyright (C) 2019~2024 偕臧 All rights reserved. | ||
* | ||
* Author: xmuli(偕臧) [email protected] | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2019~2020 偕臧 All rights reserved. | ||
* Copyright (C) 2019~2024 偕臧 All rights reserved. | ||
* | ||
* Author: xmuli(偕臧) [email protected] | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2019~2020 偕臧 All rights reserved. | ||
* Copyright (C) 2019~2024 偕臧 All rights reserved. | ||
* | ||
* Author: xmuli(偕臧) [email protected] | ||
* | ||
|