refactor: 重构 update 函数

缩小嵌套层级。
This commit is contained in:
CalciteM Team 2019-08-11 23:20:46 +08:00
parent 0f1d2e5ff1
commit c6cf674093
1 changed files with 27 additions and 34 deletions

View File

@ -1172,9 +1172,11 @@ inline long NineChess::update(long time_p /*= -1*/)
long playerNext_ms = (context.turn == PLAYER1 ? elapsedMS_2 : elapsedMS_1); long playerNext_ms = (context.turn == PLAYER1 ? elapsedMS_2 : elapsedMS_1);
// 根据局面调整计时器 // 根据局面调整计时器
switch (context.stage) {
case NineChess::GAME_PLACING: if (!(context.stage == GAME_PLACING || context.stage == GAME_MOVING)) {
case NineChess::GAME_MOVING: return -1;
}
ftime(&currentTimeb); ftime(&currentTimeb);
// 更新时间 // 更新时间
@ -1194,20 +1196,11 @@ inline long NineChess::update(long time_p /*= -1*/)
} }
// 有限时要求则判断胜负 // 有限时要求则判断胜负
if (currentRule.maxTimeLedToLose > 0) if (currentRule.maxTimeLedToLose > 0) {
win(); win();
return ret;
case NineChess::GAME_NOTSTARTED:
return ret;
case NineChess::GAME_OVER:
return ret;
default:
return ret;
} }
return ret;
} }
// 是否分出胜负 // 是否分出胜负