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();
|
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)
|
switch (state)
|
||||||
{
|
{
|
||||||
case GameState.PickRoomOne when room.number != _dicePairOne.Sum():
|
case GameState.PickRoomOne when !room.TryUnlock(_dicePairOne):
|
||||||
case GameState.PickRoomTwo when room.number != _dicePairTwo.Sum():
|
case GameState.PickRoomTwo when !room.TryUnlock(_dicePairTwo):
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,7 +88,7 @@ public class GameManager : MonoBehaviour
|
||||||
if (_dicePairOne.AreBothDiceSelected())
|
if (_dicePairOne.AreBothDiceSelected())
|
||||||
{
|
{
|
||||||
state = GameState.PickRoomOne;
|
state = GameState.PickRoomOne;
|
||||||
HighLightValidRoomsWithNumber(_dicePairOne.Sum());
|
HighLightValidRoomsWithNumber(_dicePairOne);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,14 +96,14 @@ public class GameManager : MonoBehaviour
|
||||||
}
|
}
|
||||||
case GameState.PickDiceTwo:
|
case GameState.PickDiceTwo:
|
||||||
{
|
{
|
||||||
if (!_dicePairTwo.IsDieInPair(die))
|
if (!_dicePairTwo.IsDieInPair(die) && !_dicePairOne.IsDieInPair(die))
|
||||||
{
|
{
|
||||||
_dicePairTwo.SelectDie(die);
|
_dicePairTwo.SelectDie(die);
|
||||||
|
|
||||||
if (_dicePairTwo.AreBothDiceSelected())
|
if (_dicePairTwo.AreBothDiceSelected())
|
||||||
{
|
{
|
||||||
state = GameState.PickRoomTwo;
|
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)
|
foreach (Transform roomTransform in rooms.transform)
|
||||||
{
|
{
|
||||||
Room room = roomTransform.gameObject.GetComponent<Room>();
|
Room room = roomTransform.gameObject.GetComponent<Room>();
|
||||||
if (room.number == number && room.IsValidRoomToExplore())
|
if (room.TryUnlock(pair) && room.IsValidRoomToExplore())
|
||||||
{
|
{
|
||||||
room.HighlightRoomAsOption();
|
room.HighlightRoomAsOption();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,19 @@ using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
enum KeyType
|
||||||
|
{
|
||||||
|
Number,
|
||||||
|
MatchinDice
|
||||||
|
}
|
||||||
|
|
||||||
public class Room : MonoBehaviour
|
public class Room : MonoBehaviour
|
||||||
{
|
{
|
||||||
public int number;
|
[SerializeField] private GameObject numberTextObject;
|
||||||
public GameObject numberTextObject;
|
[SerializeField] private List<GameObject> adjacentRooms;
|
||||||
public List<GameObject> adjacentRooms;
|
[SerializeField] private bool isEntrance;
|
||||||
public bool isEntrance;
|
[SerializeField] private KeyType keyType;
|
||||||
|
[SerializeField] private int number;
|
||||||
public event EventHandler<Room> ValidRoomClicked;
|
public event EventHandler<Room> ValidRoomClicked;
|
||||||
|
|
||||||
bool _isExplored = false;
|
bool _isExplored = false;
|
||||||
|
|
@ -25,7 +32,15 @@ public class Room : MonoBehaviour
|
||||||
}
|
}
|
||||||
|
|
||||||
TextMeshProUGUI numberText = numberTextObject.GetComponent<TextMeshProUGUI>();
|
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() {
|
public void SetRoomExplored() {
|
||||||
|
|
@ -89,4 +104,26 @@ public class Room : MonoBehaviour
|
||||||
}
|
}
|
||||||
return false;
|
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