Implemented the functionality for monster rooms.
This commit is contained in:
parent
6a309804ad
commit
aa49815fb9
16 changed files with 1182 additions and 71 deletions
|
|
@ -39,11 +39,11 @@ public class DiceRoller: MonoBehaviour
|
|||
_rolledBlackDice.Clear();
|
||||
for (int i = 0; i < NUMBER_OF_WHITE_DICE; i++)
|
||||
{
|
||||
_rolledWhiteDice.Add(_randomGen.Next(1,6));
|
||||
_rolledWhiteDice.Add(_randomGen.Next(1,7));
|
||||
}
|
||||
for (int i = 0; i < NUMBER_OF_BLACK_DICE; i++)
|
||||
{
|
||||
_rolledBlackDice.Add(_randomGen.Next(1,6));
|
||||
_rolledBlackDice.Add(_randomGen.Next(1,7));
|
||||
}
|
||||
diceRolled?.Invoke(this, EventArgs.Empty);
|
||||
UpdateGUI();
|
||||
|
|
|
|||
8
PuzzleGameProject/Assets/Scripts/Rooms.meta
Normal file
8
PuzzleGameProject/Assets/Scripts/Rooms.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 78d0e4d369ddb4b2faafc371989b76ca
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
50
PuzzleGameProject/Assets/Scripts/Rooms/EmptyRoom.cs
Normal file
50
PuzzleGameProject/Assets/Scripts/Rooms/EmptyRoom.cs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class EmptyRoom : Room
|
||||
{
|
||||
[SerializeField] private GameObject numberTextObject;
|
||||
[SerializeField] private int number;
|
||||
|
||||
protected override void InitializeRoom() {
|
||||
base.InitializeRoom();
|
||||
TextMeshProUGUI numberText = numberTextObject.GetComponent<TextMeshProUGUI>();
|
||||
if (keyType == KeyType.Number)
|
||||
{
|
||||
numberText.SetText(number.ToString());
|
||||
}
|
||||
else if (keyType == KeyType.MatchingDice)
|
||||
{
|
||||
numberText.SetText("=");
|
||||
}
|
||||
}
|
||||
|
||||
public override bool TryUnlock(DicePair pair)
|
||||
{
|
||||
switch (keyType)
|
||||
{
|
||||
case KeyType.Number:
|
||||
if (number == pair.Sum())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case KeyType.MatchingDice:
|
||||
if (pair.DoResultsMatch())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void SetRoomExplored() {
|
||||
_isExplored = true;
|
||||
UnhighlightRoomAsOption();
|
||||
gameObject.GetComponent<SpriteRenderer>().color =
|
||||
ColorHelper.AddColorTint(gameObject.GetComponent<SpriteRenderer>().color, Color.grey, 0.5f);
|
||||
}
|
||||
}
|
||||
2
PuzzleGameProject/Assets/Scripts/Rooms/EmptyRoom.cs.meta
Normal file
2
PuzzleGameProject/Assets/Scripts/Rooms/EmptyRoom.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a0eb90a8b6576487b8e5fac5c80e781d
|
||||
16
PuzzleGameProject/Assets/Scripts/Rooms/Key.cs
Normal file
16
PuzzleGameProject/Assets/Scripts/Rooms/Key.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class Key : MonoBehaviour
|
||||
{
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
2
PuzzleGameProject/Assets/Scripts/Rooms/Key.cs.meta
Normal file
2
PuzzleGameProject/Assets/Scripts/Rooms/Key.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 65db8ffa325fb48e89716418fa310bca
|
||||
53
PuzzleGameProject/Assets/Scripts/Rooms/Monster Room.cs
Normal file
53
PuzzleGameProject/Assets/Scripts/Rooms/Monster Room.cs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
|
||||
public class MonsterRoom : Room
|
||||
{
|
||||
[SerializeField] private List<int> locks = new();
|
||||
[SerializeField] private GameObject numberTextObject;
|
||||
[SerializeField] private int _health; // Number of times the room needs to be unlocked before becoming explored.
|
||||
|
||||
protected override void InitializeRoom() {
|
||||
base.InitializeRoom();
|
||||
|
||||
// Create the lock numbers on the room.
|
||||
numberTextObject.GetComponent<TextMeshProUGUI>().text = locks[0].ToString();
|
||||
GameObject lockToDuplicate = numberTextObject;
|
||||
for (int i = 1; i < locks.Count; i++)
|
||||
{
|
||||
lockToDuplicate = DuplicateToTheLeft(lockToDuplicate, ((RectTransform)lockToDuplicate.transform).rect.width);
|
||||
lockToDuplicate.GetComponent<TextMeshProUGUI>().text = locks[i].ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public override bool TryUnlock(DicePair pair) {
|
||||
foreach (int lockNumber in locks)
|
||||
{
|
||||
if (pair.Sum() == lockNumber)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void SetRoomExplored() {
|
||||
_health -= 1;
|
||||
if (_health == 0)
|
||||
{
|
||||
_isExplored = true;
|
||||
UnhighlightRoomAsOption();
|
||||
gameObject.GetComponent<SpriteRenderer>().color =
|
||||
ColorHelper.AddColorTint(gameObject.GetComponent<SpriteRenderer>().color, Color.grey, 0.5f);
|
||||
}
|
||||
}
|
||||
|
||||
private GameObject DuplicateToTheLeft(GameObject original, float offset) {
|
||||
GameObject clone = Instantiate(original, original.transform.parent);
|
||||
clone.transform.localPosition -= new Vector3(offset, 0, 0);
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7646eec3a0fb541528b0d43bb830e4bf
|
||||
|
|
@ -5,25 +5,23 @@ using UnityEngine;
|
|||
using System.Collections.Generic;
|
||||
using Unity.VisualScripting;
|
||||
|
||||
internal enum KeyType
|
||||
public enum KeyType
|
||||
{
|
||||
Number,
|
||||
MatchingDice
|
||||
}
|
||||
|
||||
public class Room : MonoBehaviour
|
||||
public abstract class Room : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private GameObject numberTextObject;
|
||||
[SerializeField] private List<GameObject> adjacentRooms;
|
||||
[SerializeField] private bool isEntrance;
|
||||
[SerializeField] private KeyType keyType;
|
||||
[SerializeField] private int number;
|
||||
[SerializeField] protected KeyType keyType;
|
||||
public event EventHandler<Room> ValidRoomClicked;
|
||||
|
||||
bool _isExplored = false;
|
||||
private bool _isClickable = true;
|
||||
private Color _roomNumberOriginalColor;
|
||||
|
||||
protected bool _isExplored = false;
|
||||
private bool _isClickable = true;
|
||||
|
||||
private void OnEnable() {
|
||||
GameManager.StateChanged += HandleStateChange;
|
||||
GameManager.DiceSelected += HandleDiceSelected;
|
||||
|
|
@ -38,36 +36,24 @@ public class Room : MonoBehaviour
|
|||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start() {
|
||||
InitializeRoom();
|
||||
_roomNumberOriginalColor = gameObject.GetComponentInChildren<TextMeshProUGUI>().color;
|
||||
}
|
||||
|
||||
public abstract void SetRoomExplored();
|
||||
|
||||
protected virtual void InitializeRoom() {
|
||||
if (isEntrance) {
|
||||
SetPropertiesOfEntrance();
|
||||
}
|
||||
|
||||
TextMeshProUGUI numberText = numberTextObject.GetComponent<TextMeshProUGUI>();
|
||||
_roomNumberOriginalColor = gameObject.GetComponentInChildren<TextMeshProUGUI>().color;
|
||||
|
||||
if (keyType == KeyType.Number)
|
||||
{
|
||||
numberText.SetText(number.ToString());
|
||||
}
|
||||
else if (keyType == KeyType.MatchingDice)
|
||||
{
|
||||
numberText.SetText("=");
|
||||
}
|
||||
}
|
||||
|
||||
public void SetRoomExplored() {
|
||||
_isExplored = true;
|
||||
UnhighlightRoomAsOption();
|
||||
gameObject.GetComponent<SpriteRenderer>().color =
|
||||
ColorHelper.AddColorTint(gameObject.GetComponent<SpriteRenderer>().color, Color.grey, 0.5f);
|
||||
}
|
||||
|
||||
private void HighlightRoomAsOption()
|
||||
protected void HighlightRoomAsOption()
|
||||
{
|
||||
gameObject.GetComponentInChildren<TextMeshProUGUI>().color = Color.blue;
|
||||
}
|
||||
|
||||
private void UnhighlightRoomAsOption()
|
||||
protected void UnhighlightRoomAsOption()
|
||||
{
|
||||
gameObject.GetComponentInChildren<TextMeshProUGUI>().color = _roomNumberOriginalColor;
|
||||
}
|
||||
|
|
@ -114,28 +100,8 @@ 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.MatchingDice:
|
||||
if (pair.DoResultsMatch())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
public abstract bool TryUnlock(DicePair pair);
|
||||
|
||||
private void HandleStateChange(GameState state) {
|
||||
UnhighlightRoomAsOption();
|
||||
Loading…
Add table
Add a link
Reference in a new issue