diff --git a/PuzzleGameProject/Assets/Prefabs/Black Die.prefab b/PuzzleGameProject/Assets/Prefabs/Black Die.prefab index 41fdb61..796f4e3 100644 --- a/PuzzleGameProject/Assets/Prefabs/Black Die.prefab +++ b/PuzzleGameProject/Assets/Prefabs/Black Die.prefab @@ -149,6 +149,7 @@ GameObject: - component: {fileID: 6156510816236760012} - component: {fileID: 5247104008048868212} - component: {fileID: 6084228361150234175} + - component: {fileID: -7124398980878284295} m_Layer: 5 m_Name: Black Die m_TagString: BlackDie @@ -270,3 +271,19 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: edf2cd8ae662a415898ed6567457f32d, type: 3} m_Name: m_EditorClassIdentifier: + dieButton: {fileID: 5247104008048868212} +--- !u!114 &-7124398980878284295 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7874367151511621086} + m_Enabled: 0 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e19747de3f5aca642ab2be37e372fb86, type: 3} + m_Name: + m_EditorClassIdentifier: + m_EffectColor: {r: 0.04705883, g: 0.79215693, b: 0, a: 0.5} + m_EffectDistance: {x: 1, y: -1} + m_UseGraphicAlpha: 1 diff --git a/PuzzleGameProject/Assets/Prefabs/White Die.prefab b/PuzzleGameProject/Assets/Prefabs/White Die.prefab index 588c282..ea8e7fc 100644 --- a/PuzzleGameProject/Assets/Prefabs/White Die.prefab +++ b/PuzzleGameProject/Assets/Prefabs/White Die.prefab @@ -149,6 +149,7 @@ GameObject: - component: {fileID: 6156510816236760012} - component: {fileID: 5247104008048868212} - component: {fileID: 6084228361150234175} + - component: {fileID: 6840580988586272823} m_Layer: 5 m_Name: White Die m_TagString: WhiteDie @@ -257,7 +258,19 @@ MonoBehaviour: m_TargetGraphic: {fileID: 6156510816236760012} m_OnClick: m_PersistentCalls: - m_Calls: [] + m_Calls: + - m_Target: {fileID: 0} + m_TargetAssemblyTypeName: + m_MethodName: + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 --- !u!114 &6084228361150234175 MonoBehaviour: m_ObjectHideFlags: 0 @@ -270,3 +283,19 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: edf2cd8ae662a415898ed6567457f32d, type: 3} m_Name: m_EditorClassIdentifier: + dieButton: {fileID: 5247104008048868212} +--- !u!114 &6840580988586272823 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7874367151511621086} + m_Enabled: 0 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e19747de3f5aca642ab2be37e372fb86, type: 3} + m_Name: + m_EditorClassIdentifier: + m_EffectColor: {r: 0.045367185, g: 0.7924528, b: 0, a: 0.5} + m_EffectDistance: {x: 1, y: -1} + m_UseGraphicAlpha: 1 diff --git a/PuzzleGameProject/Assets/Scenes/Level_0.unity b/PuzzleGameProject/Assets/Scenes/Level_0.unity index e1fbae6..0caa9cf 100644 --- a/PuzzleGameProject/Assets/Scenes/Level_0.unity +++ b/PuzzleGameProject/Assets/Scenes/Level_0.unity @@ -376,6 +376,7 @@ MonoBehaviour: m_EditorClassIdentifier: state: 0 rooms: {fileID: 1820284205} + dice: {fileID: 925126051} diceRoller: {fileID: 126339305} --- !u!114 &126339305 MonoBehaviour: diff --git a/PuzzleGameProject/Assets/Scripts/ColorHelper.cs b/PuzzleGameProject/Assets/Scripts/ColorHelper.cs new file mode 100644 index 0000000..8bf714d --- /dev/null +++ b/PuzzleGameProject/Assets/Scripts/ColorHelper.cs @@ -0,0 +1,17 @@ +using UnityEngine; + +public static class ColorHelper +{ + public static Color OkayGreen = new Color(12f, 202f, 0f); + + public static Color AddColorTint(Color originalColor, Color tintColor, float tintIntensity) + { + // Clamp the tintIntensity between 0 and 1 + tintIntensity = Mathf.Clamp01(tintIntensity); + + // Blend the original color with the tint color + Color blendedColor = Color.Lerp(originalColor, tintColor, tintIntensity); + + return blendedColor; + } +} diff --git a/PuzzleGameProject/Assets/Scripts/ColorUtility.cs.meta b/PuzzleGameProject/Assets/Scripts/ColorHelper.cs.meta similarity index 100% rename from PuzzleGameProject/Assets/Scripts/ColorUtility.cs.meta rename to PuzzleGameProject/Assets/Scripts/ColorHelper.cs.meta diff --git a/PuzzleGameProject/Assets/Scripts/ColorUtility.cs b/PuzzleGameProject/Assets/Scripts/ColorUtility.cs deleted file mode 100644 index 72810d2..0000000 --- a/PuzzleGameProject/Assets/Scripts/ColorUtility.cs +++ /dev/null @@ -1,18 +0,0 @@ -using UnityEngine; - -public static class ColorUtility -{ - public static Color AddGreyShade(Color originalColor, float greyIntensity) - { - // Clamp the greyIntensity between 0 and 1 - greyIntensity = Mathf.Clamp01(greyIntensity); - - // Define the grey color (e.g., medium grey) - Color grey = new Color(0.5f, 0.5f, 0.5f); // RGB (128, 128, 128) - - // Blend the original color with the grey color - Color blendedColor = Color.Lerp(originalColor, grey, greyIntensity); - - return blendedColor; - } -} diff --git a/PuzzleGameProject/Assets/Scripts/Die.cs b/PuzzleGameProject/Assets/Scripts/Die.cs index f57836b..96ec0b3 100644 --- a/PuzzleGameProject/Assets/Scripts/Die.cs +++ b/PuzzleGameProject/Assets/Scripts/Die.cs @@ -6,13 +6,55 @@ using UnityEngine.UI; public class Die : MonoBehaviour { private int _result = 0; + [SerializeField] private Button dieButton = null; // assign in the editor + public event EventHandler DieClicked; + + private void Start() + { + dieButton.onClick.AddListener(() => { DiePressed();}); + } public void SetResult(int result) { _result = result; gameObject.GetComponentInChildren().text = _result.ToString(); } + public int GetResult() + { + return _result; + } + public void ClearDie() { gameObject.GetComponent().text = String.Empty; } + + public void DieBeingUsed(bool isFirstPair, bool isPairComplete) + { + if (isPairComplete) + { + // Signify that both dice have been selected + DieSelectedAndPairComplete(); + } + else + { + // Signify that the die is selected but the pair is not complete + DieSelectedButPairNotComplete(); + } + } + + private void DiePressed() + { + DieClicked?.Invoke(this, this); + } + + private void DieSelectedButPairNotComplete() + { + gameObject.GetComponent().enabled = true; + } + + private void DieSelectedAndPairComplete() + { + gameObject.GetComponent().color = + ColorHelper.AddColorTint(gameObject.GetComponent().color, ColorHelper.OkayGreen, 0.5f); + } } diff --git a/PuzzleGameProject/Assets/Scripts/GameManager.cs b/PuzzleGameProject/Assets/Scripts/GameManager.cs index 68fc765..d22ffb7 100644 --- a/PuzzleGameProject/Assets/Scripts/GameManager.cs +++ b/PuzzleGameProject/Assets/Scripts/GameManager.cs @@ -1,37 +1,102 @@ using System; using UnityEngine; using Object = UnityEngine.Object; +using System.Collections.Generic; public enum GameState { - PickRoom, - RollDice + 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.RollDice; + 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.PickRoom) + if (state != GameState.PickRoomOne && state != GameState.PickRoomTwo) { - room.SetRoomExplored(); + 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; + } } } - - void SetUpDice() { - - } } diff --git a/PuzzleGameProject/Assets/Scripts/Room.cs b/PuzzleGameProject/Assets/Scripts/Room.cs index 8b244e5..a9d1a88 100644 --- a/PuzzleGameProject/Assets/Scripts/Room.cs +++ b/PuzzleGameProject/Assets/Scripts/Room.cs @@ -29,7 +29,7 @@ public class Room : MonoBehaviour public void SetRoomExplored() { _isExplored = true; gameObject.GetComponent().color = - ColorUtility.AddGreyShade(gameObject.GetComponent().color, 0.5f); + ColorHelper.AddColorTint(gameObject.GetComponent().color, Color.grey, 0.5f); } void SetPropertiesOfEntrance() {