62 lines
1.5 KiB
C#
62 lines
1.5 KiB
C#
using DG.Tweening;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class EndGameHandler : MonoBehaviour
|
|
{
|
|
[SerializeField] PveWinPanel winPanel;
|
|
[SerializeField] PveLossPanel lossPanel;
|
|
[SerializeField] PvpWinPanel pvpWinPanel;
|
|
[SerializeField] DrawAgainButton drawPanel;
|
|
|
|
|
|
public void HandleEndGame(Team lastPlayer, GameMode gameMode, CheckResult lastResult)
|
|
{
|
|
print("Конец игры");
|
|
|
|
|
|
if (lastResult.Draw)
|
|
DrawHandler();
|
|
else
|
|
WinHandler(winner: lastPlayer,
|
|
gameMode: gameMode,
|
|
winChipsCoords: lastResult.WinningIndexes);
|
|
|
|
}
|
|
|
|
private void DrawHandler()
|
|
{
|
|
//drawPanel.Open();
|
|
}
|
|
|
|
private void WinHandler(Team winner, GameMode gameMode, HashSet<(int row, int col)> winChipsCoords)
|
|
{
|
|
Debug.Log($"Победа {winner}; Режим {gameMode}");
|
|
PlayWinChipsAnimation(winChipsCoords);
|
|
|
|
if(gameMode == GameMode.pve)
|
|
{
|
|
if(winner == Team.Player1)
|
|
{
|
|
winPanel.Open();
|
|
}
|
|
else
|
|
lossPanel.Open();
|
|
}
|
|
else
|
|
{
|
|
pvpWinPanel.Open();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private void PlayWinChipsAnimation(HashSet<(int row, int col)> winChipsCoords)
|
|
{
|
|
Chip[,] grid = Board.Instance.Grid;
|
|
|
|
foreach (var winCoord in winChipsCoords)
|
|
grid[winCoord.col, winCoord.row].WinAnimation();
|
|
}
|
|
}
|