Refactored clicking on dice and rooms so that logic is moved out of the game manager
This commit is contained in:
parent
ede5ef1533
commit
e7ea8302ad
8 changed files with 150 additions and 67 deletions
|
|
@ -20,12 +20,12 @@ public class Room : MonoBehaviour
|
|||
public event EventHandler<Room> ValidRoomClicked;
|
||||
|
||||
bool _isExplored = false;
|
||||
|
||||
private bool _isClickable = true;
|
||||
private Color _roomNumberOriginalColor;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start() {
|
||||
|
||||
GameManager.Instance.StateChanged += HandleStateChange;
|
||||
|
||||
if (isEntrance) {
|
||||
SetPropertiesOfEntrance();
|
||||
|
|
@ -44,6 +44,10 @@ public class Room : MonoBehaviour
|
|||
}
|
||||
}
|
||||
|
||||
private void OnEnable() {
|
||||
|
||||
}
|
||||
|
||||
public void SetRoomExplored() {
|
||||
_isExplored = true;
|
||||
UnhighlightRoomAsOption();
|
||||
|
|
@ -66,12 +70,11 @@ public class Room : MonoBehaviour
|
|||
isEntrance = true;
|
||||
}
|
||||
|
||||
IEnumerator OnMouseDown()
|
||||
{
|
||||
void OnMouseDown() {
|
||||
if (!_isClickable) return;
|
||||
if (IsValidRoomToExplore()) {
|
||||
OnValidRoomClicked();
|
||||
}
|
||||
yield return null;
|
||||
}
|
||||
|
||||
protected virtual void OnValidRoomClicked() {
|
||||
|
|
@ -126,4 +129,19 @@ public class Room : MonoBehaviour
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void HandleStateChange(GameState state) {
|
||||
switch (state)
|
||||
{
|
||||
case GameState.PickDiceOne:
|
||||
case GameState.PickDiceTwo:
|
||||
case GameState.RollDice:
|
||||
_isClickable = false;
|
||||
break;
|
||||
case GameState.PickRoomTwo:
|
||||
case GameState.PickRoomOne:
|
||||
_isClickable = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue