Added the ability to use a limited number of black dice.
This commit is contained in:
parent
0e869555d3
commit
bcfd42147b
12 changed files with 1058 additions and 26 deletions
8
PuzzleGameProject/Assets/Scripts/Abilities.meta
Normal file
8
PuzzleGameProject/Assets/Scripts/Abilities.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 69edbaa8bf5994173afe7cd0eef03075
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Abilities
|
||||
{
|
||||
public class BlackDieAbility : MonoBehaviour
|
||||
{
|
||||
public static event Action AbilitySelected;
|
||||
|
||||
[SerializeField] private GameObject abilityUseOne;
|
||||
[SerializeField] private GameObject abilityUseTwo;
|
||||
[SerializeField] private GameObject abilityUseThree;
|
||||
[SerializeField] private int _uses = 3;
|
||||
|
||||
private GameObject[] _usesUsed;
|
||||
private bool _canClick;
|
||||
|
||||
private void OnEnable() {
|
||||
GameManager.StateChanged += HandleStateChanged;
|
||||
}
|
||||
|
||||
private void OnDisable() {
|
||||
GameManager.StateChanged -= HandleStateChanged;
|
||||
}
|
||||
|
||||
private void Start() {
|
||||
_usesUsed = new GameObject[_uses];
|
||||
abilityUseOne.GetComponent<Button>().onClick.AddListener(() => UseClicked(abilityUseOne));
|
||||
abilityUseTwo.GetComponent<Button>().onClick.AddListener(() => UseClicked(abilityUseTwo));
|
||||
abilityUseThree.GetComponent<Button>().onClick.AddListener(() => UseClicked(abilityUseThree));
|
||||
}
|
||||
|
||||
private void UseClicked(GameObject abilityUseObject) {
|
||||
if (!_canClick) return;
|
||||
|
||||
if (_uses > 0)
|
||||
{
|
||||
_usesUsed[_uses - 1] = abilityUseObject;
|
||||
MarkUseUsed(abilityUseObject);
|
||||
AbilitySelected?.Invoke();
|
||||
_uses -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
private void MarkUseUsed(GameObject useObject) {
|
||||
useObject.GetComponentInChildren<TextMeshProUGUI>().text = "X";
|
||||
}
|
||||
|
||||
private void UnmarkUseUsed(GameObject useObject) {
|
||||
useObject.GetComponentInChildren<TextMeshProUGUI>().text = string.Empty;
|
||||
}
|
||||
|
||||
public void AbilitySelectedButNotUsed() {
|
||||
UnmarkUseUsed(_usesUsed[_uses - 1]);
|
||||
_uses += 1;
|
||||
}
|
||||
|
||||
private void HandleStateChanged(GameState state) {
|
||||
switch (state)
|
||||
{
|
||||
case GameState.PickDiceOne:
|
||||
case GameState.PickDiceTwo:
|
||||
_canClick = true;
|
||||
break;
|
||||
default:
|
||||
_canClick = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 79af16baa8fbe4744817b63d2b6f2007
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
using System;
|
||||
using Abilities;
|
||||
using TMPro;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
|
@ -17,13 +19,22 @@ public class Die : MonoBehaviour
|
|||
private Color originalColor;
|
||||
private bool _isClickable = false;
|
||||
private bool _selected = false;
|
||||
private bool _blackDieAbilityUsed = false;
|
||||
public event Action<Die> DieSelected;
|
||||
public event Action<Die> DieUnselected;
|
||||
|
||||
private void Start() {
|
||||
GameManager.Instance.StateChanged += HandleStateChange;
|
||||
dieButton.onClick.AddListener(DiePressed);
|
||||
private void OnEnable() {
|
||||
GameManager.StateChanged += HandleStateChange;
|
||||
BlackDieAbility.AbilitySelected += HandleOnBlackDieAbilitySelected;
|
||||
}
|
||||
|
||||
private void OnDisable() {
|
||||
GameManager.StateChanged -= HandleStateChange;
|
||||
BlackDieAbility.AbilitySelected -= HandleOnBlackDieAbilitySelected;
|
||||
}
|
||||
|
||||
private void Start() {
|
||||
dieButton.onClick.AddListener(DiePressed);
|
||||
originalColor = gameObject.GetComponent<Image>().color;
|
||||
}
|
||||
|
||||
|
|
@ -59,7 +70,7 @@ public class Die : MonoBehaviour
|
|||
|
||||
private void DiePressed()
|
||||
{
|
||||
if (!_isClickable) return;
|
||||
if (!_isClickable || (color == DiceColor.Black && !_blackDieAbilityUsed)) return;
|
||||
|
||||
if (_selected)
|
||||
{
|
||||
|
|
@ -101,4 +112,8 @@ public class Die : MonoBehaviour
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleOnBlackDieAbilitySelected() {
|
||||
_blackDieAbilityUsed = true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ using System;
|
|||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
using System.Collections.Generic;
|
||||
using Abilities;
|
||||
using TMPro;
|
||||
using Unity.VisualScripting;
|
||||
|
||||
|
|
@ -15,8 +16,6 @@ public enum GameState
|
|||
}
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
public static GameManager Instance { get; private set; }
|
||||
|
||||
[SerializeField] public GameState state;
|
||||
[SerializeField] private GameObject rooms;
|
||||
[SerializeField] private DiceRoller diceRoller;
|
||||
|
|
@ -25,15 +24,7 @@ public class GameManager : MonoBehaviour
|
|||
|
||||
private DicePair _dicePairOne = new();
|
||||
private DicePair _dicePairTwo = new();
|
||||
public event Action<GameState> StateChanged;
|
||||
|
||||
private void Awake() {
|
||||
if (Instance != null && Instance != this) {
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
Instance = this;
|
||||
}
|
||||
public static event Action<GameState> StateChanged;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ using Button = UnityEngine.UI.Button;
|
|||
public class PassManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Button passButton;
|
||||
[SerializeField] private GameManager gameManager;
|
||||
|
||||
public event EventHandler PassRequested;
|
||||
|
||||
|
|
@ -15,7 +14,7 @@ public class PassManager : MonoBehaviour
|
|||
void Start()
|
||||
{
|
||||
passButton.onClick.AddListener(OnPassClicked);
|
||||
gameManager.StateChanged += HandleStateChange;
|
||||
GameManager.StateChanged += HandleStateChange;
|
||||
}
|
||||
|
||||
private void HandleStateChange(GameState state) {
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public class Room : MonoBehaviour
|
|||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start() {
|
||||
GameManager.Instance.StateChanged += HandleStateChange;
|
||||
GameManager.StateChanged += HandleStateChange;
|
||||
|
||||
if (isEntrance) {
|
||||
SetPropertiesOfEntrance();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue