using System; using UnityEngine; using Object = UnityEngine.Object; using System.Collections.Generic; public enum GameState { PickRoomOne, PickRoomTwo, PickDiceOne, PickDiceTwo, } public class GameManager : MonoBehaviour { public GameState state; public GameObject rooms; public GameObject dice; public DiceRoller diceRoller; private (Die, Die) _dicePairOne = (null, null); private (Die, Die) _dicePairTwo = (null, null); // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { state = GameState.PickDiceOne; foreach (Transform roomTransform in rooms.transform) { roomTransform.gameObject.GetComponent().ValidRoomClicked += ValidRoomClicked; } foreach (Transform diceTransform in dice.transform) { diceTransform.gameObject.GetComponent().DieClicked += DieClicked; } diceRoller.RollDice(); } void ValidRoomClicked(object sender, Room room) { if (state != GameState.PickRoomOne && state != GameState.PickRoomTwo) { return; } room.SetRoomExplored(); if (state == GameState.PickRoomOne) { state = GameState.PickDiceTwo; } else { // Not implemented } } void DieClicked(object sender, Die die) { if (state != GameState.PickDiceOne && state != GameState.PickDiceTwo) { return; } if (state == GameState.PickDiceOne) { if (_dicePairOne.Item1 == null && _dicePairOne.Item2 == null) { _dicePairOne.Item1 = die; die.DieBeingUsed(true, false); } else if (_dicePairOne.Item2 == null) { _dicePairOne.Item2 = die; _dicePairOne.Item1.DieBeingUsed(true, true); die.DieBeingUsed(true, true); } if (_dicePairOne.Item1 != null && _dicePairOne.Item2 != null) { state = GameState.PickRoomOne; } } else if(state == GameState.PickDiceTwo) { if (_dicePairTwo.Item1 == null && _dicePairTwo.Item2 == null) { _dicePairTwo.Item1 = die; die.DieBeingUsed(false, false); } else if (_dicePairTwo.Item2 == null) { _dicePairTwo.Item2 = die; _dicePairTwo.Item1.DieBeingUsed(false, true); die.DieBeingUsed(false, true); } if (_dicePairTwo.Item1 != null && _dicePairTwo.Item2 != null) { state = GameState.PickRoomTwo; } } } }