options: 新增 option 模块并将 auto restart 配置移到其中

This commit is contained in:
CalciteM Team 2019-09-20 00:19:18 +08:00
parent a2d6a222a0
commit 5adaa2cc91
8 changed files with 96 additions and 9 deletions

View File

@ -29,6 +29,7 @@ SOURCES += \
src/base/misc.cpp \
src/base/zobrist.cpp \
src/game/board.cpp \
src/game/option.cpp \
src/game/player.cpp \
src/game/position.cpp \
src/game/rule.cpp \
@ -63,6 +64,7 @@ HEADERS += \
src/ai/search.h \
src/base/zobrist.h \
src/game/board.h \
src/game/option.h \
src/game/player.h \
src/game/position.h \
src/game/rule.h \

View File

@ -455,6 +455,7 @@
<QtMoc Include="src\base\thread.h" />
<ClInclude Include="src\base\zobrist.h" />
<ClInclude Include="src\game\board.h" />
<ClInclude Include="src\game\option.h" />
<ClInclude Include="src\game\player.h" />
<ClInclude Include="src\game\position.h" />
<ClInclude Include="src\game\rule.h" />
@ -702,6 +703,7 @@
<ClCompile Include="src\base\thread.cpp" />
<ClCompile Include="src\base\zobrist.cpp" />
<ClCompile Include="src\game\board.cpp" />
<ClCompile Include="src\game\option.cpp" />
<ClCompile Include="src\game\player.cpp" />
<ClCompile Include="src\game\position.cpp" />
<ClCompile Include="src\game\rule.cpp" />

View File

@ -120,6 +120,9 @@
<ClInclude Include="src\ai\endgame.h">
<Filter>ai</Filter>
</ClInclude>
<ClInclude Include="src\game\option.h">
<Filter>game</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="debug\moc_predefs.h.cbt">
@ -341,6 +344,9 @@
<ClCompile Include="src\ai\endgame.cpp">
<Filter>ai</Filter>
</ClCompile>
<ClCompile Include="src\game\option.cpp">
<Filter>game</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="millgame.rc">

34
src/game/option.cpp Normal file
View File

@ -0,0 +1,34 @@
/*****************************************************************************
* Copyright (C) 2018-2019 MillGame authors
*
* Authors: liuweilhy <liuweilhy@163.com>
* Calcitem <calcitem@outlook.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "option.h"
Options options;
void Options::setAutoRestart(bool enabled)
{
isAutoRestart = enabled;
};
bool Options::getAutoRestart()
{
return isAutoRestart;
}

45
src/game/option.h Normal file
View File

@ -0,0 +1,45 @@
/*****************************************************************************
* Copyright (C) 2018-2019 MillGame authors
*
* Authors: liuweilhy <liuweilhy@163.com>
* Calcitem <calcitem@outlook.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef OPTION_H
#define OPTION_H
#include "config.h"
class Options
{
public:
void setAutoRestart(bool enabled);
bool getAutoRestart();
protected:
private:
// 是否棋局结束后自动重新开局
bool isAutoRestart { false };
// 是否必败时认输
bool giveUpIfMostLose { false };
};
extern Options options;
#endif /* OPTION_H */

View File

@ -34,6 +34,7 @@
#include "boarditem.h"
#include "server.h"
#include "client.h"
#include "option.h"
GameController::GameController(GameScene & scene, QObject * parent) :
QObject(parent),
@ -45,7 +46,6 @@ GameController::GameController(GameScene & scene, QObject * parent) :
hasAnimation(true),
durationTime(500),
hasSound(true),
isAutoRestart(false),
timeID(0),
ruleNo_(-1),
timeLimit(0),
@ -153,7 +153,7 @@ void GameController::gameReset()
tempGame = game_;
// 停掉线程
if (!isAutoRestart) {
if (!options.getAutoRestart()) {
ai[1]->stop();
ai[2]->stop();
isAiPlayer[1] = false;
@ -376,9 +376,9 @@ void GameController::setGiveUpIfMostLose(bool arg)
giveUpIfMostLose_ = arg;
}
void GameController::setAutoRestart(bool arg)
void GameController::setAutoRestart(bool enabled)
{
isAutoRestart = arg;
options.setAutoRestart(enabled);
}
void GameController::setRandomMove(bool arg)
@ -906,7 +906,7 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
ai[1]->stop();
ai[2]->stop();
if (isAutoRestart) {
if (options.getAutoRestart()) {
gameReset();
gameStart();

View File

@ -158,7 +158,7 @@ public slots:
void setGiveUpIfMostLose(bool arg);
// 是否自动开局
void setAutoRestart(bool arg = false);
void setAutoRestart(bool enabled = false);
// AI 是否随机走子
void setRandomMove(bool arg);
@ -244,9 +244,6 @@ private:
// 是否必败时认输
bool giveUpIfMostLose_ {false};
// 是否棋局结束后自动重新开局
bool isAutoRestart;
// AI 是否随机走子
bool randomMove_;

View File

@ -48,6 +48,7 @@
#include "server.h"
#include "client.h"
#include "version.h"
#include "option.h"
MillGameWindow::MillGameWindow(QWidget * parent) :
QMainWindow(parent),