Added roll dice button
This commit is contained in:
parent
d04624edfd
commit
dbef10d80a
10 changed files with 472 additions and 82 deletions
|
|
@ -2,9 +2,11 @@ using System;
|
|||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
|
||||
public enum GameState
|
||||
{
|
||||
RollDice,
|
||||
PickRoomOne,
|
||||
PickRoomTwo,
|
||||
PickDiceOne,
|
||||
|
|
@ -12,28 +14,35 @@ public enum GameState
|
|||
}
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
public GameState state;
|
||||
public GameObject rooms;
|
||||
public GameObject dice;
|
||||
public DiceRoller diceRoller;
|
||||
[SerializeField] private GameState state;
|
||||
[SerializeField] private GameObject rooms;
|
||||
[SerializeField] private DiceRoller diceRoller;
|
||||
|
||||
private (Die, Die) _dicePairOne = (null, null);
|
||||
private (Die, Die) _dicePairTwo = (null, null);
|
||||
private DicePair _dicePairOne = new DicePair();
|
||||
private DicePair _dicePairTwo = new DicePair();
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
state = GameState.PickDiceOne;
|
||||
diceRoller.diceRolled += DiceRolled;
|
||||
foreach (Transform roomTransform in rooms.transform)
|
||||
{
|
||||
roomTransform.gameObject.GetComponent<Room>().ValidRoomClicked += ValidRoomClicked;
|
||||
}
|
||||
|
||||
foreach (Transform diceTransform in dice.transform)
|
||||
foreach (Transform diceTransform in diceRoller.dice.transform)
|
||||
{
|
||||
diceTransform.gameObject.GetComponent<Die>().DieClicked += DieClicked;
|
||||
}
|
||||
diceRoller.RollDice();
|
||||
StartNewTurn();
|
||||
}
|
||||
|
||||
private void StartNewTurn()
|
||||
{
|
||||
state = GameState.RollDice;
|
||||
diceRoller.Enable();
|
||||
diceRoller.ResetDice();
|
||||
_dicePairOne = new DicePair();
|
||||
_dicePairTwo = new DicePair();
|
||||
}
|
||||
|
||||
void ValidRoomClicked(object sender, Room room) {
|
||||
|
|
@ -41,6 +50,14 @@ public class GameManager : MonoBehaviour
|
|||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case GameState.PickRoomOne when room.number != _dicePairOne.Sum():
|
||||
case GameState.PickRoomTwo when room.number != _dicePairTwo.Sum():
|
||||
return;
|
||||
}
|
||||
|
||||
room.SetRoomExplored();
|
||||
if (state == GameState.PickRoomOne)
|
||||
{
|
||||
|
|
@ -48,7 +65,7 @@ public class GameManager : MonoBehaviour
|
|||
}
|
||||
else
|
||||
{
|
||||
// Not implemented
|
||||
StartNewTurn();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -60,43 +77,59 @@ public class GameManager : MonoBehaviour
|
|||
return;
|
||||
}
|
||||
|
||||
if (state == GameState.PickDiceOne)
|
||||
switch (state)
|
||||
{
|
||||
if (_dicePairOne.Item1 == null && _dicePairOne.Item2 == null)
|
||||
case GameState.PickDiceOne:
|
||||
{
|
||||
_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.IsDieInPair(die))
|
||||
{
|
||||
_dicePairOne.SelectDie(die);
|
||||
|
||||
if (_dicePairOne.Item1 != null && _dicePairOne.Item2 != null)
|
||||
{
|
||||
state = GameState.PickRoomOne;
|
||||
if (_dicePairOne.AreBothDiceSelected())
|
||||
{
|
||||
state = GameState.PickRoomOne;
|
||||
HighLightValidRoomsWithNumber(_dicePairOne.Sum());
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(state == GameState.PickDiceTwo)
|
||||
{
|
||||
if (_dicePairTwo.Item1 == null && _dicePairTwo.Item2 == null)
|
||||
case GameState.PickDiceTwo:
|
||||
{
|
||||
_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.IsDieInPair(die))
|
||||
{
|
||||
_dicePairTwo.SelectDie(die);
|
||||
|
||||
if (_dicePairTwo.Item1 != null && _dicePairTwo.Item2 != null)
|
||||
{
|
||||
state = GameState.PickRoomTwo;
|
||||
if (_dicePairTwo.AreBothDiceSelected())
|
||||
{
|
||||
state = GameState.PickRoomTwo;
|
||||
HighLightValidRoomsWithNumber(_dicePairTwo.Sum());
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HighLightValidRoomsWithNumber(int number)
|
||||
{
|
||||
foreach (Transform roomTransform in rooms.transform)
|
||||
{
|
||||
Room room = roomTransform.gameObject.GetComponent<Room>();
|
||||
if (room.number == number && room.IsValidRoomToExplore())
|
||||
{
|
||||
room.HighlightRoomAsOption();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DiceRolled(object sender, EventArgs e)
|
||||
{
|
||||
if (state == GameState.RollDice)
|
||||
{
|
||||
diceRoller.Disable();
|
||||
state = GameState.PickDiceOne;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue