diff --git a/PuzzleGameProject/Assets/Scenes/Level_0.unity b/PuzzleGameProject/Assets/Scenes/Level_0.unity index fc18975..ac5c7e6 100644 --- a/PuzzleGameProject/Assets/Scenes/Level_0.unity +++ b/PuzzleGameProject/Assets/Scenes/Level_0.unity @@ -1381,6 +1381,10 @@ PrefabInstance: propertyPath: number value: 2 objectReference: {fileID: 0} + - target: {fileID: 2727030095425591755, guid: 92d87e25cc40b3e448e62e8ba0328315, type: 3} + propertyPath: keyType + value: 1 + objectReference: {fileID: 0} - target: {fileID: 2727030095425591755, guid: 92d87e25cc40b3e448e62e8ba0328315, type: 3} propertyPath: isEntrance value: 1 @@ -1913,6 +1917,10 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 1820284206} m_Modifications: + - target: {fileID: -1465197196826248026, guid: 92d87e25cc40b3e448e62e8ba0328315, type: 3} + propertyPath: m_Enabled + value: 1 + objectReference: {fileID: 0} - target: {fileID: 2435349004046080434, guid: 92d87e25cc40b3e448e62e8ba0328315, type: 3} propertyPath: m_Name value: Room (10) @@ -1921,6 +1929,10 @@ PrefabInstance: propertyPath: number value: 0 objectReference: {fileID: 0} + - target: {fileID: 2727030095425591755, guid: 92d87e25cc40b3e448e62e8ba0328315, type: 3} + propertyPath: keyType + value: 1 + objectReference: {fileID: 0} - target: {fileID: 2727030095425591755, guid: 92d87e25cc40b3e448e62e8ba0328315, type: 3} propertyPath: adjacentRooms.Array.size value: 2 diff --git a/PuzzleGameProject/Assets/Scripts/DicePair.cs b/PuzzleGameProject/Assets/Scripts/DicePair.cs index b452834..75c7c9d 100644 --- a/PuzzleGameProject/Assets/Scripts/DicePair.cs +++ b/PuzzleGameProject/Assets/Scripts/DicePair.cs @@ -9,17 +9,41 @@ public class DicePair if (_pair.Item1 == null && _pair.Item2 == null) { _pair.Item1 = die; - die.DieBeingUsed(true, false); + die.DieBeingUsed(false); } else if (_pair.Item2 == null) { _pair.Item2 = die; - _pair.Item1.DieBeingUsed(true, true); - die.DieBeingUsed(true, true); + _pair.Item1.DieBeingUsed(true); + die.DieBeingUsed(true); + } + } + + public void UnselectDie(Die die) + { + if (_pair.Item1 == die) + { + _pair.Item1.ResetDie(); + _pair.Item1 = null; + if (_pair.Item2 != null) + { + _pair.Item2.ResetDie(); + _pair.Item2.DieBeingUsed(false); + } + } + else if (_pair.Item2 == die) + { + _pair.Item2.ResetDie(); + _pair.Item2 = null; + if (_pair.Item1 != null) + { + _pair.Item1.ResetDie(); + _pair.Item1.DieBeingUsed(false); + } } } - public bool IsDieInPair(Die die) + public bool ContainsDie(Die die) { if (_pair.Item1 == die || _pair.Item2 == die) { diff --git a/PuzzleGameProject/Assets/Scripts/Die.cs b/PuzzleGameProject/Assets/Scripts/Die.cs index 9412833..fcd6f63 100644 --- a/PuzzleGameProject/Assets/Scripts/Die.cs +++ b/PuzzleGameProject/Assets/Scripts/Die.cs @@ -37,9 +37,10 @@ public class Die : MonoBehaviour public void ResetDie() { gameObject.GetComponent().color = originalColor; + gameObject.GetComponent().enabled = false; } - public void DieBeingUsed(bool isFirstPair, bool isPairComplete) + public void DieBeingUsed(bool isPairComplete) { if (isPairComplete) { diff --git a/PuzzleGameProject/Assets/Scripts/GameManager.cs b/PuzzleGameProject/Assets/Scripts/GameManager.cs index 9878b6b..9dcd006 100644 --- a/PuzzleGameProject/Assets/Scripts/GameManager.cs +++ b/PuzzleGameProject/Assets/Scripts/GameManager.cs @@ -72,16 +72,11 @@ public class GameManager : MonoBehaviour void DieClicked(object sender, Die die) { - if (state != GameState.PickDiceOne && state != GameState.PickDiceTwo) - { - return; - } - switch (state) { case GameState.PickDiceOne: { - if (!_dicePairOne.IsDieInPair(die)) + if (!_dicePairOne.ContainsDie(die)) { _dicePairOne.SelectDie(die); @@ -91,12 +86,16 @@ public class GameManager : MonoBehaviour HighLightValidRoomsWithNumber(_dicePairOne); } } + else + { + _dicePairOne.UnselectDie(die); + } break; } case GameState.PickDiceTwo: { - if (!_dicePairTwo.IsDieInPair(die) && !_dicePairOne.IsDieInPair(die)) + if (!_dicePairTwo.ContainsDie(die) && !_dicePairOne.ContainsDie(die)) { _dicePairTwo.SelectDie(die); @@ -106,9 +105,29 @@ public class GameManager : MonoBehaviour HighLightValidRoomsWithNumber(_dicePairTwo); } } + else if (_dicePairTwo.ContainsDie(die)) + { + _dicePairTwo.UnselectDie(die); + } break; } + case GameState.PickRoomOne: + if (_dicePairOne.ContainsDie(die)) + { + _dicePairOne.UnselectDie(die); + UnhighLightRoomsAsOptions(); + state = GameState.PickDiceOne; + } + break; + case GameState.PickRoomTwo: + if (_dicePairTwo.ContainsDie(die)) + { + _dicePairTwo.UnselectDie(die); + UnhighLightRoomsAsOptions(); + state = GameState.PickDiceTwo; + } + break; } } @@ -124,6 +143,14 @@ public class GameManager : MonoBehaviour } } + void UnhighLightRoomsAsOptions() + { + foreach (Transform roomTransform in rooms.transform) + { + roomTransform.gameObject.GetComponent().UnhighlightRoomAsOption(); + } + } + private void DiceRolled(object sender, EventArgs e) { if (state == GameState.RollDice) diff --git a/PuzzleGameProject/Assets/Scripts/Room.cs b/PuzzleGameProject/Assets/Scripts/Room.cs index f99ce98..b9fb2f3 100644 --- a/PuzzleGameProject/Assets/Scripts/Room.cs +++ b/PuzzleGameProject/Assets/Scripts/Room.cs @@ -32,7 +32,8 @@ public class Room : MonoBehaviour } TextMeshProUGUI numberText = numberTextObject.GetComponent(); - + _roomNumberOriginalColor = gameObject.GetComponentInChildren().color; + if (keyType == KeyType.Number) { numberText.SetText(number.ToString()); @@ -52,7 +53,6 @@ public class Room : MonoBehaviour public void HighlightRoomAsOption() { - _roomNumberOriginalColor = gameObject.GetComponentInChildren().color; gameObject.GetComponentInChildren().color = Color.blue; }