移除重复代码
This commit is contained in:
parent
e8ddc4112f
commit
caa3bfb512
@ -119,18 +119,8 @@ export class PartResultCommand extends Command<CardGameState, {}> {
|
||||
result.push(obj2)
|
||||
}
|
||||
|
||||
let deadCount0 = 0;
|
||||
let deadCount1 = 0;
|
||||
for (let [, player] of this.state.players) {
|
||||
if (player.team == 0 && player.state == PlayerStateConst.PLAYER_DEAD ) {
|
||||
deadCount0 ++;
|
||||
} else if (player.team == 1 && player.state == PlayerStateConst.PLAYER_DEAD ){
|
||||
deadCount1 ++;
|
||||
}
|
||||
}
|
||||
const roundNum = new GameEnv().duelRoundNum;
|
||||
const totalRound = roundNum * new GameEnv().maxDuelNum;
|
||||
if ((deadCount0 == 2 || deadCount1 == 2) || (this.state.round >= totalRound - 1)) { // 游戏结束
|
||||
let gameResult = gameUtil.checkGameEnd(this.state);
|
||||
if (gameResult) {
|
||||
return [new Wait().setPayload(time*1000) ,new GameResultCommand()];
|
||||
} else { // 下发消息, 进入正常的下一轮
|
||||
this.room.bPartResult(new PartResultMsg(result));
|
||||
|
@ -6,6 +6,7 @@ import {NextTurnCommand} from "./NextTurnCommand";
|
||||
import {PlayerStateConst} from "../../constants/PlayerStateConst";
|
||||
import {Wait} from "./Wait";
|
||||
import {GameResultCommand} from "./GameResultCommand";
|
||||
import gameUtil from "../../utils/game.util";
|
||||
|
||||
/**
|
||||
* 一轮结束
|
||||
@ -30,21 +31,10 @@ export class TurnEndCommand extends Command<CardGameState, {}> {
|
||||
// }
|
||||
// 判断是否胜利
|
||||
|
||||
let deadCount0 = 0;
|
||||
let deadCount1 = 0;
|
||||
for (let [, player] of this.state.players) {
|
||||
if (player.team == 0 && player.state == PlayerStateConst.PLAYER_DEAD ) {
|
||||
deadCount0 ++;
|
||||
} else if (player.team == 1 && player.state == PlayerStateConst.PLAYER_DEAD ){
|
||||
deadCount1 ++;
|
||||
}
|
||||
}
|
||||
const roundNum = new GameEnv().duelRoundNum;
|
||||
const totalRound = roundNum * new GameEnv().maxDuelNum;
|
||||
if ((deadCount0 == 2 || deadCount1 == 2) || (this.state.round >= totalRound - 1)) { // 游戏结束
|
||||
let result = gameUtil.checkGameEnd(this.state);
|
||||
if (result) {
|
||||
return [new GameResultCommand()];
|
||||
}
|
||||
|
||||
return [new NextTurnCommand()]
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,10 @@ import {SystemCardCfg} from "../cfg/parsers/SystemCardCfg";
|
||||
import {EffectCardCfg} from "../cfg/parsers/EffectCardCfg";
|
||||
import {error} from "../common/Debug";
|
||||
import {Room} from "colyseus";
|
||||
import {PlayerStateConst} from "../constants/PlayerStateConst";
|
||||
import {GameEnv} from "../cfg/GameEnv";
|
||||
import {GameResultCommand} from "../rooms/commands/GameResultCommand";
|
||||
import {CardGameState} from "../rooms/schema/CardGameState";
|
||||
|
||||
let gameUtil = {
|
||||
/**
|
||||
@ -292,6 +296,20 @@ let gameUtil = {
|
||||
return result;
|
||||
},
|
||||
|
||||
checkGameEnd(state: CardGameState) {
|
||||
let deadCount0 = 0;
|
||||
let deadCount1 = 0;
|
||||
for (let [, player] of state.players) {
|
||||
if (player.team == 0 && player.state == PlayerStateConst.PLAYER_DEAD ) {
|
||||
deadCount0 ++;
|
||||
} else if (player.team == 1 && player.state == PlayerStateConst.PLAYER_DEAD ){
|
||||
deadCount1 ++;
|
||||
}
|
||||
}
|
||||
const roundNum = new GameEnv().duelRoundNum;
|
||||
const totalRound = roundNum * new GameEnv().maxDuelNum;
|
||||
return (deadCount0 == 2 || deadCount1 == 2) || (state.round >= totalRound - 1);
|
||||
}
|
||||
|
||||
}
|
||||
export default gameUtil;
|
||||
|
Loading…
x
Reference in New Issue
Block a user