2026-01-21 15:35:44 +03:00

210 lines
6.8 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 System.Collections.Generic;
using UnityEngine;
public class CheckState : IState
{
GameManager gm;
int row, col;
bool timerWin;
public CheckState(int row, int col)
{
this.row = row;
this.col = col;
timerWin = false;
}
public CheckState(bool timerWin)
{
if (timerWin) this.timerWin = true;
else this.timerWin = false;
}
public void enter()
{
gm = GameManager.instance;
if (timerWin)
{
WinByTimerHandling();
}
else
{
NormalHandling();
}
}
void NormalHandling()
{
bool swipeToNextRightNow = false;
CheckResult result = GameManager.fieldModel.check(row, col);
gm.lastResult = result;
IState nextState;
//pvp решение победа в раунде или в игре
bool endround = false;
bool endgame = false;
// подсчет очков
if (result.end)//Раунд окончен. Считаем очки и ставим стейт показ победителя
{
if (gm.gameMode == GameMode.pvp && !result.draw)
{
//победил p1
if (gm.currentPlayer == CellState.Player1)
{
gm.player1score += 1;
gm.Player1Scale.SetMedalsCount(gm.player1score);
}
else//победил p2
{
gm.player2score += 1;
gm.Player2Scale.SetMedalsCount(gm.player2score);
}
endround = true;
if (gm.player1score == 5 || gm.player2score == 5)
endgame = true;
if (endgame)
AvatarEventBus.Instance.OnEndGame?.Invoke(gm.currentPlayer);
else if(endround)
AvatarEventBus.Instance.OnEndRound?.Invoke(gm.currentPlayer);
}
else if (gm.gameMode == GameMode.pve && !result.draw) //конец раунда с ботом
{
//НЕ НИЧЬЯ
VictoryScale botScale = gm.botScale;
if (gm.currentPlayer == CellState.Player1)//[ПОБЕДА ИГРОКА]
{
if (CharacterController.CurrentCharacter.HasPrize)
{
PrizeSystem.GivePrize(CharacterController.CurrentCharacter.prize);
CharacterController.CurrentCharacter.HasPrize = false;
}
DifficultyManager.instance.IncreaseDifficulty();
gm.vsBotScore += 1;
CharacterEventBus.Instance.OnPlayerWin?.Invoke();
LightUtility.Win();
CharacterController.CurrentCharacter.GetComponent<Animator>().SetTrigger("Lose");
swipeToNextRightNow = true;
//swipeToNextRightNow = false;
}
else//Бот победил
{
LightUtility.Lose();
CharacterController.CurrentCharacter.GetComponent<Animator>().SetTrigger("Win");
DifficultyManager.instance.DecreaseDifficulty();
if (gm.vsBotScore != 0)
gm.vsBotScore -= 1;
CharacterEventBus.Instance.OnBotWin?.Invoke();
}
botScale.SetMedalsCount(gm.vsBotScore);
}
else if (gm.gameMode == GameMode.pve && result.draw)
{
CharacterEventBus.Instance.OnDraw?.Invoke();
}
nextState = new ShowWinnerState(result);
}
else
{
gm.SwitchPlayer();
nextState = new StartTurnState();
}
if (gm.gameMode == GameMode.pve && gm.vsBotScore == gm.botsAmount) gm.upgradeFeeshkaDifficulty();
//конец игры - призовое состояние
if (gm.player1score == 5 || gm.player2score == 5 || gm.vsBotScore == gm.botsAmount)
{
nextState = new PrizeState();
if (gm.botScale.isActiveAndEnabled) gm.botScale.ClearScale();
if (gm.Player1Scale.isActiveAndEnabled) gm.Player1Scale.ClearScale();
if (gm.Player2Scale.isActiveAndEnabled) gm.Player2Scale.ClearScale();
}
else if (swipeToNextRightNow)
{
ShowWinnerState showWinner = new ShowWinnerState(result);
showWinner.subState = ShowWinnerState.ShowWinnerSubstates.ExitByTime;
showWinner.timeRest = 4;
nextState = showWinner;
}
gm.stateMachine.ChangeState(nextState);
}
void WinByTimerHandling()
{
//запустить проверку по полю
CheckResult result = new CheckResult(true, false, null, null);
gm.lastResult = result;
IState nextState;
if (gm.gameMode == GameMode.pvp)
{
if (!result.draw)
{
//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)//время вышло при игре с ботом - бот победил
{
if (!result.draw)
{
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(result);
//конец игры - призовое состояние
if (gm.player1score == 5 || gm.player2score == 5 || gm.vsBotScore == gm.botsAmount)
{
nextState = new PrizeState();
if (gm.botScale.isActiveAndEnabled) gm.botScale.ClearScale();
if (gm.Player1Scale.isActiveAndEnabled) gm.Player1Scale.ClearScale();
if (gm.Player2Scale.isActiveAndEnabled) gm.Player2Scale.ClearScale();
}
gm.stateMachine.ChangeState(nextState);
}
public void exit()
{
}
public void update()
{
}
}