Implemented both dice selections
This commit is contained in:
parent
2b08dc425f
commit
d04624edfd
9 changed files with 182 additions and 29 deletions
17
PuzzleGameProject/Assets/Scripts/ColorHelper.cs
Normal file
17
PuzzleGameProject/Assets/Scripts/ColorHelper.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
using UnityEngine;
|
||||
|
||||
public static class ColorHelper
|
||||
{
|
||||
public static Color OkayGreen = new Color(12f, 202f, 0f);
|
||||
|
||||
public static Color AddColorTint(Color originalColor, Color tintColor, float tintIntensity)
|
||||
{
|
||||
// Clamp the tintIntensity between 0 and 1
|
||||
tintIntensity = Mathf.Clamp01(tintIntensity);
|
||||
|
||||
// Blend the original color with the tint color
|
||||
Color blendedColor = Color.Lerp(originalColor, tintColor, tintIntensity);
|
||||
|
||||
return blendedColor;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
using UnityEngine;
|
||||
|
||||
public static class ColorUtility
|
||||
{
|
||||
public static Color AddGreyShade(Color originalColor, float greyIntensity)
|
||||
{
|
||||
// Clamp the greyIntensity between 0 and 1
|
||||
greyIntensity = Mathf.Clamp01(greyIntensity);
|
||||
|
||||
// Define the grey color (e.g., medium grey)
|
||||
Color grey = new Color(0.5f, 0.5f, 0.5f); // RGB (128, 128, 128)
|
||||
|
||||
// Blend the original color with the grey color
|
||||
Color blendedColor = Color.Lerp(originalColor, grey, greyIntensity);
|
||||
|
||||
return blendedColor;
|
||||
}
|
||||
}
|
||||
|
|
@ -6,13 +6,55 @@ using UnityEngine.UI;
|
|||
public class Die : MonoBehaviour
|
||||
{
|
||||
private int _result = 0;
|
||||
[SerializeField] private Button dieButton = null; // assign in the editor
|
||||
public event EventHandler<Die> DieClicked;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
dieButton.onClick.AddListener(() => { DiePressed();});
|
||||
}
|
||||
|
||||
public void SetResult(int result) {
|
||||
_result = result;
|
||||
gameObject.GetComponentInChildren<TextMeshProUGUI>().text = _result.ToString();
|
||||
}
|
||||
|
||||
public int GetResult()
|
||||
{
|
||||
return _result;
|
||||
}
|
||||
|
||||
public void ClearDie() {
|
||||
gameObject.GetComponent<TextMeshProUGUI>().text = String.Empty;
|
||||
}
|
||||
|
||||
public void DieBeingUsed(bool isFirstPair, bool isPairComplete)
|
||||
{
|
||||
if (isPairComplete)
|
||||
{
|
||||
// Signify that both dice have been selected
|
||||
DieSelectedAndPairComplete();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Signify that the die is selected but the pair is not complete
|
||||
DieSelectedButPairNotComplete();
|
||||
}
|
||||
}
|
||||
|
||||
private void DiePressed()
|
||||
{
|
||||
DieClicked?.Invoke(this, this);
|
||||
}
|
||||
|
||||
private void DieSelectedButPairNotComplete()
|
||||
{
|
||||
gameObject.GetComponent<Outline>().enabled = true;
|
||||
}
|
||||
|
||||
private void DieSelectedAndPairComplete()
|
||||
{
|
||||
gameObject.GetComponent<Image>().color =
|
||||
ColorHelper.AddColorTint(gameObject.GetComponent<Image>().color, ColorHelper.OkayGreen, 0.5f);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,37 +1,102 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public enum GameState
|
||||
{
|
||||
PickRoom,
|
||||
RollDice
|
||||
PickRoomOne,
|
||||
PickRoomTwo,
|
||||
PickDiceOne,
|
||||
PickDiceTwo,
|
||||
}
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
public GameState state;
|
||||
public GameObject rooms;
|
||||
public GameObject dice;
|
||||
public DiceRoller diceRoller;
|
||||
|
||||
private (Die, Die) _dicePairOne = (null, null);
|
||||
private (Die, Die) _dicePairTwo = (null, null);
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
state = GameState.RollDice;
|
||||
state = GameState.PickDiceOne;
|
||||
foreach (Transform roomTransform in rooms.transform)
|
||||
{
|
||||
roomTransform.gameObject.GetComponent<Room>().ValidRoomClicked += ValidRoomClicked;
|
||||
}
|
||||
|
||||
foreach (Transform diceTransform in dice.transform)
|
||||
{
|
||||
diceTransform.gameObject.GetComponent<Die>().DieClicked += DieClicked;
|
||||
}
|
||||
diceRoller.RollDice();
|
||||
}
|
||||
|
||||
void ValidRoomClicked(object sender, Room room) {
|
||||
if (state == GameState.PickRoom)
|
||||
if (state != GameState.PickRoomOne && state != GameState.PickRoomTwo)
|
||||
{
|
||||
room.SetRoomExplored();
|
||||
return;
|
||||
}
|
||||
room.SetRoomExplored();
|
||||
if (state == GameState.PickRoomOne)
|
||||
{
|
||||
state = GameState.PickDiceTwo;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Not implemented
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DieClicked(object sender, Die die)
|
||||
{
|
||||
if (state != GameState.PickDiceOne && state != GameState.PickDiceTwo)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (state == GameState.PickDiceOne)
|
||||
{
|
||||
if (_dicePairOne.Item1 == null && _dicePairOne.Item2 == null)
|
||||
{
|
||||
_dicePairOne.Item1 = die;
|
||||
die.DieBeingUsed(true, false);
|
||||
}
|
||||
else if (_dicePairOne.Item2 == null)
|
||||
{
|
||||
_dicePairOne.Item2 = die;
|
||||
_dicePairOne.Item1.DieBeingUsed(true, true);
|
||||
die.DieBeingUsed(true, true);
|
||||
}
|
||||
|
||||
if (_dicePairOne.Item1 != null && _dicePairOne.Item2 != null)
|
||||
{
|
||||
state = GameState.PickRoomOne;
|
||||
}
|
||||
}
|
||||
else if(state == GameState.PickDiceTwo)
|
||||
{
|
||||
if (_dicePairTwo.Item1 == null && _dicePairTwo.Item2 == null)
|
||||
{
|
||||
_dicePairTwo.Item1 = die;
|
||||
die.DieBeingUsed(false, false);
|
||||
}
|
||||
else if (_dicePairTwo.Item2 == null)
|
||||
{
|
||||
_dicePairTwo.Item2 = die;
|
||||
_dicePairTwo.Item1.DieBeingUsed(false, true);
|
||||
die.DieBeingUsed(false, true);
|
||||
}
|
||||
|
||||
if (_dicePairTwo.Item1 != null && _dicePairTwo.Item2 != null)
|
||||
{
|
||||
state = GameState.PickRoomTwo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SetUpDice() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ public class Room : MonoBehaviour
|
|||
public void SetRoomExplored() {
|
||||
_isExplored = true;
|
||||
gameObject.GetComponent<SpriteRenderer>().color =
|
||||
ColorUtility.AddGreyShade(gameObject.GetComponent<SpriteRenderer>().color, 0.5f);
|
||||
ColorHelper.AddColorTint(gameObject.GetComponent<SpriteRenderer>().color, Color.grey, 0.5f);
|
||||
}
|
||||
|
||||
void SetPropertiesOfEntrance() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue