refactor: 重构 giveup()

This commit is contained in:
CalciteM Team 2019-08-11 23:07:53 +08:00
parent 7f1816a64b
commit 0f1d2e5ff1
1 changed files with 19 additions and 17 deletions

View File

@ -1051,25 +1051,27 @@ bool NineChess::choose(int c, int p)
bool NineChess::giveup(Player loser)
{
if (context.stage == GAME_MOVING || context.stage == GAME_PLACING) {
if (loser == PLAYER1) {
context.stage = GAME_OVER;
winner = PLAYER2;
tips = "玩家1投子认负。";
sprintf(cmdline, "Player1 give up!");
cmdlist.push_back(string(cmdline));
return true;
} else if (loser == PLAYER2) {
context.stage = GAME_OVER;
winner = PLAYER1;
tips = "玩家2投子认负。";
sprintf(cmdline, "Player2 give up!");
cmdlist.push_back(string(cmdline));
return true;
}
if (context.stage == GAME_NOTSTARTED ||
context.stage == GAME_OVER ||
context.stage == GAME_NONE) {
return false;
}
return false;
context.stage = GAME_OVER;
if (loser == PLAYER1) {
winner = PLAYER2;
tips = "玩家1投子认负。";
sprintf(cmdline, "Player1 give up!");
} else if (loser == PLAYER2) {
winner = PLAYER1;
tips = "玩家2投子认负。";
sprintf(cmdline, "Player2 give up!");
}
cmdlist.push_back(string(cmdline));
return true;
}
// 打算用个C++的命令行解析库的,简单的没必要,但中文编码有极小概率出问题