diff --git a/PuzzleGameProject/Assets/Scripts/DicePair.cs b/PuzzleGameProject/Assets/Scripts/DicePair.cs index f2e2175..b452834 100644 --- a/PuzzleGameProject/Assets/Scripts/DicePair.cs +++ b/PuzzleGameProject/Assets/Scripts/DicePair.cs @@ -43,4 +43,14 @@ public class DicePair { return _pair.Item1.GetResult() + _pair.Item2.GetResult(); } + + public bool DoResultsMatch() + { + if (_pair.Item1.GetResult() == _pair.Item2.GetResult()) + { + return true; + } + + return false; + } } diff --git a/PuzzleGameProject/Assets/Scripts/GameManager.cs b/PuzzleGameProject/Assets/Scripts/GameManager.cs index 98c9981..9878b6b 100644 --- a/PuzzleGameProject/Assets/Scripts/GameManager.cs +++ b/PuzzleGameProject/Assets/Scripts/GameManager.cs @@ -53,8 +53,8 @@ public class GameManager : MonoBehaviour switch (state) { - case GameState.PickRoomOne when room.number != _dicePairOne.Sum(): - case GameState.PickRoomTwo when room.number != _dicePairTwo.Sum(): + case GameState.PickRoomOne when !room.TryUnlock(_dicePairOne): + case GameState.PickRoomTwo when !room.TryUnlock(_dicePairTwo): return; } @@ -88,7 +88,7 @@ public class GameManager : MonoBehaviour if (_dicePairOne.AreBothDiceSelected()) { state = GameState.PickRoomOne; - HighLightValidRoomsWithNumber(_dicePairOne.Sum()); + HighLightValidRoomsWithNumber(_dicePairOne); } } @@ -96,14 +96,14 @@ public class GameManager : MonoBehaviour } case GameState.PickDiceTwo: { - if (!_dicePairTwo.IsDieInPair(die)) + if (!_dicePairTwo.IsDieInPair(die) && !_dicePairOne.IsDieInPair(die)) { _dicePairTwo.SelectDie(die); if (_dicePairTwo.AreBothDiceSelected()) { state = GameState.PickRoomTwo; - HighLightValidRoomsWithNumber(_dicePairTwo.Sum()); + HighLightValidRoomsWithNumber(_dicePairTwo); } } @@ -112,12 +112,12 @@ public class GameManager : MonoBehaviour } } - void HighLightValidRoomsWithNumber(int number) + void HighLightValidRoomsWithNumber(DicePair pair) { foreach (Transform roomTransform in rooms.transform) { Room room = roomTransform.gameObject.GetComponent(); - if (room.number == number && room.IsValidRoomToExplore()) + if (room.TryUnlock(pair) && room.IsValidRoomToExplore()) { room.HighlightRoomAsOption(); } diff --git a/PuzzleGameProject/Assets/Scripts/Room.cs b/PuzzleGameProject/Assets/Scripts/Room.cs index 09f8320..f99ce98 100644 --- a/PuzzleGameProject/Assets/Scripts/Room.cs +++ b/PuzzleGameProject/Assets/Scripts/Room.cs @@ -4,12 +4,19 @@ using TMPro; using UnityEngine; using System.Collections.Generic; +enum KeyType +{ + Number, + MatchinDice +} + public class Room : MonoBehaviour { - public int number; - public GameObject numberTextObject; - public List adjacentRooms; - public bool isEntrance; + [SerializeField] private GameObject numberTextObject; + [SerializeField] private List adjacentRooms; + [SerializeField] private bool isEntrance; + [SerializeField] private KeyType keyType; + [SerializeField] private int number; public event EventHandler ValidRoomClicked; bool _isExplored = false; @@ -25,7 +32,15 @@ public class Room : MonoBehaviour } TextMeshProUGUI numberText = numberTextObject.GetComponent(); - numberText.SetText(number.ToString()); + + if (keyType == KeyType.Number) + { + numberText.SetText(number.ToString()); + } + else if (keyType == KeyType.MatchinDice) + { + numberText.SetText("="); + } } public void SetRoomExplored() { @@ -89,4 +104,26 @@ public class Room : MonoBehaviour } return false; } + + public bool TryUnlock(DicePair pair) + { + switch (keyType) + { + case KeyType.Number: + if (number == pair.Sum()) + { + return true; + } + return false; + case KeyType.MatchinDice: + if (pair.DoResultsMatch()) + { + return true; + } + + return false; + } + + return false; + } }