From e6d9b5ae92d47b63315c3f4fa3dfb4b23b5d5db9 Mon Sep 17 00:00:00 2001 From: XMuli Date: Thu, 14 Dec 2023 20:37:51 +0800 Subject: [PATCH] chroe: Clean up the code after the function is completed --- AboutAuthor.cpp | 6 +-- AboutAuthor.h | 2 +- ChessBoard.cpp | 5 +-- ChessBoard.h | 104 +++++++++++++++++++++---------------------- ChessPieces.cpp | 2 +- ChessPieces.h | 16 +++---- ChessStep.cpp | 2 +- ChessStep.h | 14 +++--- ChessVoice.h | 12 ++--- ChooseMainWindow.cpp | 4 +- ChooseMainWindow.h | 2 +- MachineGame.cpp | 2 +- MachineGame.h | 24 +++++----- NetworkGame.cpp | 2 +- NetworkGame.h | 2 +- main.cpp | 2 +- 16 files changed, 98 insertions(+), 103 deletions(-) diff --git a/AboutAuthor.cpp b/AboutAuthor.cpp index ff15f13..bf94a26 100755 --- a/AboutAuthor.cpp +++ b/AboutAuthor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019~2020 偕臧 All rights reserved. + * Copyright (C) 2019~2024 偕臧 All rights reserved. * * Author: xmuli(偕臧) xmulitech@gmail.com * @@ -26,8 +26,8 @@ #include 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); diff --git a/AboutAuthor.h b/AboutAuthor.h index cc7b3e1..1336aef 100755 --- a/AboutAuthor.h +++ b/AboutAuthor.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019~2020 偕臧 All rights reserved. + * Copyright (C) 2019~2024 偕臧 All rights reserved. * * Author: xmuli(偕臧) xmulitech@gmail.com * diff --git a/ChessBoard.cpp b/ChessBoard.cpp index a943c99..4b7de51 100644 --- a/ChessBoard.cpp +++ b/ChessBoard.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019~2020 偕臧 All rights reserved. + * Copyright (C) 2019~2024 偕臧 All rights reserved. * * Author: xmuli(偕臧) xmulitech@gmail.com * @@ -20,9 +20,8 @@ * along with this program. If not, see . */ #include "ChessBoard.h" - -#include #include "ui_ChessBoard.h" +#include ChessBoard::ChessBoard(QWidget *parent) : QMainWindow(parent), diff --git a/ChessBoard.h b/ChessBoard.h index 10ccd7a..d311ba6 100644 --- a/ChessBoard.h +++ b/ChessBoard.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019~2020 偕臧 All rights reserved. + * Copyright (C) 2019~2024 偕臧 All rights reserved. * * Author: xmuli(偕臧) xmulitech@gmail.com * @@ -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& steps); //绘制上次移动棋子的起止位置 - void drawTextStep(); //绘制文本棋谱 -// virtual void mousePressEvent(QMouseEvent *); //鼠标点击事件 + virtual void paintEvent(QPaintEvent *); // 绘画棋盘 + void drawChessPieces(QPainter& painter, int id); // 绘画单个具体的棋子 + void drawLastStep(QPainter &painter, QVector& 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& steps); //保存步数 - QString textStep(int moveid, int row, int col); //文本棋谱 - - void backOne(); //悔棋一子 - void back(ChessStep* step); //悔棋到指定步数 - virtual void back(); //悔棋 - - ChessPieces m_ChessPieces[32]; //所有棋子 - QVector 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& steps); // 保存步数 + QString textStep(int moveid, int row, int col); // 文本棋谱 + + void backOne(); // 悔棋一子 + void back(ChessStep* step); // 悔棋到指定步数 + virtual void back(); // 悔棋 + + ChessPieces m_ChessPieces[32]; // 所有棋子 + QVector 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 diff --git a/ChessPieces.cpp b/ChessPieces.cpp index 4fb15e3..3d4e51f 100755 --- a/ChessPieces.cpp +++ b/ChessPieces.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019~2020 偕臧 All rights reserved. + * Copyright (C) 2019~2024 偕臧 All rights reserved. * * Author: xmuli(偕臧) xmulitech@gmail.com * diff --git a/ChessPieces.h b/ChessPieces.h index 34beb81..68a753d 100755 --- a/ChessPieces.h +++ b/ChessPieces.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019~2020 偕臧 All rights reserved. + * Copyright (C) 2019~2024 偕臧 All rights reserved. * * Author: xmuli(偕臧) xmulitech@gmail.com * @@ -30,7 +30,7 @@ class ChessPieces ChessPieces(); ~ChessPieces(); - void init(int id); //初始化 + void init(int id); //初始化 QString getnName(bool isRedSide); //棋子对应的汉字 QString getColText(int col); QString getRowText(int rowTo); @@ -38,12 +38,12 @@ class ChessPieces 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"}; diff --git a/ChessStep.cpp b/ChessStep.cpp index 566f571..8ffeccf 100755 --- a/ChessStep.cpp +++ b/ChessStep.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019~2020 偕臧 All rights reserved. + * Copyright (C) 2019~2024 偕臧 All rights reserved. * * Author: xmuli(偕臧) xmulitech@gmail.com * diff --git a/ChessStep.h b/ChessStep.h index 41235d5..5d013d6 100755 --- a/ChessStep.h +++ b/ChessStep.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019~2020 偕臧 All rights reserved. + * Copyright (C) 2019~2024 偕臧 All rights reserved. * * Author: xmuli(偕臧) xmulitech@gmail.com * @@ -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 diff --git a/ChessVoice.h b/ChessVoice.h index 4e10f45..ac820c9 100644 --- a/ChessVoice.h +++ b/ChessVoice.h @@ -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(); // 将军音效 }; diff --git a/ChooseMainWindow.cpp b/ChooseMainWindow.cpp index f8caf2b..e06988d 100755 --- a/ChooseMainWindow.cpp +++ b/ChooseMainWindow.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019~2020 偕臧 All rights reserved. + * Copyright (C) 2019~2024 偕臧 All rights reserved. * * Author: xmuli(偕臧) xmulitech@gmail.com * @@ -81,7 +81,7 @@ ChooseMainWindow::ChooseMainWindow(QWidget *parent) : QDialog(parent) "是否作为[服务器]启动?
" "- Yes: 服务器, 属红方
" "- No: 客户端, 属黑方

" - "📢: 📖Wiki", + "📢: 📖 Wiki", QMessageBox::Yes | QMessageBox::No ); diff --git a/ChooseMainWindow.h b/ChooseMainWindow.h index ebfbf9e..4a8c9ca 100755 --- a/ChooseMainWindow.h +++ b/ChooseMainWindow.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019~2020 偕臧 All rights reserved. + * Copyright (C) 2019~2024 偕臧 All rights reserved. * * Author: xmuli(偕臧) xmulitech@gmail.com * diff --git a/MachineGame.cpp b/MachineGame.cpp index cfedefa..6292ec3 100755 --- a/MachineGame.cpp +++ b/MachineGame.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019~2020 偕臧 All rights reserved. + * Copyright (C) 2019~2024 偕臧 All rights reserved. * * Author: xmuli(偕臧) xmulitech@gmail.com * diff --git a/MachineGame.h b/MachineGame.h index 8c06dcd..ebbba3f 100755 --- a/MachineGame.h +++ b/MachineGame.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019~2020 偕臧 All rights reserved. + * Copyright (C) 2019~2024 偕臧 All rights reserved. * * Author: xmuli(偕臧) xmulitech@gmail.com * @@ -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& steps); // 保存棋子步骤 + void getAllPossibleMoveStep(QVector& steps); // 获得所有可能的移动步骤(击杀) + void getAllPossibleMoveStepAndNoKill(QVector& steps); // 获得所有可能的移动步骤(不击杀) - void saveStep(int moveID, int checkedID, int row, int col, QVector& steps); //保存棋子步骤 - void getAllPossibleMoveStep(QVector& steps); //获得所有可能的移动步骤(击杀) - void getAllPossibleMoveStepAndNoKill(QVector& 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 diff --git a/NetworkGame.cpp b/NetworkGame.cpp index 52e9fdf..5b8a0db 100755 --- a/NetworkGame.cpp +++ b/NetworkGame.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019~2020 偕臧 All rights reserved. + * Copyright (C) 2019~2024 偕臧 All rights reserved. * * Author: xmuli(偕臧) xmulitech@gmail.com * diff --git a/NetworkGame.h b/NetworkGame.h index 9cfcbbe..209efd1 100755 --- a/NetworkGame.h +++ b/NetworkGame.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019~2020 偕臧 All rights reserved. + * Copyright (C) 2019~2024 偕臧 All rights reserved. * * Author: xmuli(偕臧) xmulitech@gmail.com * diff --git a/main.cpp b/main.cpp index 428fe11..0fcf101 100755 --- a/main.cpp +++ b/main.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019~2020 偕臧 All rights reserved. + * Copyright (C) 2019~2024 偕臧 All rights reserved. * * Author: xmuli(偕臧) xmulitech@gmail.com *