Implemented unselecting dice selection

This commit is contained in:
Max 2025-01-21 15:55:10 +01:00
parent 1b55b43f34
commit 31917ba415
5 changed files with 78 additions and 14 deletions

View file

@ -1381,6 +1381,10 @@ PrefabInstance:
propertyPath: number propertyPath: number
value: 2 value: 2
objectReference: {fileID: 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} - target: {fileID: 2727030095425591755, guid: 92d87e25cc40b3e448e62e8ba0328315, type: 3}
propertyPath: isEntrance propertyPath: isEntrance
value: 1 value: 1
@ -1913,6 +1917,10 @@ PrefabInstance:
serializedVersion: 3 serializedVersion: 3
m_TransformParent: {fileID: 1820284206} m_TransformParent: {fileID: 1820284206}
m_Modifications: m_Modifications:
- target: {fileID: -1465197196826248026, guid: 92d87e25cc40b3e448e62e8ba0328315, type: 3}
propertyPath: m_Enabled
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2435349004046080434, guid: 92d87e25cc40b3e448e62e8ba0328315, type: 3} - target: {fileID: 2435349004046080434, guid: 92d87e25cc40b3e448e62e8ba0328315, type: 3}
propertyPath: m_Name propertyPath: m_Name
value: Room (10) value: Room (10)
@ -1921,6 +1929,10 @@ PrefabInstance:
propertyPath: number propertyPath: number
value: 0 value: 0
objectReference: {fileID: 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} - target: {fileID: 2727030095425591755, guid: 92d87e25cc40b3e448e62e8ba0328315, type: 3}
propertyPath: adjacentRooms.Array.size propertyPath: adjacentRooms.Array.size
value: 2 value: 2

View file

@ -9,17 +9,41 @@ public class DicePair
if (_pair.Item1 == null && _pair.Item2 == null) if (_pair.Item1 == null && _pair.Item2 == null)
{ {
_pair.Item1 = die; _pair.Item1 = die;
die.DieBeingUsed(true, false); die.DieBeingUsed(false);
} }
else if (_pair.Item2 == null) else if (_pair.Item2 == null)
{ {
_pair.Item2 = die; _pair.Item2 = die;
_pair.Item1.DieBeingUsed(true, true); _pair.Item1.DieBeingUsed(true);
die.DieBeingUsed(true, true); die.DieBeingUsed(true);
} }
} }
public bool IsDieInPair(Die die) 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 ContainsDie(Die die)
{ {
if (_pair.Item1 == die || _pair.Item2 == die) if (_pair.Item1 == die || _pair.Item2 == die)
{ {

View file

@ -37,9 +37,10 @@ public class Die : MonoBehaviour
public void ResetDie() public void ResetDie()
{ {
gameObject.GetComponent<Image>().color = originalColor; gameObject.GetComponent<Image>().color = originalColor;
gameObject.GetComponent<Outline>().enabled = false;
} }
public void DieBeingUsed(bool isFirstPair, bool isPairComplete) public void DieBeingUsed(bool isPairComplete)
{ {
if (isPairComplete) if (isPairComplete)
{ {

View file

@ -72,16 +72,11 @@ public class GameManager : MonoBehaviour
void DieClicked(object sender, Die die) void DieClicked(object sender, Die die)
{ {
if (state != GameState.PickDiceOne && state != GameState.PickDiceTwo)
{
return;
}
switch (state) switch (state)
{ {
case GameState.PickDiceOne: case GameState.PickDiceOne:
{ {
if (!_dicePairOne.IsDieInPair(die)) if (!_dicePairOne.ContainsDie(die))
{ {
_dicePairOne.SelectDie(die); _dicePairOne.SelectDie(die);
@ -91,12 +86,16 @@ public class GameManager : MonoBehaviour
HighLightValidRoomsWithNumber(_dicePairOne); HighLightValidRoomsWithNumber(_dicePairOne);
} }
} }
else
{
_dicePairOne.UnselectDie(die);
}
break; break;
} }
case GameState.PickDiceTwo: case GameState.PickDiceTwo:
{ {
if (!_dicePairTwo.IsDieInPair(die) && !_dicePairOne.IsDieInPair(die)) if (!_dicePairTwo.ContainsDie(die) && !_dicePairOne.ContainsDie(die))
{ {
_dicePairTwo.SelectDie(die); _dicePairTwo.SelectDie(die);
@ -106,9 +105,29 @@ public class GameManager : MonoBehaviour
HighLightValidRoomsWithNumber(_dicePairTwo); HighLightValidRoomsWithNumber(_dicePairTwo);
} }
} }
else if (_dicePairTwo.ContainsDie(die))
{
_dicePairTwo.UnselectDie(die);
}
break; 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<Room>().UnhighlightRoomAsOption();
}
}
private void DiceRolled(object sender, EventArgs e) private void DiceRolled(object sender, EventArgs e)
{ {
if (state == GameState.RollDice) if (state == GameState.RollDice)

View file

@ -32,6 +32,7 @@ public class Room : MonoBehaviour
} }
TextMeshProUGUI numberText = numberTextObject.GetComponent<TextMeshProUGUI>(); TextMeshProUGUI numberText = numberTextObject.GetComponent<TextMeshProUGUI>();
_roomNumberOriginalColor = gameObject.GetComponentInChildren<TextMeshProUGUI>().color;
if (keyType == KeyType.Number) if (keyType == KeyType.Number)
{ {
@ -52,7 +53,6 @@ public class Room : MonoBehaviour
public void HighlightRoomAsOption() public void HighlightRoomAsOption()
{ {
_roomNumberOriginalColor = gameObject.GetComponentInChildren<TextMeshProUGUI>().color;
gameObject.GetComponentInChildren<TextMeshProUGUI>().color = Color.blue; gameObject.GetComponentInChildren<TextMeshProUGUI>().color = Color.blue;
} }