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