Implemented basic room exploration logic.
This commit is contained in:
parent
cb7aff20dd
commit
4bd34a1335
13 changed files with 186 additions and 92 deletions
18
PuzzleGameProject/Assets/Scripts/ColorUtility.cs
Normal file
18
PuzzleGameProject/Assets/Scripts/ColorUtility.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
2
PuzzleGameProject/Assets/Scripts/ColorUtility.cs.meta
Normal file
2
PuzzleGameProject/Assets/Scripts/ColorUtility.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b672f01694df748be8bec0b7866a5972
|
||||
|
|
@ -1,19 +1,30 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
public enum GameState
|
||||
{
|
||||
PickRoom
|
||||
}
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
public TurnManager turnManager;
|
||||
public RoomManager roomManager;
|
||||
public GameState state;
|
||||
public GameObject rooms;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
roomManager.InnitializeRooms();
|
||||
state = GameState.PickRoom;
|
||||
foreach (Transform roomTransform in rooms.transform)
|
||||
{
|
||||
roomTransform.gameObject.GetComponent<Room>().ValidRoomClicked += ValidRoomClicked;
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
void ValidRoomClicked(object sender, Room room) {
|
||||
if (state == GameState.PickRoom)
|
||||
{
|
||||
room.SetRoomExplored();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
|
@ -8,13 +10,15 @@ public class Room : MonoBehaviour
|
|||
public GameObject numberTextObject;
|
||||
public List<GameObject> adjacentRooms;
|
||||
public bool isEntrance;
|
||||
private bool isExplored = false;
|
||||
public event EventHandler<Room> ValidRoomClicked;
|
||||
|
||||
bool _isExplored = false;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
if (isEntrance)
|
||||
{
|
||||
void Start() {
|
||||
|
||||
|
||||
if (isEntrance) {
|
||||
SetPropertiesOfEntrance();
|
||||
}
|
||||
|
||||
|
|
@ -22,15 +26,53 @@ public class Room : MonoBehaviour
|
|||
numberText.SetText(number.ToString());
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
public void SetRoomExplored() {
|
||||
_isExplored = true;
|
||||
gameObject.GetComponent<SpriteRenderer>().color =
|
||||
ColorUtility.AddGreyShade(gameObject.GetComponent<SpriteRenderer>().color, 0.5f);
|
||||
}
|
||||
|
||||
private void SetPropertiesOfEntrance()
|
||||
void SetPropertiesOfEntrance() {
|
||||
gameObject.GetComponent<SpriteRenderer>().color = Color.green;
|
||||
isEntrance = true;
|
||||
}
|
||||
|
||||
IEnumerator OnMouseDown()
|
||||
{
|
||||
this.gameObject.GetComponent<SpriteRenderer>().color = Color.green;
|
||||
this.isEntrance = true;
|
||||
if (IsValidRoomToExplore()) {
|
||||
OnValidRoomClicked();
|
||||
}
|
||||
yield return null;
|
||||
}
|
||||
|
||||
protected virtual void OnValidRoomClicked() {
|
||||
ValidRoomClicked?.Invoke(this, this);
|
||||
}
|
||||
|
||||
// Check if the room is valid to be explored. If so trigger the event.
|
||||
bool IsValidRoomToExplore() {
|
||||
if (_isExplored) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isEntrance) {
|
||||
// All entrance rooms are valid to be explored.
|
||||
return true;
|
||||
}
|
||||
else if (HasExploredAdjacentRooms()) {
|
||||
// Otherwise the room must have an adjacent room explored.
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HasExploredAdjacentRooms() {
|
||||
foreach (GameObject adjacentRoom in adjacentRooms) {
|
||||
if (adjacentRoom.GetComponent<Room>()._isExplored)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +0,0 @@
|
|||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class RoomManager : MonoBehaviour
|
||||
{
|
||||
public GameObject rooms;
|
||||
private List<GameObject> _entranceRooms = new List<GameObject>();
|
||||
|
||||
public void InnitializeRooms()
|
||||
{
|
||||
AddEntranceRoomsToList(rooms);
|
||||
}
|
||||
|
||||
private void AddEntranceRoomsToList(GameObject rooms)
|
||||
{
|
||||
foreach (Transform roomTransform in rooms.transform)
|
||||
{
|
||||
if (roomTransform.gameObject.GetComponent<Room>().isEntrance)
|
||||
{
|
||||
_entranceRooms.Add(roomTransform.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<GameObject> GetEntranceRooms()
|
||||
{
|
||||
return _entranceRooms;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f0c75429168c5fb418e656b295433971
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class TurnManager : MonoBehaviour
|
||||
{
|
||||
public RoomManager roomManager;
|
||||
private int _turn = 0;
|
||||
|
||||
// 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()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void takeTurn()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6d900f1b1caebac429626fd7fe820582
|
||||
Loading…
Add table
Add a link
Reference in a new issue