From c6cf67409350a68b3b4e53fffad80d4b5fc5d3cb Mon Sep 17 00:00:00 2001 From: CalciteM Team Date: Sun, 11 Aug 2019 23:20:46 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=20update=20?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 缩小嵌套层级。 --- NineChess/src/ninechess.cpp | 61 ++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 34 deletions(-) diff --git a/NineChess/src/ninechess.cpp b/NineChess/src/ninechess.cpp index 40c14a08..6c088b97 100644 --- a/NineChess/src/ninechess.cpp +++ b/NineChess/src/ninechess.cpp @@ -1172,42 +1172,35 @@ inline long NineChess::update(long time_p /*= -1*/) long playerNext_ms = (context.turn == PLAYER1 ? elapsedMS_2 : elapsedMS_1); // 根据局面调整计时器 - switch (context.stage) { - case NineChess::GAME_PLACING: - case NineChess::GAME_MOVING: - ftime(¤tTimeb); - // 更新时间 - if (time_p >= *player_ms) { - *player_ms = ret = time_p; - long t = elapsedMS_1 + elapsedMS_2; - if (t % 1000 <= currentTimeb.millitm) { - startTimeb.time = currentTimeb.time - (t / 1000); - startTimeb.millitm = currentTimeb.millitm - (t % 1000); - } else { - startTimeb.time = currentTimeb.time - (t / 1000) - 1; - startTimeb.millitm = currentTimeb.millitm + 1000 - (t % 1000); - } - } else { - *player_ms = ret = static_cast(currentTimeb.time - startTimeb.time) * 1000 - + (currentTimeb.millitm - startTimeb.millitm) - playerNext_ms; - } - - // 有限时要求则判断胜负 - if (currentRule.maxTimeLedToLose > 0) - win(); - - return ret; - - case NineChess::GAME_NOTSTARTED: - return ret; - - case NineChess::GAME_OVER: - return ret; - - default: - return ret; + if (!(context.stage == GAME_PLACING || context.stage == GAME_MOVING)) { + return -1; } + + ftime(¤tTimeb); + + // 更新时间 + if (time_p >= *player_ms) { + *player_ms = ret = time_p; + long t = elapsedMS_1 + elapsedMS_2; + if (t % 1000 <= currentTimeb.millitm) { + startTimeb.time = currentTimeb.time - (t / 1000); + startTimeb.millitm = currentTimeb.millitm - (t % 1000); + } else { + startTimeb.time = currentTimeb.time - (t / 1000) - 1; + startTimeb.millitm = currentTimeb.millitm + 1000 - (t % 1000); + } + } else { + *player_ms = ret = static_cast(currentTimeb.time - startTimeb.time) * 1000 + + (currentTimeb.millitm - startTimeb.millitm) - playerNext_ms; + } + + // 有限时要求则判断胜负 + if (currentRule.maxTimeLedToLose > 0) { + win(); + } + + return ret; } // 是否分出胜负