Implemented basic room exploration logic.
This commit is contained in:
parent
cb7aff20dd
commit
4bd34a1335
13 changed files with 186 additions and 92 deletions
13
PuzzleGameProject/.idea/.idea.PuzzleGameProject/.idea/.gitignore
generated
vendored
Normal file
13
PuzzleGameProject/.idea/.idea.PuzzleGameProject/.idea/.gitignore
generated
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Rider ignored files
|
||||
/modules.xml
|
||||
/.idea.PuzzleGameProject.iml
|
||||
/contentModel.xml
|
||||
/projectSettingsUpdater.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
8
PuzzleGameProject/.idea/.idea.PuzzleGameProject/.idea/indexLayout.xml
generated
Normal file
8
PuzzleGameProject/.idea/.idea.PuzzleGameProject/.idea/indexLayout.xml
generated
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
||||
6
PuzzleGameProject/.idea/.idea.PuzzleGameProject/.idea/vcs.xml
generated
Normal file
6
PuzzleGameProject/.idea/.idea.PuzzleGameProject/.idea/vcs.xml
generated
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -11,6 +11,7 @@ GameObject:
|
|||
- component: {fileID: 9187907134033443523}
|
||||
- component: {fileID: 1770509300873928573}
|
||||
- component: {fileID: 2727030095425591755}
|
||||
- component: {fileID: 4019891345885281529}
|
||||
m_Layer: 0
|
||||
m_Name: Room
|
||||
m_TagString: Untagged
|
||||
|
|
@ -103,6 +104,69 @@ MonoBehaviour:
|
|||
m_EditorClassIdentifier:
|
||||
number: 0
|
||||
numberTextObject: {fileID: 8119019481281764985}
|
||||
adjacentRooms: []
|
||||
isEntrance: 0
|
||||
validRoomClickedEvent:
|
||||
m_PersistentCalls:
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 11500000, guid: 85fe57d438ef1ec4fa8b36b9c17c11a4, type: 3}
|
||||
m_TargetAssemblyTypeName: UnityEngine.Object, UnityEngine
|
||||
m_MethodName: set_name
|
||||
m_Mode: 5
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 0}
|
||||
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
|
||||
m_IntArgument: 0
|
||||
m_FloatArgument: 0
|
||||
m_StringArgument: ValidRoomClicked
|
||||
m_BoolArgument: 0
|
||||
m_CallState: 2
|
||||
--- !u!61 &4019891345885281529
|
||||
BoxCollider2D:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2435349004046080434}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 3
|
||||
m_Density: 1
|
||||
m_Material: {fileID: 0}
|
||||
m_IncludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_ExcludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_LayerOverridePriority: 0
|
||||
m_ForceSendLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_ForceReceiveLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_ContactCaptureLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_CallbackLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_IsTrigger: 1
|
||||
m_UsedByEffector: 0
|
||||
m_CompositeOperation: 0
|
||||
m_CompositeOrder: 0
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_SpriteTilingProperty:
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
pivot: {x: 0.5, y: 0.5}
|
||||
oldSize: {x: 1, y: 1}
|
||||
newSize: {x: 1, y: 1}
|
||||
adaptiveTilingThreshold: 0.5
|
||||
drawMode: 0
|
||||
adaptiveTiling: 0
|
||||
m_AutoTiling: 0
|
||||
m_Size: {x: 1, y: 1}
|
||||
m_EdgeRadius: 0
|
||||
--- !u!1 &7488793311042651820
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
|||
|
|
@ -339,7 +339,6 @@ GameObject:
|
|||
m_Component:
|
||||
- component: {fileID: 126339302}
|
||||
- component: {fileID: 126339304}
|
||||
- component: {fileID: 126339303}
|
||||
m_Layer: 0
|
||||
m_Name: GameManager
|
||||
m_TagString: Untagged
|
||||
|
|
@ -362,19 +361,6 @@ Transform:
|
|||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &126339303
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 126339301}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: f0c75429168c5fb418e656b295433971, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
rooms: {fileID: 1820284205}
|
||||
--- !u!114 &126339304
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
@ -384,10 +370,11 @@ MonoBehaviour:
|
|||
m_GameObject: {fileID: 126339301}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 6d900f1b1caebac429626fd7fe820582, type: 3}
|
||||
m_Script: {fileID: 11500000, guid: 85fe57d438ef1ec4fa8b36b9c17c11a4, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
roomManager: {fileID: 0}
|
||||
state: 0
|
||||
rooms: {fileID: 1820284205}
|
||||
--- !u!1001 &408992220
|
||||
PrefabInstance:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
|||
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