Implemented both dice selections
This commit is contained in:
parent
2b08dc425f
commit
d04624edfd
9 changed files with 182 additions and 29 deletions
|
|
@ -149,6 +149,7 @@ GameObject:
|
||||||
- component: {fileID: 6156510816236760012}
|
- component: {fileID: 6156510816236760012}
|
||||||
- component: {fileID: 5247104008048868212}
|
- component: {fileID: 5247104008048868212}
|
||||||
- component: {fileID: 6084228361150234175}
|
- component: {fileID: 6084228361150234175}
|
||||||
|
- component: {fileID: -7124398980878284295}
|
||||||
m_Layer: 5
|
m_Layer: 5
|
||||||
m_Name: Black Die
|
m_Name: Black Die
|
||||||
m_TagString: BlackDie
|
m_TagString: BlackDie
|
||||||
|
|
@ -270,3 +271,19 @@ MonoBehaviour:
|
||||||
m_Script: {fileID: 11500000, guid: edf2cd8ae662a415898ed6567457f32d, type: 3}
|
m_Script: {fileID: 11500000, guid: edf2cd8ae662a415898ed6567457f32d, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
dieButton: {fileID: 5247104008048868212}
|
||||||
|
--- !u!114 &-7124398980878284295
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 7874367151511621086}
|
||||||
|
m_Enabled: 0
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: e19747de3f5aca642ab2be37e372fb86, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
m_EffectColor: {r: 0.04705883, g: 0.79215693, b: 0, a: 0.5}
|
||||||
|
m_EffectDistance: {x: 1, y: -1}
|
||||||
|
m_UseGraphicAlpha: 1
|
||||||
|
|
|
||||||
|
|
@ -149,6 +149,7 @@ GameObject:
|
||||||
- component: {fileID: 6156510816236760012}
|
- component: {fileID: 6156510816236760012}
|
||||||
- component: {fileID: 5247104008048868212}
|
- component: {fileID: 5247104008048868212}
|
||||||
- component: {fileID: 6084228361150234175}
|
- component: {fileID: 6084228361150234175}
|
||||||
|
- component: {fileID: 6840580988586272823}
|
||||||
m_Layer: 5
|
m_Layer: 5
|
||||||
m_Name: White Die
|
m_Name: White Die
|
||||||
m_TagString: WhiteDie
|
m_TagString: WhiteDie
|
||||||
|
|
@ -257,7 +258,19 @@ MonoBehaviour:
|
||||||
m_TargetGraphic: {fileID: 6156510816236760012}
|
m_TargetGraphic: {fileID: 6156510816236760012}
|
||||||
m_OnClick:
|
m_OnClick:
|
||||||
m_PersistentCalls:
|
m_PersistentCalls:
|
||||||
m_Calls: []
|
m_Calls:
|
||||||
|
- m_Target: {fileID: 0}
|
||||||
|
m_TargetAssemblyTypeName:
|
||||||
|
m_MethodName:
|
||||||
|
m_Mode: 1
|
||||||
|
m_Arguments:
|
||||||
|
m_ObjectArgument: {fileID: 0}
|
||||||
|
m_ObjectArgumentAssemblyTypeName:
|
||||||
|
m_IntArgument: 0
|
||||||
|
m_FloatArgument: 0
|
||||||
|
m_StringArgument:
|
||||||
|
m_BoolArgument: 0
|
||||||
|
m_CallState: 2
|
||||||
--- !u!114 &6084228361150234175
|
--- !u!114 &6084228361150234175
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|
@ -270,3 +283,19 @@ MonoBehaviour:
|
||||||
m_Script: {fileID: 11500000, guid: edf2cd8ae662a415898ed6567457f32d, type: 3}
|
m_Script: {fileID: 11500000, guid: edf2cd8ae662a415898ed6567457f32d, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
dieButton: {fileID: 5247104008048868212}
|
||||||
|
--- !u!114 &6840580988586272823
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 7874367151511621086}
|
||||||
|
m_Enabled: 0
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: e19747de3f5aca642ab2be37e372fb86, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
m_EffectColor: {r: 0.045367185, g: 0.7924528, b: 0, a: 0.5}
|
||||||
|
m_EffectDistance: {x: 1, y: -1}
|
||||||
|
m_UseGraphicAlpha: 1
|
||||||
|
|
|
||||||
|
|
@ -376,6 +376,7 @@ MonoBehaviour:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
state: 0
|
state: 0
|
||||||
rooms: {fileID: 1820284205}
|
rooms: {fileID: 1820284205}
|
||||||
|
dice: {fileID: 925126051}
|
||||||
diceRoller: {fileID: 126339305}
|
diceRoller: {fileID: 126339305}
|
||||||
--- !u!114 &126339305
|
--- !u!114 &126339305
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
|
|
|
||||||
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
|
public class Die : MonoBehaviour
|
||||||
{
|
{
|
||||||
private int _result = 0;
|
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) {
|
public void SetResult(int result) {
|
||||||
_result = result;
|
_result = result;
|
||||||
gameObject.GetComponentInChildren<TextMeshProUGUI>().text = _result.ToString();
|
gameObject.GetComponentInChildren<TextMeshProUGUI>().text = _result.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int GetResult()
|
||||||
|
{
|
||||||
|
return _result;
|
||||||
|
}
|
||||||
|
|
||||||
public void ClearDie() {
|
public void ClearDie() {
|
||||||
gameObject.GetComponent<TextMeshProUGUI>().text = String.Empty;
|
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 System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
public enum GameState
|
public enum GameState
|
||||||
{
|
{
|
||||||
PickRoom,
|
PickRoomOne,
|
||||||
RollDice
|
PickRoomTwo,
|
||||||
|
PickDiceOne,
|
||||||
|
PickDiceTwo,
|
||||||
}
|
}
|
||||||
public class GameManager : MonoBehaviour
|
public class GameManager : MonoBehaviour
|
||||||
{
|
{
|
||||||
public GameState state;
|
public GameState state;
|
||||||
public GameObject rooms;
|
public GameObject rooms;
|
||||||
|
public GameObject dice;
|
||||||
public DiceRoller diceRoller;
|
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
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
state = GameState.RollDice;
|
state = GameState.PickDiceOne;
|
||||||
foreach (Transform roomTransform in rooms.transform)
|
foreach (Transform roomTransform in rooms.transform)
|
||||||
{
|
{
|
||||||
roomTransform.gameObject.GetComponent<Room>().ValidRoomClicked += ValidRoomClicked;
|
roomTransform.gameObject.GetComponent<Room>().ValidRoomClicked += ValidRoomClicked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (Transform diceTransform in dice.transform)
|
||||||
|
{
|
||||||
|
diceTransform.gameObject.GetComponent<Die>().DieClicked += DieClicked;
|
||||||
|
}
|
||||||
diceRoller.RollDice();
|
diceRoller.RollDice();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ValidRoomClicked(object sender, Room room) {
|
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() {
|
public void SetRoomExplored() {
|
||||||
_isExplored = true;
|
_isExplored = true;
|
||||||
gameObject.GetComponent<SpriteRenderer>().color =
|
gameObject.GetComponent<SpriteRenderer>().color =
|
||||||
ColorUtility.AddGreyShade(gameObject.GetComponent<SpriteRenderer>().color, 0.5f);
|
ColorHelper.AddColorTint(gameObject.GetComponent<SpriteRenderer>().color, Color.grey, 0.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetPropertiesOfEntrance() {
|
void SetPropertiesOfEntrance() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue