支持设置棋局结束后自动重新开始
This commit is contained in:
parent
43833226ca
commit
d8f9f375ab
|
@ -227,7 +227,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>491</width>
|
||||
<height>21</height>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menu_F">
|
||||
|
@ -276,6 +276,7 @@
|
|||
<addaction name="separator"/>
|
||||
<addaction name="actionEngine1_T"/>
|
||||
<addaction name="actionEngine2_R"/>
|
||||
<addaction name="separator"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_O">
|
||||
<property name="title">
|
||||
|
@ -286,8 +287,11 @@
|
|||
<addaction name="actionToolBar_T"/>
|
||||
<addaction name="actionDockBar_D"/>
|
||||
<addaction name="actionMusic_M"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionSound_S"/>
|
||||
<addaction name="actionAnimation_A"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionAutoRestart_A"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_H">
|
||||
<property name="title">
|
||||
|
@ -1089,6 +1093,14 @@
|
|||
<string>关于(A)</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionAutoRestart_A">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>自动重新开局(&A)</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<customwidgets>
|
||||
|
|
|
@ -38,8 +38,6 @@
|
|||
#define EMIT_COMMAND_DELAY (0)
|
||||
#endif
|
||||
|
||||
//#define AOTO_RESTART_GAME
|
||||
|
||||
//#define MIN_MAX_ONLY
|
||||
|
||||
//#define EVALUATE_ENABLE
|
||||
|
|
|
@ -1479,9 +1479,6 @@ bool MillGame::command(const char *cmd)
|
|||
tips = "三次重复局面判和。";
|
||||
sprintf(cmdline, "Threefold Repetition. Draw!");
|
||||
cmdlist.emplace_back(string(cmdline));
|
||||
#ifdef AOTO_RESTART_GAME
|
||||
start(); // TODO: 待转移到更合适的位置
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
@ -1986,10 +1983,6 @@ void MillGame::setTips()
|
|||
tips = "玩家2获胜!比分 " + to_string(score_1) + ":" + to_string(score_2) + ", 和棋 " + to_string(score_draw);
|
||||
}
|
||||
|
||||
#ifdef AOTO_RESTART_GAME
|
||||
start(); // TODO: 待转移到更合适的位置
|
||||
#endif
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -50,6 +50,7 @@ GameController::GameController(GameScene & scene, QObject * parent) :
|
|||
hasAnimation(true),
|
||||
durationTime(500),
|
||||
hasSound(true),
|
||||
isAutoRestart(false),
|
||||
timeID(0),
|
||||
ruleNo_(-1),
|
||||
timeLimit(0),
|
||||
|
@ -144,10 +145,12 @@ void GameController::gameReset()
|
|||
chessTemp = chess_;
|
||||
|
||||
// 停掉线程
|
||||
ai1.stop();
|
||||
ai2.stop();
|
||||
isAiPlayer1 = false;
|
||||
isAiPlayer2 = false;
|
||||
if (!isAutoRestart) {
|
||||
ai1.stop();
|
||||
ai2.stop();
|
||||
isAiPlayer1 = false;
|
||||
isAiPlayer2 = false;
|
||||
}
|
||||
|
||||
// 清除棋子
|
||||
qDeleteAll(pieceList);
|
||||
|
@ -361,6 +364,11 @@ void GameController::playSound(const QString &soundPath)
|
|||
#endif /* ! DONOT_PLAY_SOUND */
|
||||
}
|
||||
|
||||
void GameController::setAutoRestart(bool arg)
|
||||
{
|
||||
isAutoRestart = arg;
|
||||
}
|
||||
|
||||
// 上下翻转
|
||||
void GameController::flip()
|
||||
{
|
||||
|
@ -862,8 +870,9 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
|
|||
// 播放胜利或失败音效
|
||||
#ifndef DONOT_PLAY_WIN_SOUND
|
||||
if (chess_.whoWin() != MillGame::NOBODY &&
|
||||
(manualListModel.data(manualListModel.index(currentRow - 1))).toString().contains("Time over."))
|
||||
(manualListModel.data(manualListModel.index(currentRow - 1))).toString().contains("Time over.")) {
|
||||
playSound(":/sound/resources/sound/win.wav");
|
||||
}
|
||||
#endif
|
||||
|
||||
// AI设置
|
||||
|
@ -885,9 +894,21 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
|
|||
}
|
||||
}
|
||||
// 如果已经决出胜负
|
||||
else {
|
||||
ai1.stop();
|
||||
ai2.stop();
|
||||
else {
|
||||
ai1.stop();
|
||||
ai2.stop();
|
||||
|
||||
if (isAutoRestart) {
|
||||
gameReset();
|
||||
gameStart();
|
||||
|
||||
if (isAiPlayer1) {
|
||||
setEngine1(true);
|
||||
}
|
||||
if (isAiPlayer2) {
|
||||
setEngine2(true);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MESSAGEBOX_ENABLE
|
||||
// 弹框
|
||||
|
|
|
@ -145,6 +145,9 @@ public slots:
|
|||
// 播放声音
|
||||
void playSound(const QString &soundPath);
|
||||
|
||||
// 是否自动开局
|
||||
void setAutoRestart(bool arg = false);
|
||||
|
||||
// 上下翻转
|
||||
void flip();
|
||||
|
||||
|
@ -229,6 +232,9 @@ private:
|
|||
// 是否有落子音效
|
||||
bool hasSound;
|
||||
|
||||
// 是否棋局结束后自动重新开局
|
||||
bool isAutoRestart;
|
||||
|
||||
// 定时器ID
|
||||
int timeID;
|
||||
|
||||
|
|
|
@ -199,12 +199,16 @@ void MillGameWindow::initialize()
|
|||
connect(ui.actionEngine2_R, SIGNAL(toggled(bool)),
|
||||
game, SLOT(setEngine2(bool)));
|
||||
|
||||
connect(ui.actionSound_S, SIGNAL(toggled(bool)),
|
||||
connect(ui.
|
||||
actionSound_S, SIGNAL(toggled(bool)),
|
||||
game, SLOT(setSound(bool)));
|
||||
|
||||
connect(ui.actionAnimation_A, SIGNAL(toggled(bool)),
|
||||
game, SLOT(setAnimation(bool)));
|
||||
|
||||
connect(ui.actionAutoRestart_A, SIGNAL(toggled(bool)),
|
||||
game, SLOT(setAutoRestart(bool)));
|
||||
|
||||
// 视图上下翻转
|
||||
connect(ui.actionFlip_F, &QAction::triggered,
|
||||
game, &GameController::flip);
|
||||
|
|
|
@ -101,6 +101,7 @@ private slots:
|
|||
//void on_actionDockBar_D_toggled(bool arg1);
|
||||
//void on_actionSound_S_toggled(bool arg1);
|
||||
//void on_actionAnimation_A_toggled(bool arg1);
|
||||
//void on_actionAutoRestart_A_triggered();
|
||||
void on_actionViewHelp_V_triggered();
|
||||
void on_actionWeb_W_triggered();
|
||||
void on_actionAbout_A_triggered();
|
||||
|
|
Loading…
Reference in New Issue