chip-game/Assets/Scripts/Gameplay/EndOfTurnHandler.cs

85 lines
2.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using UnityEngine;
public static class EndOfTurnHandler
{
private static GameManager gm => GameManager.instance;
private static bool TotalWin() =>
gm.player1score == 5 || gm.player2score == 5 || gm.vsBotScore == gm.botsAmount;
private static void ClearAllScales()
{
if (gm.botScale.isActiveAndEnabled) gm.botScale.ClearScale();
if (gm.Player1Scale.isActiveAndEnabled) gm.Player1Scale.ClearScale();
if (gm.Player2Scale.isActiveAndEnabled) gm.Player2Scale.ClearScale();
}
//Надо куда то это перемещать. Мб в тот же роутер.
public static void WinByTimerHandling()
{
//При победе по таймеру:
//PVP проиграл тот, кто не успел кинуть фишку
//PVE - прогрывает человек
var result = new CheckResult(true, false, null);
IState nextState;
if (gm.gameMode == GameMode.pvp)
{
//p2 не успел
if (gm.currentPlayer == CellState.Player2)
{
gm.player1score += 1;
gm.Player1Scale.SetMedalsCount(gm.player1score);
}
else//p1 не успел
{
gm.player2score += 1;
gm.Player2Scale.SetMedalsCount(gm.player2score);
}
}
else if (gm.gameMode == GameMode.pve)//время вышло при игре с ботом - бот победил
{
LightUtility.Lose();
CharacterController.CurrentCharacter.GetComponent<Animator>().SetTrigger("Win");
//НЕ НИЧЬЯ
VictoryScale vsBotScale = gm.botScale;
DifficultyManager.Instance.DecreaseDifficulty();
CharacterEventBus.Instance.OnBotWin?.Invoke();
if (gm.vsBotScore != 0) gm.vsBotScore -= 1;
vsBotScale.SetMedalsCount(gm.vsBotScore);
}
nextState = new ShowWinnerState();
//конец игры - призовое состояние
if (TotalWin())
{
nextState = new VictoryState();
ClearAllScales();
}
gm.stateMachine.ChangeState(nextState);
}
public static TurnEndingResult Evaluate(CheckResult result, GameMode gameMode, CellState lastPlayer)
{
if (!result.End) return TurnEndingResult.GameContinues;
if (result.Draw) return TurnEndingResult.Draw;
if (gameMode == GameMode.pve)
{
return lastPlayer == CellState.Player1 ? TurnEndingResult.PlayerWinPve : TurnEndingResult.BotWin;
}
else //pvp
{
return TurnEndingResult.PlayerWinPvp;
}
}
}