qt: gamecontroller 改名为 Game
This commit is contained in:
parent
4538b6a6d9
commit
d424ca4e86
|
@ -43,7 +43,7 @@ SOURCES += \
|
|||
src/ui/qt/pieceitem.cpp \
|
||||
src/ui/qt/server.cpp \
|
||||
src/ui/qt/boarditem.cpp \
|
||||
src/ui/qt/gamecontroller.cpp \
|
||||
src/ui/qt/game.cpp \
|
||||
src/ui/qt/gamescene.cpp \
|
||||
src/ui/qt/gameview.cpp \
|
||||
src/ui/qt/client.cpp \
|
||||
|
@ -75,7 +75,7 @@ HEADERS += \
|
|||
src/types.h \
|
||||
src/test/test.h \
|
||||
src/ui/qt/client.h \
|
||||
src/ui/qt/gamecontroller.h \
|
||||
src/ui/qt/game.h \
|
||||
src/ui/qt/gamescene.h \
|
||||
src/ui/qt/gameview.h \
|
||||
src/ui/qt/gamewindow.h \
|
||||
|
|
|
@ -486,7 +486,14 @@
|
|||
<QtMoc Include="src\test\test.h" />
|
||||
<ClInclude Include="src\ui\qt\boarditem.h" />
|
||||
<QtMoc Include="src\ui\qt\client.h" />
|
||||
<QtMoc Include="src\ui\qt\gamecontroller.h" />
|
||||
<QtMoc Include="src\ui\qt\game.h">
|
||||
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.\GeneratedFiles\$(ConfigurationName);.\GeneratedFiles;.;$(QTDIR)\include;.\debug;\include;$(QTDIR)\mkspecs\win32-msvc;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtMultimedia;$(QTDIR)\include\QtMultimediaWidgets;$(QTDIR)\include\QtNetwork;$(QTDIR)\include\QtNetworkAuth;$(QTDIR)\include\QtWidgets</IncludePath>
|
||||
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">.\GeneratedFiles\$(ConfigurationName);.\GeneratedFiles;.;$(QTDIR)\include;.\debug;\include;$(QTDIR)\mkspecs\win32-msvc;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtMultimedia;$(QTDIR)\include\QtMultimediaWidgets;$(QTDIR)\include\QtNetwork;$(QTDIR)\include\QtNetworkAuth;$(QTDIR)\include\QtWidgets</IncludePath>
|
||||
<Define Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">QT_UI;_WINDOWS;UNICODE;_UNICODE;WIN32;WIN64;_CRT_SECURE_NO_WARNINGS;QT_CORE_LIB;QT_GUI_LIB;QT_MULTIMEDIA_LIB;QT_MULTIMEDIAWIDGETS_LIB;QT_NETWORK_LIB;QT_NETWORKAUTH_LIB;QT_WIDGETS_LIB;%(PreprocessorDefinitions)</Define>
|
||||
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ProjectDir)\src\ui\qt;$(ProjectDir)\src\ui;$(ProjectDir)\src\test;$(ProjectDir)\src;$(ProjectDir)\include;.\GeneratedFiles\$(ConfigurationName);.\GeneratedFiles;.;$(QTDIR)\include;.\release;\include;$(QTDIR)\mkspecs\win32-msvc;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtMultimedia;$(QTDIR)\include\QtMultimediaWidgets;$(QTDIR)\include\QtNetwork;$(QTDIR)\include\QtNetworkAuth;$(QTDIR)\include\QtWidgets</IncludePath>
|
||||
<Define Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">_CONSOLE;UNICODE;_UNICODE;WIN32;WIN64;QT_NO_DEBUG;NDEBUG;QT_CORE_LIB;QT_GUI_LIB;QT_MULTIMEDIA_LIB;QT_MULTIMEDIAWIDGETS_LIB;QT_NETWORK_LIB;QT_NETWORKAUTH_LIB;QT_WIDGETS_LIB;%(PreprocessorDefinitions)</Define>
|
||||
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.\GeneratedFiles\$(ConfigurationName);.\GeneratedFiles;.;$(QTDIR)\include;.\release;\include;$(QTDIR)\mkspecs\win32-msvc;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtMultimedia;$(QTDIR)\include\QtMultimediaWidgets;$(QTDIR)\include\QtNetwork;$(QTDIR)\include\QtNetworkAuth;$(QTDIR)\include\QtWidgets</IncludePath>
|
||||
</QtMoc>
|
||||
<QtMoc Include="src\ui\qt\gamescene.h" />
|
||||
<QtMoc Include="src\ui\qt\gameview.h" />
|
||||
<QtMoc Include="src\ui\qt\gamewindow.h" />
|
||||
|
@ -738,7 +745,7 @@
|
|||
<ClCompile Include="src\test\test.cpp" />
|
||||
<ClCompile Include="src\ui\qt\boarditem.cpp" />
|
||||
<ClCompile Include="src\ui\qt\client.cpp" />
|
||||
<ClCompile Include="src\ui\qt\gamecontroller.cpp" />
|
||||
<ClCompile Include="src\ui\qt\game.cpp" />
|
||||
<ClCompile Include="src\ui\qt\gamescene.cpp" />
|
||||
<ClCompile Include="src\ui\qt\gameview.cpp" />
|
||||
<ClCompile Include="src\ui\qt\gamewindow.cpp" />
|
||||
|
|
|
@ -258,9 +258,6 @@
|
|||
<QtMoc Include="src\ui\qt\client.h">
|
||||
<Filter>Qt Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="src\ui\qt\gamecontroller.h">
|
||||
<Filter>Qt Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="src\ui\qt\gamescene.h">
|
||||
<Filter>Qt Files</Filter>
|
||||
</QtMoc>
|
||||
|
@ -282,6 +279,9 @@
|
|||
<QtMoc Include="src\thread.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="src\ui\qt\game.h">
|
||||
<Filter>Qt Files</Filter>
|
||||
</QtMoc>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\test\test.cpp">
|
||||
|
@ -332,9 +332,6 @@
|
|||
<ClCompile Include="src\ui\qt\client.cpp">
|
||||
<Filter>Qt Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\ui\qt\gamecontroller.cpp">
|
||||
<Filter>Qt Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\ui\qt\gamescene.cpp">
|
||||
<Filter>Qt Files</Filter>
|
||||
</ClCompile>
|
||||
|
@ -365,6 +362,9 @@
|
|||
<ClCompile Include="src\main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\ui\qt\game.cpp">
|
||||
<Filter>Qt Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="millgame.rc">
|
||||
|
|
|
@ -18,22 +18,22 @@
|
|||
*/
|
||||
|
||||
#ifdef TRAINING_MODE
|
||||
#include "gamecontroller.h"
|
||||
#include "game.h"
|
||||
#include "trainer.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
loggerDebug("Training start...\n");
|
||||
|
||||
GameController *gameController = new GameController();
|
||||
Game *game = new Game();
|
||||
|
||||
gameController->gameReset();
|
||||
gameController->gameStart();
|
||||
game->gameReset();
|
||||
game->gameStart();
|
||||
|
||||
gameController->isAiPlayer[BLACK] = gameController->isAiPlayer[WHITE] = true;
|
||||
game->isAiPlayer[BLACK] = game->isAiPlayer[WHITE] = true;
|
||||
|
||||
gameController->setEngine(1, true);
|
||||
gameController->setEngine(2, true);
|
||||
game->setEngine(1, true);
|
||||
game->setEngine(2, true);
|
||||
|
||||
#ifdef WIN32
|
||||
system("pause");
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#include <QThread>
|
||||
#include <iomanip>
|
||||
|
||||
#include "gamecontroller.h"
|
||||
#include "game.h"
|
||||
#include "graphicsconst.h"
|
||||
#include "boarditem.h"
|
||||
#include "server.h"
|
||||
|
@ -42,7 +42,7 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
GameController::GameController(
|
||||
Game::Game(
|
||||
#ifndef TRAINING_MODE
|
||||
GameScene & scene,
|
||||
#endif
|
||||
|
@ -119,7 +119,7 @@ GameController::GameController(
|
|||
//scene.installEventFilter(this);
|
||||
}
|
||||
|
||||
GameController::~GameController()
|
||||
Game::~Game()
|
||||
{
|
||||
// 停止计时器
|
||||
if (timeID != 0)
|
||||
|
@ -138,7 +138,7 @@ GameController::~GameController()
|
|||
cmdlist.clear();
|
||||
}
|
||||
|
||||
const map<int, QStringList> GameController::getActions()
|
||||
const map<int, QStringList> Game::getActions()
|
||||
{
|
||||
// 主窗口更新菜单栏
|
||||
// 之所以不用信号和槽的模式,是因为发信号的时候槽还来不及关联
|
||||
|
@ -162,7 +162,7 @@ extern deque<int> openingBookDeque;
|
|||
extern deque<int> openingBookDequeBak;
|
||||
#endif
|
||||
|
||||
void GameController::gameStart()
|
||||
void Game::gameStart()
|
||||
{
|
||||
//cmdlist.clear();
|
||||
position.start();
|
||||
|
@ -184,7 +184,7 @@ void GameController::gameStart()
|
|||
#endif
|
||||
}
|
||||
|
||||
void GameController::gameReset()
|
||||
void Game::gameReset()
|
||||
{
|
||||
while (aiThread[BLACK]->searching || aiThread[WHITE]->searching) {
|
||||
loggerDebug(".");
|
||||
|
@ -310,14 +310,14 @@ void GameController::gameReset()
|
|||
#endif // TRAINING_MODE
|
||||
}
|
||||
|
||||
void GameController::setEditing(bool arg)
|
||||
void Game::setEditing(bool arg)
|
||||
{
|
||||
#ifndef TRAINING_MODE
|
||||
isEditing = arg;
|
||||
#endif
|
||||
}
|
||||
|
||||
void GameController::setInvert(bool arg)
|
||||
void Game::setInvert(bool arg)
|
||||
{
|
||||
#ifndef TRAINING_MODE
|
||||
isInverted = arg;
|
||||
|
@ -340,7 +340,7 @@ void GameController::setInvert(bool arg)
|
|||
#endif // TRAINING_MODE
|
||||
}
|
||||
|
||||
void GameController::setRule(int ruleNo, int stepLimited /*= -1*/, int timeLimited /*= -1*/)
|
||||
void Game::setRule(int ruleNo, int stepLimited /*= -1*/, int timeLimited /*= -1*/)
|
||||
{
|
||||
// 更新规则,原限时和限步不变
|
||||
if (ruleNo < 0 || ruleNo >= N_RULES)
|
||||
|
@ -368,7 +368,7 @@ void GameController::setRule(int ruleNo, int stepLimited /*= -1*/, int timeLimit
|
|||
gameReset();
|
||||
}
|
||||
|
||||
void GameController::setEngine(Color color, bool enabled)
|
||||
void Game::setEngine(Color color, bool enabled)
|
||||
{
|
||||
isAiPlayer[color] = enabled;
|
||||
|
||||
|
@ -381,17 +381,17 @@ void GameController::setEngine(Color color, bool enabled)
|
|||
}
|
||||
}
|
||||
|
||||
void GameController::setEngineBlack(bool enabled)
|
||||
void Game::setEngineBlack(bool enabled)
|
||||
{
|
||||
setEngine(BLACK, enabled);
|
||||
}
|
||||
|
||||
void GameController::setEngineWhite(bool enabled)
|
||||
void Game::setEngineWhite(bool enabled)
|
||||
{
|
||||
setEngine(WHITE, enabled);
|
||||
}
|
||||
|
||||
void GameController::setAiDepthTime(int time1, int time2)
|
||||
void Game::setAiDepthTime(int time1, int time2)
|
||||
{
|
||||
stopAndWaitAiThreads();
|
||||
|
||||
|
@ -401,13 +401,13 @@ void GameController::setAiDepthTime(int time1, int time2)
|
|||
startAiThreads();
|
||||
}
|
||||
|
||||
void GameController::getAiDepthTime(int &time1, int &time2)
|
||||
void Game::getAiDepthTime(int &time1, int &time2)
|
||||
{
|
||||
time1 = aiThread[BLACK]->getTimeLimit();
|
||||
time2 = aiThread[WHITE]->getTimeLimit();
|
||||
}
|
||||
|
||||
void GameController::setAnimation(bool arg)
|
||||
void Game::setAnimation(bool arg)
|
||||
{
|
||||
#ifndef TRAINING_MODE
|
||||
hasAnimation = arg;
|
||||
|
@ -420,14 +420,14 @@ void GameController::setAnimation(bool arg)
|
|||
#endif // TRAINING_MODE
|
||||
}
|
||||
|
||||
void GameController::setSound(bool arg)
|
||||
void Game::setSound(bool arg)
|
||||
{
|
||||
#ifndef TRAINING_MODE
|
||||
hasSound = arg;
|
||||
#endif // TRAINING_MODE
|
||||
}
|
||||
|
||||
void GameController::playSound(sound_t soundType, Color c)
|
||||
void Game::playSound(sound_t soundType, Color c)
|
||||
{
|
||||
string soundDir = ":/sound/resources/sound/";
|
||||
string sideStr = c == BLACK ? "B" : "W";
|
||||
|
@ -531,27 +531,27 @@ void GameController::playSound(sound_t soundType, Color c)
|
|||
#endif // TRAINING_MODE
|
||||
}
|
||||
|
||||
void GameController::setResignIfMostLose(bool enabled)
|
||||
void Game::setResignIfMostLose(bool enabled)
|
||||
{
|
||||
gameOptions.setResignIfMostLose(enabled);
|
||||
}
|
||||
|
||||
void GameController::setAutoRestart(bool enabled)
|
||||
void Game::setAutoRestart(bool enabled)
|
||||
{
|
||||
gameOptions.setAutoRestart(enabled);
|
||||
}
|
||||
|
||||
void GameController::setAutoChangeFirstMove(bool enabled)
|
||||
void Game::setAutoChangeFirstMove(bool enabled)
|
||||
{
|
||||
gameOptions.setAutoChangeFirstMove(enabled);
|
||||
}
|
||||
|
||||
void GameController::setRandomMove(bool enabled)
|
||||
void Game::setRandomMove(bool enabled)
|
||||
{
|
||||
gameOptions.setRandomMoveEnabled(enabled);
|
||||
}
|
||||
|
||||
void GameController::setLearnEndgame(bool enabled)
|
||||
void Game::setLearnEndgame(bool enabled)
|
||||
{
|
||||
gameOptions.setLearnEndgameEnabled(enabled);
|
||||
|
||||
|
@ -562,25 +562,25 @@ void GameController::setLearnEndgame(bool enabled)
|
|||
#endif
|
||||
}
|
||||
|
||||
void GameController::setIDS(bool enabled)
|
||||
void Game::setIDS(bool enabled)
|
||||
{
|
||||
gameOptions.setIDSEnabled(enabled);
|
||||
}
|
||||
|
||||
// DepthExtension
|
||||
void GameController::setDepthExtension(bool enabled)
|
||||
void Game::setDepthExtension(bool enabled)
|
||||
{
|
||||
gameOptions.setDepthExtension(enabled);
|
||||
}
|
||||
|
||||
// OpeningBook
|
||||
void GameController::setOpeningBook(bool enabled)
|
||||
void Game::setOpeningBook(bool enabled)
|
||||
{
|
||||
gameOptions.setOpeningBook(enabled);
|
||||
}
|
||||
|
||||
// 上下翻转
|
||||
void GameController::flip()
|
||||
void Game::flip()
|
||||
{
|
||||
#ifndef TRAINING_MODE
|
||||
stopAndWaitAiThreads();
|
||||
|
@ -606,7 +606,7 @@ void GameController::flip()
|
|||
}
|
||||
|
||||
// 左右镜像
|
||||
void GameController::mirror()
|
||||
void Game::mirror()
|
||||
{
|
||||
#ifndef TRAINING_MODE
|
||||
stopAndWaitAiThreads();
|
||||
|
@ -634,7 +634,7 @@ void GameController::mirror()
|
|||
}
|
||||
|
||||
// 视图须时针旋转90°
|
||||
void GameController::turnRight()
|
||||
void Game::turnRight()
|
||||
{
|
||||
#ifndef TRAINING_MODE
|
||||
stopAndWaitAiThreads();
|
||||
|
@ -660,7 +660,7 @@ void GameController::turnRight()
|
|||
}
|
||||
|
||||
// 视图逆时针旋转90°
|
||||
void GameController::turnLeft()
|
||||
void Game::turnLeft()
|
||||
{
|
||||
#ifndef TRAINING_MODE
|
||||
stopAndWaitAiThreads();
|
||||
|
@ -681,7 +681,7 @@ void GameController::turnLeft()
|
|||
#endif // TRAINING_MODE
|
||||
}
|
||||
|
||||
void GameController::updateTime()
|
||||
void Game::updateTime()
|
||||
{
|
||||
int timePoint = -1;
|
||||
time_t *ourSeconds = &elapsedSeconds[sideToMove];
|
||||
|
@ -701,7 +701,7 @@ void GameController::updateTime()
|
|||
}
|
||||
}
|
||||
|
||||
void GameController::timerEvent(QTimerEvent *event)
|
||||
void Game::timerEvent(QTimerEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
static QTime qt1, qt2;
|
||||
|
@ -772,13 +772,13 @@ void GameController::timerEvent(QTimerEvent *event)
|
|||
#endif
|
||||
}
|
||||
|
||||
bool GameController::isAIsTurn()
|
||||
bool Game::isAIsTurn()
|
||||
{
|
||||
return isAiPlayer[sideToMove];
|
||||
}
|
||||
|
||||
// 关键槽函数,根据QGraphicsScene的信号和状态来执行选子、落子或去子
|
||||
bool GameController::actionPiece(QPointF pos)
|
||||
bool Game::actionPiece(QPointF pos)
|
||||
{
|
||||
#ifndef TRAINING_MODE
|
||||
// 点击非落子点,不执行
|
||||
|
@ -943,7 +943,7 @@ bool GameController::actionPiece(QPointF pos)
|
|||
}
|
||||
|
||||
|
||||
bool GameController::resign()
|
||||
bool Game::resign()
|
||||
{
|
||||
bool result = position.resign(position.sideToMove);
|
||||
|
||||
|
@ -975,7 +975,7 @@ bool GameController::resign()
|
|||
}
|
||||
|
||||
// 关键槽函数,棋谱的命令行执行,与actionPiece独立
|
||||
bool GameController::command(const string &cmd, bool update /* = true */)
|
||||
bool Game::command(const string &cmd, bool update /* = true */)
|
||||
{
|
||||
int total;
|
||||
float bwinrate, wwinrate, drawrate;
|
||||
|
@ -1186,7 +1186,7 @@ bool GameController::command(const string &cmd, bool update /* = true */)
|
|||
}
|
||||
|
||||
// 浏览历史局面,通过command函数刷新局面显示
|
||||
bool GameController::phaseChange(int row, bool forceUpdate)
|
||||
bool Game::phaseChange(int row, bool forceUpdate)
|
||||
{
|
||||
#ifndef TRAINING_MODE
|
||||
// 如果row是当前浏览的棋谱行,则不需要刷新
|
||||
|
@ -1215,7 +1215,7 @@ bool GameController::phaseChange(int row, bool forceUpdate)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool GameController::updateScence()
|
||||
bool Game::updateScence()
|
||||
{
|
||||
#ifndef TRAINING_MODE
|
||||
return updateScence(position);
|
||||
|
@ -1224,7 +1224,7 @@ bool GameController::updateScence()
|
|||
#endif
|
||||
}
|
||||
|
||||
bool GameController::updateScence(Position &p)
|
||||
bool Game::updateScence(Position &p)
|
||||
{
|
||||
#ifndef TRAINING_MODE
|
||||
const Piece *board = p.get_board();
|
||||
|
@ -1380,7 +1380,7 @@ bool GameController::updateScence(Position &p)
|
|||
}
|
||||
|
||||
#ifdef NET_FIGHT_SUPPORT
|
||||
void GameController::showNetworkWindow()
|
||||
void Game::showNetworkWindow()
|
||||
{
|
||||
#ifndef TRAINING_MODE
|
||||
getServer()->show();
|
||||
|
@ -1389,19 +1389,19 @@ void GameController::showNetworkWindow()
|
|||
}
|
||||
#endif
|
||||
|
||||
void GameController::showTestWindow()
|
||||
void Game::showTestWindow()
|
||||
{
|
||||
gameTest->show();
|
||||
}
|
||||
|
||||
void GameController::humanResign()
|
||||
void Game::humanResign()
|
||||
{
|
||||
if (position.get_winner() == NOBODY) {
|
||||
resign();
|
||||
}
|
||||
}
|
||||
|
||||
void GameController::saveScore()
|
||||
void Game::saveScore()
|
||||
{
|
||||
QString strDate = QDateTime::currentDateTime().toString("yyyy-MM-dd");
|
||||
qint64 pid = QCoreApplication::applicationPid();
|
||||
|
@ -1463,12 +1463,12 @@ out:
|
|||
file.close();
|
||||
}
|
||||
|
||||
inline char GameController::color_to_char(Color color)
|
||||
inline char Game::color_to_char(Color color)
|
||||
{
|
||||
return static_cast<char>('0' + color);
|
||||
}
|
||||
|
||||
inline std::string GameController::char_to_string(char ch)
|
||||
inline std::string Game::char_to_string(char ch)
|
||||
{
|
||||
if (ch == '1') {
|
||||
return "黑方";
|
||||
|
@ -1477,7 +1477,7 @@ inline std::string GameController::char_to_string(char ch)
|
|||
}
|
||||
}
|
||||
|
||||
void GameController::appendGameOverReasonToCmdlist()
|
||||
void Game::appendGameOverReasonToCmdlist()
|
||||
{
|
||||
if (position.phase != PHASE_GAMEOVER) {
|
||||
return;
|
||||
|
@ -1518,7 +1518,7 @@ void GameController::appendGameOverReasonToCmdlist()
|
|||
cmdlist.emplace_back(cmdline);
|
||||
}
|
||||
|
||||
void GameController::setTips()
|
||||
void Game::setTips()
|
||||
{
|
||||
Position &p = position;
|
||||
|
||||
|
@ -1599,7 +1599,7 @@ void GameController::setTips()
|
|||
}
|
||||
}
|
||||
|
||||
time_t GameController::get_elapsed_time(int us)
|
||||
time_t Game::get_elapsed_time(int us)
|
||||
{
|
||||
return elapsedSeconds[us];
|
||||
}
|
|
@ -76,18 +76,18 @@ enum sound_t
|
|||
GAME_SOUND_WIN_AND_LOSSES_ARE_OBVIOUS
|
||||
};
|
||||
|
||||
class GameController : public QObject
|
||||
class Game : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GameController(
|
||||
Game(
|
||||
#ifndef TRAINING_MODE
|
||||
GameScene &scene,
|
||||
#endif
|
||||
QObject *parent = nullptr
|
||||
);
|
||||
~GameController() override;
|
||||
~Game() override;
|
||||
|
||||
//主窗口菜单栏明细
|
||||
const map<int, QStringList> getActions();
|
||||
|
@ -489,12 +489,12 @@ private:
|
|||
std::vector <std::string> cmdlist;
|
||||
};
|
||||
|
||||
inline time_t GameController::start_timeb() const
|
||||
inline time_t Game::start_timeb() const
|
||||
{
|
||||
return startTime;
|
||||
}
|
||||
|
||||
inline void GameController::set_start_time(int stimeb)
|
||||
inline void Game::set_start_time(int stimeb)
|
||||
{
|
||||
startTime = stimeb;
|
||||
}
|
|
@ -39,7 +39,7 @@
|
|||
#include <QDesktopWidget>
|
||||
|
||||
#include "gamewindow.h"
|
||||
#include "gamecontroller.h"
|
||||
#include "game.h"
|
||||
#include "gamescene.h"
|
||||
#include "graphicsconst.h"
|
||||
#include "server.h"
|
||||
|
@ -116,9 +116,9 @@ MillGameWindow::MillGameWindow(QWidget * parent) :
|
|||
|
||||
MillGameWindow::~MillGameWindow()
|
||||
{
|
||||
if (gameController) {
|
||||
gameController->disconnect();
|
||||
gameController->deleteLater();
|
||||
if (game) {
|
||||
game->disconnect();
|
||||
game->deleteLater();
|
||||
}
|
||||
|
||||
qDeleteAll(ruleActionList);
|
||||
|
@ -156,18 +156,18 @@ bool MillGameWindow::eventFilter(QObject *watched, QEvent *event)
|
|||
void MillGameWindow::initialize()
|
||||
{
|
||||
// 初始化函数,仅执行一次
|
||||
if (gameController)
|
||||
if (game)
|
||||
return;
|
||||
|
||||
#ifndef TRAINING_MODE
|
||||
// 开辟一个新的游戏控制器
|
||||
gameController = new GameController(*scene, this);
|
||||
game = new Game(*scene, this);
|
||||
#else
|
||||
gameController = new GameController(this);
|
||||
game = new Game(this);
|
||||
#endif // TRAINING_MODE
|
||||
|
||||
// 添加新菜单栏动作
|
||||
map<int, QStringList> actions = gameController->getActions();
|
||||
map<int, QStringList> actions = game->getActions();
|
||||
|
||||
for (auto i = actions.begin(); i != actions.end(); i++) {
|
||||
// map的key存放int索引值,value存放规则名称和规则提示
|
||||
|
@ -191,18 +191,18 @@ void MillGameWindow::initialize()
|
|||
// 关联主窗口动作信号和控制器的槽
|
||||
|
||||
connect(ui.actionResign_G, SIGNAL(triggered()),
|
||||
gameController, SLOT(resign()));
|
||||
game, SLOT(resign()));
|
||||
|
||||
#ifdef MOBILE_APP_UI
|
||||
connect(ui.pushButton_resign, SIGNAL(released()),
|
||||
gameController, SLOT(resign()));
|
||||
game, SLOT(resign()));
|
||||
#endif
|
||||
|
||||
connect(ui.actionEngine1_T, SIGNAL(toggled(bool)),
|
||||
gameController, SLOT(setEngineBlack(bool)));
|
||||
game, SLOT(setEngineBlack(bool)));
|
||||
|
||||
connect(ui.actionEngine2_R, SIGNAL(toggled(bool)),
|
||||
gameController, SLOT(setEngineWhite(bool)));
|
||||
game, SLOT(setEngineWhite(bool)));
|
||||
|
||||
#ifdef TEST_MODE
|
||||
//ui.actionEngine1_T->setChecked(false);
|
||||
|
@ -210,106 +210,106 @@ void MillGameWindow::initialize()
|
|||
#endif // TEST_MODE
|
||||
|
||||
connect(ui.actionSound_S, SIGNAL(toggled(bool)),
|
||||
gameController, SLOT(setSound(bool)));
|
||||
game, SLOT(setSound(bool)));
|
||||
|
||||
#ifdef TEST_MODE
|
||||
ui.actionSound_S->setChecked(false);
|
||||
#endif // TEST_MODE
|
||||
|
||||
connect(ui.actionAnimation_A, SIGNAL(toggled(bool)),
|
||||
gameController, SLOT(setAnimation(bool)));
|
||||
game, SLOT(setAnimation(bool)));
|
||||
|
||||
connect(ui.actionResignIfMostLose_G, SIGNAL(toggled(bool)),
|
||||
gameController, SLOT(setResignIfMostLose(bool)));
|
||||
game, SLOT(setResignIfMostLose(bool)));
|
||||
|
||||
#ifdef TEST_MODE
|
||||
//ui.actionResignIfMostLose_G->setChecked(true);
|
||||
#endif // TEST_MODE
|
||||
|
||||
connect(ui.actionAutoRestart_A, SIGNAL(toggled(bool)),
|
||||
gameController, SLOT(setAutoRestart(bool)));
|
||||
game, SLOT(setAutoRestart(bool)));
|
||||
|
||||
#ifdef TEST_MODE
|
||||
ui.actionAutoRestart_A->setChecked(true);
|
||||
#endif // TEST_MODE
|
||||
|
||||
connect(ui.actionAutoChangeFirstMove_C, SIGNAL(toggled(bool)),
|
||||
gameController, SLOT(setAutoChangeFirstMove(bool)));
|
||||
game, SLOT(setAutoChangeFirstMove(bool)));
|
||||
|
||||
connect(ui.actionRandomMove_R, SIGNAL(toggled(bool)),
|
||||
gameController, SLOT(setRandomMove(bool)));
|
||||
game, SLOT(setRandomMove(bool)));
|
||||
|
||||
connect(ui.actionLearnEndgame_E, SIGNAL(toggled(bool)),
|
||||
gameController, SLOT(setLearnEndgame(bool)));
|
||||
game, SLOT(setLearnEndgame(bool)));
|
||||
|
||||
connect(ui.actionIDS_I, SIGNAL(toggled(bool)),
|
||||
gameController, SLOT(setIDS(bool)));
|
||||
game, SLOT(setIDS(bool)));
|
||||
|
||||
// DepthExtension
|
||||
connect(ui.actionDepthExtension_D, SIGNAL(toggled(bool)),
|
||||
gameController, SLOT(setDepthExtension(bool)));
|
||||
game, SLOT(setDepthExtension(bool)));
|
||||
|
||||
// OpeningBook
|
||||
connect(ui.actionOpeningBook_O, SIGNAL(toggled(bool)),
|
||||
gameController, SLOT(setOpeningBook(bool)));
|
||||
game, SLOT(setOpeningBook(bool)));
|
||||
|
||||
// 视图上下翻转
|
||||
connect(ui.actionFlip_F, &QAction::triggered,
|
||||
gameController, &GameController::flip);
|
||||
game, &Game::flip);
|
||||
|
||||
// 视图左右镜像
|
||||
connect(ui.actionMirror_M, &QAction::triggered,
|
||||
gameController, &GameController::mirror);
|
||||
game, &Game::mirror);
|
||||
|
||||
// 视图须时针旋转90°
|
||||
connect(ui.actionTurnRight_R, &QAction::triggered,
|
||||
gameController, &GameController::turnRight);
|
||||
game, &Game::turnRight);
|
||||
|
||||
// 视图逆时针旋转90°
|
||||
connect(ui.actionTurnLeftt_L, &QAction::triggered,
|
||||
gameController, &GameController::turnLeft);
|
||||
game, &Game::turnLeft);
|
||||
|
||||
// 关联控制器的信号和主窗口控件的槽
|
||||
|
||||
// 更新LCD,显示总盘数
|
||||
connect(gameController, SIGNAL(nGamesPlayedChanged(QString)),
|
||||
connect(game, SIGNAL(nGamesPlayedChanged(QString)),
|
||||
ui.scoreLcdNumber_GamesPlayed, SLOT(display(QString)));
|
||||
|
||||
// 更新LCD,显示玩家1赢盘数
|
||||
connect(gameController, SIGNAL(score1Changed(QString)),
|
||||
connect(game, SIGNAL(score1Changed(QString)),
|
||||
ui.scoreLcdNumber_1, SLOT(display(QString)));
|
||||
|
||||
// 更新LCD,显示玩家2赢盘数
|
||||
connect(gameController, SIGNAL(score2Changed(QString)),
|
||||
connect(game, SIGNAL(score2Changed(QString)),
|
||||
ui.scoreLcdNumber_2, SLOT(display(QString)));
|
||||
|
||||
// 更新LCD,显示和棋数
|
||||
connect(gameController, SIGNAL(scoreDrawChanged(QString)),
|
||||
connect(game, SIGNAL(scoreDrawChanged(QString)),
|
||||
ui.scoreLcdNumber_draw, SLOT(display(QString)));
|
||||
|
||||
// 更新LCD,显示玩家1赢盘率
|
||||
connect(gameController, SIGNAL(winningRate1Changed(QString)),
|
||||
connect(game, SIGNAL(winningRate1Changed(QString)),
|
||||
ui.winningRateLcdNumber_1, SLOT(display(QString)));
|
||||
|
||||
// 更新LCD,显示玩家2赢盘率
|
||||
connect(gameController, SIGNAL(winningRate2Changed(QString)),
|
||||
connect(game, SIGNAL(winningRate2Changed(QString)),
|
||||
ui.winningRateLcdNumber_2, SLOT(display(QString)));
|
||||
|
||||
// 更新LCD,显示和棋率
|
||||
connect(gameController, SIGNAL(winningRateDrawChanged(QString)),
|
||||
connect(game, SIGNAL(winningRateDrawChanged(QString)),
|
||||
ui.winningRateLcdNumber_draw, SLOT(display(QString)));
|
||||
|
||||
// 更新LCD1,显示玩家1用时
|
||||
connect(gameController, SIGNAL(time1Changed(QString)),
|
||||
connect(game, SIGNAL(time1Changed(QString)),
|
||||
ui.lcdNumber_1, SLOT(display(QString)));
|
||||
|
||||
// 更新LCD2,显示玩家2用时
|
||||
connect(gameController, SIGNAL(time2Changed(QString)),
|
||||
connect(game, SIGNAL(time2Changed(QString)),
|
||||
ui.lcdNumber_2, SLOT(display(QString)));
|
||||
|
||||
// 关联场景的信号和控制器的槽
|
||||
connect(scene, SIGNAL(mouseReleased(QPointF)),
|
||||
gameController, SLOT(actionPiece(QPointF)));
|
||||
game, SLOT(actionPiece(QPointF)));
|
||||
|
||||
// 为状态栏添加一个正常显示的标签
|
||||
auto *statusBarlabel = new QLabel(this);
|
||||
|
@ -319,7 +319,7 @@ void MillGameWindow::initialize()
|
|||
ui.statusBar->addWidget(statusBarlabel);
|
||||
|
||||
// 更新状态栏
|
||||
connect(gameController, SIGNAL(statusBarChanged(QString)),
|
||||
connect(game, SIGNAL(statusBarChanged(QString)),
|
||||
statusBarlabel, SLOT(setText(QString)));
|
||||
|
||||
// 默认规则
|
||||
|
@ -327,13 +327,13 @@ void MillGameWindow::initialize()
|
|||
ruleActionList[ruleNo]->setChecked(true);
|
||||
|
||||
// 重置游戏规则
|
||||
gameController->setRule(ruleNo);
|
||||
game->setRule(ruleNo);
|
||||
|
||||
// 更新规则显示
|
||||
ruleInfo();
|
||||
|
||||
// 关联列表视图和字符串列表模型
|
||||
ui.listView->setModel(gameController->getManualListModel());
|
||||
ui.listView->setModel(game->getManualListModel());
|
||||
|
||||
// 因为QListView的rowsInserted在setModel之后才能启动,
|
||||
// 第一次需手动初始化选中listView第一项
|
||||
|
@ -424,8 +424,8 @@ void MillGameWindow::ctxMenu(const QPoint &pos)
|
|||
|
||||
void MillGameWindow::ruleInfo()
|
||||
{
|
||||
int s = gameController->getStepsLimit();
|
||||
int t = gameController->getTimeLimit();
|
||||
int s = game->getStepsLimit();
|
||||
int t = game->getTimeLimit();
|
||||
|
||||
QString tl(" 不限时");
|
||||
QString sl(" 不限步");
|
||||
|
@ -487,8 +487,8 @@ void MillGameWindow::on_actionLimited_T_triggered()
|
|||
* 还要写与主窗口的接口,费劲
|
||||
* 于是手写QDialog界面
|
||||
*/
|
||||
int gStep = gameController->getStepsLimit();
|
||||
int gTime = gameController->getTimeLimit();
|
||||
int gStep = game->getStepsLimit();
|
||||
int gTime = game->getTimeLimit();
|
||||
|
||||
// 定义新对话框
|
||||
auto *dialog = new QDialog(this);
|
||||
|
@ -551,7 +551,7 @@ void MillGameWindow::on_actionLimited_T_triggered()
|
|||
int dTime = comboBox_time->currentData().toInt();
|
||||
if (gStep != dStep || gTime != dTime) {
|
||||
// 重置游戏规则
|
||||
gameController->setRule(ruleNo, static_cast<int>(dStep), dTime);
|
||||
game->setRule(ruleNo, static_cast<int>(dStep), dTime);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -578,7 +578,7 @@ void MillGameWindow::actionRules_triggered()
|
|||
ruleNo = action->data().toInt();
|
||||
|
||||
// 如果游戏规则没变化,则返回
|
||||
if (ruleNo == gameController->getRuleIndex())
|
||||
if (ruleNo == game->getRuleIndex())
|
||||
return;
|
||||
|
||||
// 取消AI设定
|
||||
|
@ -586,7 +586,7 @@ void MillGameWindow::actionRules_triggered()
|
|||
ui.actionEngine2_R->setChecked(false);
|
||||
|
||||
// 重置游戏规则
|
||||
gameController->setRule(ruleNo);
|
||||
game->setRule(ruleNo);
|
||||
|
||||
// 更新规则显示
|
||||
ruleInfo();
|
||||
|
@ -598,17 +598,17 @@ void MillGameWindow::on_actionNew_N_triggered()
|
|||
|
||||
// 棋未下完,且已经走了若干步以上,则算对手得分
|
||||
if (strlist->stringList().size() > 12) {
|
||||
gameController->humanResign();
|
||||
game->humanResign();
|
||||
}
|
||||
|
||||
gameController->saveScore();
|
||||
game->saveScore();
|
||||
|
||||
#ifdef SAVE_GAMEBOOK_WHEN_ACTION_NEW_TRIGGERED
|
||||
QString strDateTime = QDateTime::currentDateTime().toString("yyyy-MM-dd_hhmmss");
|
||||
QString strDate = QDateTime::currentDateTime().toString("yyyy-MM-dd");
|
||||
QString whoWin;
|
||||
|
||||
switch (gameController->getPosition()->get_winner()) {
|
||||
switch (game->getPosition()->get_winner()) {
|
||||
case BLACK:
|
||||
whoWin = "Black-Win";
|
||||
break;
|
||||
|
@ -638,7 +638,7 @@ void MillGameWindow::on_actionNew_N_triggered()
|
|||
ui.actionAutoRun_A->setChecked(false);
|
||||
|
||||
// 重置游戏规则
|
||||
gameController->gameReset();
|
||||
game->gameReset();
|
||||
|
||||
// 重设AI设定
|
||||
if (ui.actionEngine2_R->isChecked()) {
|
||||
|
@ -691,7 +691,7 @@ void MillGameWindow::on_actionOpen_O_triggered()
|
|||
cmd = textStream.readLine();
|
||||
|
||||
// 读取并显示棋谱时,不必刷新棋局场景
|
||||
if (!(gameController->command(cmd.toStdString(), false))) {
|
||||
if (!(game->command(cmd.toStdString(), false))) {
|
||||
// 定义新对话框
|
||||
QMessageBox msgBox(QMessageBox::Warning, tr("文件错误"), tr("不是正确的棋谱文件"), QMessageBox::Ok);
|
||||
msgBox.exec();
|
||||
|
@ -700,11 +700,11 @@ void MillGameWindow::on_actionOpen_O_triggered()
|
|||
|
||||
while (!textStream.atEnd()) {
|
||||
cmd = textStream.readLine();
|
||||
gameController->command(cmd.toStdString(), false);
|
||||
game->command(cmd.toStdString(), false);
|
||||
}
|
||||
|
||||
// 最后刷新棋局场景
|
||||
gameController->updateScence();
|
||||
game->updateScence();
|
||||
}
|
||||
|
||||
void MillGameWindow::on_actionSave_S_triggered()
|
||||
|
@ -760,7 +760,7 @@ void MillGameWindow::on_actionInvert_I_toggled(bool arg1)
|
|||
}
|
||||
|
||||
// 让控制器改变棋子颜色
|
||||
gameController->setInvert(arg1);
|
||||
game->setInvert(arg1);
|
||||
}
|
||||
|
||||
// 前后招的公共槽
|
||||
|
@ -824,7 +824,7 @@ void MillGameWindow::on_actionRowChange()
|
|||
}
|
||||
|
||||
// 更新局面
|
||||
gameController->phaseChange(currentRow);
|
||||
game->phaseChange(currentRow);
|
||||
|
||||
#if 0
|
||||
// 下面的代码全部取消,改用QTimer的方式实现
|
||||
|
@ -893,7 +893,7 @@ void MillGameWindow::onAutoRunTimeOut(QPrivateSignal signal)
|
|||
}
|
||||
|
||||
// 更新局面
|
||||
gameController->phaseChange(currentRow);
|
||||
game->phaseChange(currentRow);
|
||||
}
|
||||
|
||||
// 自动运行
|
||||
|
@ -905,7 +905,7 @@ void MillGameWindow::on_actionAutoRun_A_toggled(bool arg1)
|
|||
ui.gameView->setEnabled(false);
|
||||
|
||||
// 启动定时器
|
||||
autoRunTimer.start(gameController->getDurationTime() * 10 + 50);
|
||||
autoRunTimer.start(game->getDurationTime() * 10 + 50);
|
||||
} else {
|
||||
// 关闭定时器
|
||||
autoRunTimer.stop();
|
||||
|
@ -922,7 +922,7 @@ void MillGameWindow::on_actionLocal_L_triggered()
|
|||
ui.actionEngineFight_E->setChecked(false);
|
||||
ui.actionInternet_I->setChecked(false);
|
||||
|
||||
gameController->getTest()->stop();
|
||||
game->getTest()->stop();
|
||||
}
|
||||
|
||||
void MillGameWindow::on_actionInternet_I_triggered()
|
||||
|
@ -932,9 +932,9 @@ void MillGameWindow::on_actionInternet_I_triggered()
|
|||
ui.actionEngineFight_E->setChecked(false);
|
||||
ui.actionInternet_I->setChecked(true);
|
||||
|
||||
gameController->getTest()->stop();
|
||||
game->getTest()->stop();
|
||||
|
||||
gameController->showNetworkWindow();
|
||||
game->showNetworkWindow();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -944,7 +944,7 @@ void MillGameWindow::on_actionEngineFight_E_triggered()
|
|||
ui.actionEngineFight_E->setChecked(true);
|
||||
ui.actionInternet_I->setChecked(false);
|
||||
|
||||
gameController->showTestWindow();
|
||||
game->showTestWindow();
|
||||
}
|
||||
|
||||
void MillGameWindow::on_actionEngine_E_triggered()
|
||||
|
@ -1005,7 +1005,7 @@ void MillGameWindow::on_actionEngine_E_triggered()
|
|||
|
||||
// 目前数据
|
||||
int time1, time2;
|
||||
gameController->getAiDepthTime(time1, time2);
|
||||
game->getAiDepthTime(time1, time2);
|
||||
spinBox_time1->setValue(time1);
|
||||
spinBox_time2->setValue(time2);
|
||||
|
||||
|
@ -1019,7 +1019,7 @@ void MillGameWindow::on_actionEngine_E_triggered()
|
|||
if (time1 != time1_new ||
|
||||
time2 != time2_new) {
|
||||
// 重置AI
|
||||
gameController->setAiDepthTime(time1_new, time2_new);
|
||||
game->setAiDepthTime(time1_new, time2_new);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
using namespace std;
|
||||
|
||||
class GameScene;
|
||||
class GameController;
|
||||
class Game;
|
||||
|
||||
class MillGameWindow : public QMainWindow
|
||||
{
|
||||
|
@ -120,7 +120,7 @@ private:
|
|||
GameScene *scene {nullptr};
|
||||
|
||||
// 控制器
|
||||
GameController *gameController {nullptr};
|
||||
Game *game {nullptr};
|
||||
|
||||
// 动态增加的菜单栏动作列表
|
||||
vector<QAction *> ruleActionList;
|
||||
|
|
Loading…
Reference in New Issue