78 lines
1.9 KiB
C#
78 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
public class TurnHandler : MonoBehaviour
|
|
{
|
|
#region Statication
|
|
|
|
public static TurnHandler instance;
|
|
|
|
private void Awake()
|
|
{
|
|
if (instance != null && instance != this)
|
|
{
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
instance = this;
|
|
}
|
|
|
|
#endregion
|
|
|
|
public List<PlayerEntity> playerEntities = new();
|
|
public List<Enemy> enemyEntities = new();
|
|
public enum GameState {PlayerTurn, EnemyTurn}
|
|
public GameState currentGameState = GameState.PlayerTurn;
|
|
|
|
private int currentEnemy;
|
|
|
|
private void SortEnemies()
|
|
{
|
|
enemyEntities = enemyEntities.OrderBy(o=>o.turnSpeed).ToList();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
SortEnemies();
|
|
}
|
|
|
|
public void UpdateTurns()
|
|
{
|
|
if (currentGameState == GameState.PlayerTurn)
|
|
{
|
|
bool allDone = true;
|
|
foreach (PlayerEntity player in playerEntities)
|
|
{
|
|
if (!player.hasMoved || !player.hasAttacked)
|
|
{
|
|
allDone = false;
|
|
}
|
|
}
|
|
if (allDone)
|
|
{
|
|
foreach (PlayerEntity player in playerEntities)
|
|
{
|
|
player.hasMoved = false;
|
|
player.hasAttacked = false;
|
|
}
|
|
//currentGameState = GameState.EnemyTurn;
|
|
}
|
|
}
|
|
else if (currentGameState == GameState.EnemyTurn)
|
|
{
|
|
enemyEntities[currentEnemy].StartTurn();
|
|
currentEnemy++;
|
|
if (currentEnemy > enemyEntities.Count)
|
|
{
|
|
currentGameState = GameState.PlayerTurn;
|
|
foreach (PlayerEntity player in playerEntities)
|
|
{
|
|
player.hasMoved = false;
|
|
player.hasAttacked = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|