From caa3bfb5122f9c3a4abd242726adf174e9f2b607 Mon Sep 17 00:00:00 2001 From: zhl Date: Tue, 22 Dec 2020 10:59:20 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E9=87=8D=E5=A4=8D=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rooms/commands/PartResultCommand.ts | 14 ++------------ src/rooms/commands/TurnEndCommand.ts | 16 +++------------- src/utils/game.util.ts | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/rooms/commands/PartResultCommand.ts b/src/rooms/commands/PartResultCommand.ts index d5959d7..0edfec3 100644 --- a/src/rooms/commands/PartResultCommand.ts +++ b/src/rooms/commands/PartResultCommand.ts @@ -119,18 +119,8 @@ export class PartResultCommand extends Command { 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)); diff --git a/src/rooms/commands/TurnEndCommand.ts b/src/rooms/commands/TurnEndCommand.ts index 5f62705..40d5802 100644 --- a/src/rooms/commands/TurnEndCommand.ts +++ b/src/rooms/commands/TurnEndCommand.ts @@ -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 { // } // 判断是否胜利 - 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()] } diff --git a/src/utils/game.util.ts b/src/utils/game.util.ts index 9f59bb3..63705ab 100644 --- a/src/utils/game.util.ts +++ b/src/utils/game.util.ts @@ -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;