chip-game/Assets/Scripts/GameFSM/VictoryState.cs

109 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 TMPro;
using UnityEngine;
public class VictoryState : IState
{
VictoryScale scale;
GameManager gameManager;
TextMeshProUGUI ToMenuLabel;
TextMeshProUGUI TimerLabel;
float TimeRest = 15;
IState nextState;
public void enter()
{
LightUtility.Prize();
gameManager = GameManager.instance;
gameManager.timerManager.StopAllTimers();
ToMenuLabel = gameManager.ToMenuLabel;
//ToMenuLabel.text = "До перехода";
TimerLabel = gameManager.TimerLabel;
ToMenuLabel.gameObject.SetActive(true);
//определяем с какой шкалой мы имеем дело
if (gameManager.gameMode == GameMode.pvp)
{
nextState = new ShowWinnerState();
if (gameManager.currentPlayer == CellState.Player1)
{
scale = gameManager.Player1Scale;
gameManager.winPanel.ShowWin(CellState.Player1);
}
else
{
scale = gameManager.Player2Scale;
gameManager.winPanel.ShowWin(CellState.Player2);
}
}
else
{
//победили ботов
scale = gameManager.botScale;
gameManager.winPanel.ShowWin(CellState.Empty);
nextState = new VictoryVideoState(new EnterNameState());
}
//вкл анимацию приза
scale.SetWinState();
scale.winParticles.Play();
}
public void exit()
{
//выкл анимацию приза
scale.SetIdleState();
scale.winParticles.Stop();
gameManager.winPanel.CloseWin();
ToMenuLabel.gameObject.SetActive(false);
}
public void update()
{
//полинг инпутов
if (In.GetButtonDownAnyPlayer(PlayerAction.down))
{
gameManager.stateMachine.ChangeState(nextState);
}
TimerProcessing();
}
void GivePrizeAndGoMenu()
{
gameManager.stateMachine.ChangeState(nextState);
}
private void TimerProcessing()
{
TimeRest -= Time.deltaTime;
if (TimeRest < 0)
{
GivePrizeAndGoMenu();
}
TimerLabel.text = getTimeText();
}
private string getTimeText()//в утилити бы это вынести
{
string minutes = ((int)(TimeRest / 60)).ToString();
string seconds = ((int)(TimeRest % 60)).ToString();
if (minutes.Length < 2) minutes = "0" + minutes;
if (seconds.Length < 2) seconds = "0" + seconds;
string result = minutes + ":" + seconds;
return result;
}
}