Implemented matching dice rooms
This commit is contained in:
parent
dbef10d80a
commit
1b55b43f34
3 changed files with 59 additions and 12 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Room>();
|
||||
if (room.number == number && room.IsValidRoomToExplore())
|
||||
if (room.TryUnlock(pair) && room.IsValidRoomToExplore())
|
||||
{
|
||||
room.HighlightRoomAsOption();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<GameObject> adjacentRooms;
|
||||
public bool isEntrance;
|
||||
[SerializeField] private GameObject numberTextObject;
|
||||
[SerializeField] private List<GameObject> adjacentRooms;
|
||||
[SerializeField] private bool isEntrance;
|
||||
[SerializeField] private KeyType keyType;
|
||||
[SerializeField] private int number;
|
||||
public event EventHandler<Room> ValidRoomClicked;
|
||||
|
||||
bool _isExplored = false;
|
||||
|
|
@ -25,7 +32,15 @@ public class Room : MonoBehaviour
|
|||
}
|
||||
|
||||
TextMeshProUGUI numberText = numberTextObject.GetComponent<TextMeshProUGUI>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue