Skip to content

Commit

Permalink
chroe: Clean up the code after the function is completed
Browse files Browse the repository at this point in the history
  • Loading branch information
XMuli committed Dec 14, 2023
1 parent 87de5d9 commit e6d9b5a
Show file tree
Hide file tree
Showing 16 changed files with 98 additions and 103 deletions.
6 changes: 3 additions & 3 deletions AboutAuthor.cpp
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]
*
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion AboutAuthor.h
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]
*
Expand Down
5 changes: 2 additions & 3 deletions ChessBoard.cpp
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]
*
Expand All @@ -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),
Expand Down
104 changes: 51 additions & 53 deletions ChessBoard.h
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]
*
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand All @@ -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
2 changes: 1 addition & 1 deletion ChessPieces.cpp
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]
*
Expand Down
16 changes: 8 additions & 8 deletions ChessPieces.h
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]
*
Expand Down Expand Up @@ -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"};
Expand Down
2 changes: 1 addition & 1 deletion ChessStep.cpp
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]
*
Expand Down
14 changes: 7 additions & 7 deletions ChessStep.h
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]
*
Expand Down Expand Up @@ -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
12 changes: 6 additions & 6 deletions ChessVoice.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ class ChessVoice : public QObject
QSound *m_back =new QSound(":/sound/backChess.wav",this);
QSound *m_general =new QSound(":/sound/generalSound.wav",this);

void voiceWin(); //胜利音效
void voiceSelect(); //选棋音效
void voiceMove(); //移动音效
void voiceEat(); //吃子音效
void voiceBack(); //悔棋音效
void voiceGeneral();//将军音效
void voiceWin(); // 胜利音效
void voiceSelect(); // 选棋音效
void voiceMove(); // 移动音效
void voiceEat(); // 吃子音效
void voiceBack(); // 悔棋音效
void voiceGeneral(); // 将军音效

};

Expand Down
4 changes: 2 additions & 2 deletions ChooseMainWindow.cpp
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]
*
Expand Down Expand Up @@ -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
);

Expand Down
2 changes: 1 addition & 1 deletion ChooseMainWindow.h
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]
*
Expand Down
2 changes: 1 addition & 1 deletion MachineGame.cpp
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]
*
Expand Down
24 changes: 11 additions & 13 deletions MachineGame.h
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]
*
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion NetworkGame.cpp
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]
*
Expand Down
2 changes: 1 addition & 1 deletion NetworkGame.h
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]
*
Expand Down
2 changes: 1 addition & 1 deletion main.cpp
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]
*
Expand Down

0 comments on commit e6d9b5a

Please sign in to comment.