diff --git a/Assets/Prefabs/Characters/Player1Mesh.prefab b/Assets/Prefabs/Characters/Player1Mesh.prefab index a99f20b..e1bfd6a 100644 --- a/Assets/Prefabs/Characters/Player1Mesh.prefab +++ b/Assets/Prefabs/Characters/Player1Mesh.prefab @@ -29,7 +29,7 @@ Transform: m_GameObject: {fileID: 7993275380040288456} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 18.7, y: 3.76, z: -10.59} - m_LocalScale: {x: 2.1844, y: 2.1844, z: 2.1844} + m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} @@ -110,3 +110,4 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: da493b8dbb3aa475abf11f31549b9293, type: 3} m_Name: m_EditorClassIdentifier: + playerState: 0 diff --git a/Assets/Prefabs/Characters/Player2Mesh.prefab b/Assets/Prefabs/Characters/Player2Mesh.prefab index b53b369..e1258a1 100644 --- a/Assets/Prefabs/Characters/Player2Mesh.prefab +++ b/Assets/Prefabs/Characters/Player2Mesh.prefab @@ -29,7 +29,7 @@ Transform: m_GameObject: {fileID: 7993275380040288456} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 18.7, y: 3.76, z: -10.59} - m_LocalScale: {x: 2.1844, y: 2.1844, z: 2.1844} + m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} diff --git a/Assets/Prefabs/Characters/Player3Mesh.prefab b/Assets/Prefabs/Characters/Player3Mesh.prefab index e39badd..60b2fed 100644 --- a/Assets/Prefabs/Characters/Player3Mesh.prefab +++ b/Assets/Prefabs/Characters/Player3Mesh.prefab @@ -29,7 +29,7 @@ Transform: m_GameObject: {fileID: 7993275380040288456} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 18.7, y: 3.76, z: -10.59} - m_LocalScale: {x: 2.1844, y: 2.1844, z: 2.1844} + m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} diff --git a/Assets/Prefabs/Characters/Player4Mesh.prefab b/Assets/Prefabs/Characters/Player4Mesh.prefab index 09ab5fb..35a7abf 100644 --- a/Assets/Prefabs/Characters/Player4Mesh.prefab +++ b/Assets/Prefabs/Characters/Player4Mesh.prefab @@ -29,7 +29,7 @@ Transform: m_GameObject: {fileID: 7993275380040288456} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 18.7, y: 3.76, z: -10.59} - m_LocalScale: {x: 2.1844, y: 2.1844, z: 2.1844} + m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} diff --git a/Assets/Prefabs/Tile/Tile (1).prefab b/Assets/Prefabs/Tile/Tile (1).prefab index 1255fcc..f079fc6 100644 --- a/Assets/Prefabs/Tile/Tile (1).prefab +++ b/Assets/Prefabs/Tile/Tile (1).prefab @@ -10,7 +10,7 @@ GameObject: m_Component: - component: {fileID: 340880581} m_Layer: 0 - m_Name: GameObject + m_Name: Placement (1) m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -24,12 +24,12 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 340880580} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -1.09, y: 0, z: -1.01} - m_LocalScale: {x: 0.5, y: 0.5, z: 0.5} + m_LocalPosition: {x: -0.93, y: 0, z: -0.73} + m_LocalScale: {x: 0.74999994, y: 0.74999994, z: 0.74999994} m_ConstrainProportionsScale: 1 m_Children: [] m_Father: {fileID: 2960581183699728426} - m_RootOrder: 0 + m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &489080435 GameObject: @@ -41,7 +41,7 @@ GameObject: m_Component: - component: {fileID: 489080436} m_Layer: 0 - m_Name: GameObject (1) + m_Name: Placement (3) m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -55,12 +55,12 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 489080435} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -1.11, y: 0, z: 1.2} - m_LocalScale: {x: 0.5, y: 0.5, z: 0.5} + m_LocalPosition: {x: -0.93, y: 0, z: 0.97} + m_LocalScale: {x: 0.74999994, y: 0.74999994, z: 0.74999994} m_ConstrainProportionsScale: 1 m_Children: [] m_Father: {fileID: 2960581183699728426} - m_RootOrder: 2 + m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &575231063 GameObject: @@ -72,7 +72,7 @@ GameObject: m_Component: - component: {fileID: 575231064} m_Layer: 0 - m_Name: GameObject (3) + m_Name: Placement (4) m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -86,12 +86,12 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 575231063} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0.89, y: 0, z: -1.05} - m_LocalScale: {x: 0.5, y: 0.5, z: 0.5} + m_LocalPosition: {x: 0.8, y: 0, z: -0.73} + m_LocalScale: {x: 0.74999994, y: 0.74999994, z: 0.74999994} m_ConstrainProportionsScale: 1 m_Children: [] m_Father: {fileID: 2960581183699728426} - m_RootOrder: 3 + m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1493812672 GameObject: @@ -103,7 +103,7 @@ GameObject: m_Component: - component: {fileID: 1493812673} m_Layer: 0 - m_Name: GameObject (2) + m_Name: Placement (2) m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -118,11 +118,11 @@ Transform: m_GameObject: {fileID: 1493812672} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0.8, y: 0, z: 0.97} - m_LocalScale: {x: 0.5, y: 0.5, z: 0.5} + m_LocalScale: {x: 0.74999994, y: 0.74999994, z: 0.74999994} m_ConstrainProportionsScale: 1 m_Children: [] m_Father: {fileID: 2960581183699728426} - m_RootOrder: 1 + m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &2960581183699728427 GameObject: @@ -153,6 +153,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: + - {fileID: 4090225931849457574} - {fileID: 340880581} - {fileID: 1493812673} - {fileID: 489080436} @@ -172,4 +173,35 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: be69a8cfb3b2940308cbac570565e629, type: 3} m_Name: m_EditorClassIdentifier: - isSafeZone: 0 + isSafeZone: 1 +--- !u!1 &7673046030148000875 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 4090225931849457574} + m_Layer: 0 + m_Name: CenterPlacement + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &4090225931849457574 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7673046030148000875} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 1, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 2960581183699728426} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/Assets/Scenes/Game.unity b/Assets/Scenes/Game.unity index bf96e40..72ba135 100644 --- a/Assets/Scenes/Game.unity +++ b/Assets/Scenes/Game.unity @@ -326,6 +326,10 @@ PrefabInstance: m_Modification: m_TransformParent: {fileID: 868479585} m_Modifications: + - target: {fileID: 2960581183699728421, guid: bc986262997c641d9b5bcff22bd100c1, type: 3} + propertyPath: isSafeZone + value: 1 + objectReference: {fileID: 0} - target: {fileID: 2960581183699728426, guid: bc986262997c641d9b5bcff22bd100c1, type: 3} propertyPath: m_RootOrder value: 12 @@ -472,6 +476,10 @@ PrefabInstance: m_Modification: m_TransformParent: {fileID: 868479585} m_Modifications: + - target: {fileID: 2960581183699728421, guid: bc986262997c641d9b5bcff22bd100c1, type: 3} + propertyPath: isSafeZone + value: 1 + objectReference: {fileID: 0} - target: {fileID: 2960581183699728426, guid: bc986262997c641d9b5bcff22bd100c1, type: 3} propertyPath: m_RootOrder value: 8 @@ -1284,6 +1292,10 @@ PrefabInstance: propertyPath: m_Name value: Player1Mesh (2) objectReference: {fileID: 0} + - target: {fileID: 7993275380040288456, guid: 9ae10e3fa7db64f47af31a5f0ebbecdc, type: 3} + propertyPath: m_IsActive + value: 0 + objectReference: {fileID: 0} - target: {fileID: 7993275380040288459, guid: 9ae10e3fa7db64f47af31a5f0ebbecdc, type: 3} propertyPath: m_RootOrder value: 2 @@ -1346,6 +1358,10 @@ PrefabInstance: propertyPath: m_Name value: Player1Mesh (1) objectReference: {fileID: 0} + - target: {fileID: 7993275380040288456, guid: 9ae10e3fa7db64f47af31a5f0ebbecdc, type: 3} + propertyPath: m_IsActive + value: 0 + objectReference: {fileID: 0} - target: {fileID: 7993275380040288459, guid: 9ae10e3fa7db64f47af31a5f0ebbecdc, type: 3} propertyPath: m_RootOrder value: 1 @@ -2097,6 +2113,10 @@ PrefabInstance: propertyPath: m_Name value: Player3Mesh (2) objectReference: {fileID: 0} + - target: {fileID: 7993275380040288456, guid: 195e8a45a36974637bff1dab6791e632, type: 3} + propertyPath: m_IsActive + value: 0 + objectReference: {fileID: 0} - target: {fileID: 7993275380040288459, guid: 195e8a45a36974637bff1dab6791e632, type: 3} propertyPath: m_RootOrder value: 2 @@ -2278,6 +2298,10 @@ PrefabInstance: propertyPath: m_Name value: Player3Mesh (3) objectReference: {fileID: 0} + - target: {fileID: 7993275380040288456, guid: 195e8a45a36974637bff1dab6791e632, type: 3} + propertyPath: m_IsActive + value: 0 + objectReference: {fileID: 0} - target: {fileID: 7993275380040288459, guid: 195e8a45a36974637bff1dab6791e632, type: 3} propertyPath: m_RootOrder value: 3 @@ -2431,6 +2455,10 @@ PrefabInstance: m_Modification: m_TransformParent: {fileID: 868479585} m_Modifications: + - target: {fileID: 2960581183699728421, guid: bc986262997c641d9b5bcff22bd100c1, type: 3} + propertyPath: isSafeZone + value: 1 + objectReference: {fileID: 0} - target: {fileID: 2960581183699728426, guid: bc986262997c641d9b5bcff22bd100c1, type: 3} propertyPath: m_RootOrder value: 24 @@ -2903,6 +2931,10 @@ PrefabInstance: propertyPath: m_Name value: Player2Mesh (2) objectReference: {fileID: 0} + - target: {fileID: 7993275380040288456, guid: 81ea53750af48479785425335304fdc7, type: 3} + propertyPath: m_IsActive + value: 1 + objectReference: {fileID: 0} - target: {fileID: 7993275380040288459, guid: 81ea53750af48479785425335304fdc7, type: 3} propertyPath: m_RootOrder value: 2 @@ -3250,6 +3282,10 @@ PrefabInstance: propertyPath: m_Name value: Player3Mesh (1) objectReference: {fileID: 0} + - target: {fileID: 7993275380040288456, guid: 195e8a45a36974637bff1dab6791e632, type: 3} + propertyPath: m_IsActive + value: 0 + objectReference: {fileID: 0} - target: {fileID: 7993275380040288459, guid: 195e8a45a36974637bff1dab6791e632, type: 3} propertyPath: m_RootOrder value: 1 @@ -3614,24 +3650,28 @@ MonoBehaviour: endIndex: 46 playersParent: {fileID: 1373272158} playerPawns: [] + totalPawnsFinished: 0 - playerType: 1 playerCornerEntity: {fileID: 241691679} startIndex: 12 endIndex: 10 playersParent: {fileID: 1841959051} playerPawns: [] + totalPawnsFinished: 0 - playerType: 2 playerCornerEntity: {fileID: 987201643} startIndex: 24 endIndex: 22 playersParent: {fileID: 1934858463} playerPawns: [] + totalPawnsFinished: 0 - playerType: 3 playerCornerEntity: {fileID: 1251876826} startIndex: 36 endIndex: 34 playersParent: {fileID: 1094154913} playerPawns: [] + totalPawnsFinished: 0 --- !u!1001 &923111009 PrefabInstance: m_ObjectHideFlags: 0 @@ -3767,6 +3807,10 @@ PrefabInstance: propertyPath: m_Name value: Player1Mesh (3) objectReference: {fileID: 0} + - target: {fileID: 7993275380040288456, guid: 9ae10e3fa7db64f47af31a5f0ebbecdc, type: 3} + propertyPath: m_IsActive + value: 0 + objectReference: {fileID: 0} - target: {fileID: 7993275380040288459, guid: 9ae10e3fa7db64f47af31a5f0ebbecdc, type: 3} propertyPath: m_RootOrder value: 3 @@ -4504,6 +4548,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: f06aabb5d8a9f441e99482ccf020f10c, type: 3} m_Name: m_EditorClassIdentifier: + diceTestValue: 6 --- !u!1001 &1041368837 PrefabInstance: m_ObjectHideFlags: 0 @@ -4573,6 +4618,10 @@ PrefabInstance: m_Modification: m_TransformParent: {fileID: 868479585} m_Modifications: + - target: {fileID: 2960581183699728421, guid: bc986262997c641d9b5bcff22bd100c1, type: 3} + propertyPath: isSafeZone + value: 1 + objectReference: {fileID: 0} - target: {fileID: 2960581183699728426, guid: bc986262997c641d9b5bcff22bd100c1, type: 3} propertyPath: m_RootOrder value: 36 @@ -5011,6 +5060,10 @@ PrefabInstance: m_Modification: m_TransformParent: {fileID: 868479585} m_Modifications: + - target: {fileID: 2960581183699728421, guid: bc986262997c641d9b5bcff22bd100c1, type: 3} + propertyPath: isSafeZone + value: 1 + objectReference: {fileID: 0} - target: {fileID: 2960581183699728426, guid: bc986262997c641d9b5bcff22bd100c1, type: 3} propertyPath: m_RootOrder value: 19 @@ -5800,6 +5853,10 @@ PrefabInstance: propertyPath: m_Name value: Player4Mesh (1) objectReference: {fileID: 0} + - target: {fileID: 7993275380040288456, guid: 28a2e17f2aa28459099c180350293bf6, type: 3} + propertyPath: m_IsActive + value: 1 + objectReference: {fileID: 0} - target: {fileID: 7993275380040288459, guid: 28a2e17f2aa28459099c180350293bf6, type: 3} propertyPath: m_RootOrder value: 1 @@ -5862,6 +5919,10 @@ PrefabInstance: propertyPath: m_Name value: Player2Mesh (1) objectReference: {fileID: 0} + - target: {fileID: 7993275380040288456, guid: 81ea53750af48479785425335304fdc7, type: 3} + propertyPath: m_IsActive + value: 1 + objectReference: {fileID: 0} - target: {fileID: 7993275380040288459, guid: 81ea53750af48479785425335304fdc7, type: 3} propertyPath: m_RootOrder value: 1 @@ -6715,6 +6776,10 @@ PrefabInstance: m_Modification: m_TransformParent: {fileID: 868479585} m_Modifications: + - target: {fileID: 2960581183699728421, guid: bc986262997c641d9b5bcff22bd100c1, type: 3} + propertyPath: isSafeZone + value: 1 + objectReference: {fileID: 0} - target: {fileID: 2960581183699728426, guid: bc986262997c641d9b5bcff22bd100c1, type: 3} propertyPath: m_RootOrder value: 31 @@ -6792,6 +6857,10 @@ PrefabInstance: propertyPath: m_Name value: Player4Mesh (2) objectReference: {fileID: 0} + - target: {fileID: 7993275380040288456, guid: 28a2e17f2aa28459099c180350293bf6, type: 3} + propertyPath: m_IsActive + value: 1 + objectReference: {fileID: 0} - target: {fileID: 7993275380040288459, guid: 28a2e17f2aa28459099c180350293bf6, type: 3} propertyPath: m_RootOrder value: 2 @@ -7176,6 +7245,10 @@ PrefabInstance: propertyPath: m_Name value: Player2Mesh (3) objectReference: {fileID: 0} + - target: {fileID: 7993275380040288456, guid: 81ea53750af48479785425335304fdc7, type: 3} + propertyPath: m_IsActive + value: 1 + objectReference: {fileID: 0} - target: {fileID: 7993275380040288459, guid: 81ea53750af48479785425335304fdc7, type: 3} propertyPath: m_RootOrder value: 3 @@ -7234,6 +7307,10 @@ PrefabInstance: m_Modification: m_TransformParent: {fileID: 868479585} m_Modifications: + - target: {fileID: 2960581183699728421, guid: bc986262997c641d9b5bcff22bd100c1, type: 3} + propertyPath: isSafeZone + value: 1 + objectReference: {fileID: 0} - target: {fileID: 2960581183699728426, guid: bc986262997c641d9b5bcff22bd100c1, type: 3} propertyPath: m_RootOrder value: 43 @@ -7521,6 +7598,10 @@ PrefabInstance: propertyPath: m_Name value: Player4Mesh (3) objectReference: {fileID: 0} + - target: {fileID: 7993275380040288456, guid: 28a2e17f2aa28459099c180350293bf6, type: 3} + propertyPath: m_IsActive + value: 1 + objectReference: {fileID: 0} - target: {fileID: 7993275380040288459, guid: 28a2e17f2aa28459099c180350293bf6, type: 3} propertyPath: m_RootOrder value: 3 diff --git a/Assets/Scripts/Gameplay/GameplayManager.cs b/Assets/Scripts/Gameplay/GameplayManager.cs index 299eb3c..3bb80c2 100644 --- a/Assets/Scripts/Gameplay/GameplayManager.cs +++ b/Assets/Scripts/Gameplay/GameplayManager.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using UnityEngine; @@ -19,6 +20,7 @@ public class PlayerGameData public int endIndex; public Transform playersParent; public List playerPawns; + public int totalPawnsFinished = 0; } public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader @@ -30,7 +32,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader [SerializeField] private PlayerGameData[] playerGameDatas; - private PlayerTypes currentPlayerTurn; + private PlayerTypes currentPlayerTypeTurn; private int currentPlayerTurnIndex = 0; private List playerTypes = new List(); @@ -47,7 +49,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader get; private set; } - private bool HasRolledSix = false; + private bool CanRollDiceAgain = false; // used for when you get a 6 or when you reach the finish point public void Initialize() { @@ -60,14 +62,14 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader CanRollDice = true; InitCurrentGamePlayerInfo( - new List { PlayerTypes.Player1, PlayerTypes.Player2, PlayerTypes.Player3, PlayerTypes.Player4 }); + new List { PlayerTypes.Player1, PlayerTypes.Player3 }); } // TODO :: Call based on 2P/3P/4P public void InitCurrentGamePlayerInfo(List playerTypes) { this.playerTypes = playerTypes; - currentPlayerTurn = playerTypes[currentPlayerTurnIndex]; + currentPlayerTypeTurn = playerTypes[currentPlayerTurnIndex]; // initialize the board based on the player types foreach (PlayerGameData playerGameData in playerGameDatas) @@ -83,6 +85,8 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader playerGameDatasDict[playerGameData.playerType].playerPawns = new List(); foreach (Transform playerPawnChild in playerGameData.playersParent) { + if (!playerPawnChild.gameObject.activeInHierarchy) continue; + playerGameDatasDict[playerGameData.playerType].playerPawns.Add(playerPawnChild.GetComponent()); } } @@ -91,7 +95,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader public void EnablePlayerSelectionStates(bool state) { - foreach (PlayerPawn playerPawn in playerGameDatasDict[currentPlayerTurn].playerPawns) + foreach (PlayerPawn playerPawn in playerGameDatasDict[currentPlayerTypeTurn].playerPawns) { if (playerPawn.GetPlayerState() == PlayerState.InFinishingPath) continue; @@ -104,7 +108,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader CanRollDice = false; // add core dice logic here - Debug.Log($"LUDO :: rolledVal: {rolledVal}"); + Debug.Log($"Tile Index :: LUDO :: rolledVal: {rolledVal} :: {currentPlayerTypeTurn}"); diceRolledValue = rolledVal; if (rolledVal == Ludo_3D_Constants.Max_Dice_Rolls) @@ -113,7 +117,23 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader // also play a simple animation before selecting EnablePlayerSelectionStates(true); - HasRolledSix = true; + CanRollDiceAgain = true; + + bool AreAllPawnsInFinishingPath = false; + foreach (var pawn in playerGameDatasDict[currentPlayerTypeTurn].playerPawns) + { + if (pawn.GetPlayerState() == PlayerState.InFinishingPath && pawn.GetPlayerState() != PlayerState.HasFinished) + { + AreAllPawnsInFinishingPath = true; + continue; + } + + AreAllPawnsInFinishingPath = false; + break; + } + + if (AreAllPawnsInFinishingPath) + CanRollDice = true; pointerMeshRend.material = selectMat; // pointerMeshRend.materials[0] = selectMat; @@ -121,33 +141,41 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader else // if there are any other pawns that are in safe or moving state { // for player's logic - IEnumerable availPlayers = playerGameDatasDict[currentPlayerTurn].playerPawns.Select(pawn => pawn) + IEnumerable availPlayers = playerGameDatasDict[currentPlayerTypeTurn].playerPawns.Select(pawn => pawn) .Where(pawn => pawn.GetPlayerState() == PlayerState.InSafeZone || pawn.GetPlayerState() == PlayerState.Moving || pawn.GetPlayerState() == PlayerState.InFinishingPath); - + int customAvailPlayers = availPlayers.Count(); + foreach (PlayerPawn playerPawn in availPlayers) { Debug.Log($"## playerPawn.GetPlayerState(): {playerPawn.GetPlayerState()}"); if (playerPawn.GetPlayerState() == PlayerState.InFinishingPath) { - // TODO :: if rolled dice value <= rem tiles to complete in finishing path - // TODO :: playerPawn.SetPlayerSelectionState(true); - // if (diceRolledValue < 6 - playerPawn.CurrentTileIndex) // TODO :: Change hardcoded value - } - else - { - playerPawn.SetPlayerSelectionState(true); + if (diceRolledValue <= tilesManager.GetFinishingTileDataLength(currentPlayerTypeTurn) - (playerPawn.CurrentTileIndex + 1)) + { + playerPawn.SetPlayerSelectionState(true); + } + else + { + customAvailPlayers--; + } + + continue; } + + playerPawn.SetPlayerSelectionState(true); } - if (availPlayers.Count() < 1) + // if (availPlayers.Count() < 1) + Debug.Log($"CustomAvailablePlayers: {customAvailPlayers}"); + if (customAvailPlayers < 1) { SwitchPlayer(); CanRollDice = true; } - HasRolledSix = false; + CanRollDiceAgain = false; } } @@ -155,7 +183,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader { EnablePlayerSelectionStates(false); - PlayerGameData playerGameData = playerGameDatasDict[currentPlayerTurn]; + PlayerGameData playerGameData = playerGameDatasDict[currentPlayerTypeTurn]; if (playerPawn.GetPlayerState() == PlayerState.InHome) { @@ -169,90 +197,221 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader return; } - else if (playerPawn.GetPlayerState() == PlayerState.InSafeZone || playerPawn.GetPlayerState() == PlayerState.Moving - || playerPawn.GetPlayerState() == PlayerState.InFinishingPath) + else if (playerPawn.GetPlayerState() == PlayerState.InFinishingPath + || playerPawn.CurrentTileIndex == playerGameDatasDict[currentPlayerTypeTurn].endIndex) + { + int finishingPathIndex = GetNextFinishingTileIndex(playerPawn); + int targetIdx = finishingPathIndex + diceRolledValue > tilesManager.GetFinishingTileDataLength(currentPlayerTypeTurn) - 1 ? + tilesManager.GetFinishingTileDataLength(currentPlayerTypeTurn) - 1 : finishingPathIndex + diceRolledValue; + + Debug.Log($"TargetIdx: {targetIdx}"); + MoveThroughFinishingPath(playerPawn, finishingPathIndex, targetIdx); + } + else if (playerPawn.GetPlayerState() == PlayerState.InSafeZone || playerPawn.GetPlayerState() == PlayerState.Moving) { // move based on the dice value + Debug.Log($"Tile Index :: currentTileIndex: {playerPawn.CurrentTileIndex}"); + int nextTileIdx = GetNextGeneralTileIndex(playerPawn); + int targetIdx = playerPawn.CurrentTileIndex + diceRolledValue; - MoveThroughTiles(playerPawn, playerPawn.CurrentTileIndex + 1, targetIndex: playerPawn.CurrentTileIndex + diceRolledValue); + if (nextTileIdx == 0) + targetIdx = targetIdx - playerPawn.CurrentTileIndex; + + Tile currentSittingTile = tilesManager.RetrieveTileBasedOnIndex(playerPawn.CurrentTileIndex); + if (currentSittingTile.IsSafeZone) + { + currentSittingTile.UpdateSafeZonePlayerData(currentPlayerTypeTurn); + } + + MoveThroughTiles(playerPawn, nextTileIdx, targetIndex: targetIdx); } } - private void SwitchPlayer() + private int GetNextGeneralTileIndex(PlayerPawn playerPawn) { - if (!HasRolledSix) + return playerPawn.CurrentTileIndex == tilesManager.GetGeneralTilesLength() - 1 ? 0 : playerPawn.CurrentTileIndex + 1; + } + + private int GetNextFinishingTileIndex(PlayerPawn playerPawn) + { + return playerPawn.CurrentTileIndex > tilesManager.GetFinishingTileDataLength(currentPlayerTypeTurn) - 1 ? 0 : playerPawn.CurrentTileIndex + 1; + } + + private void SwitchPlayer(PlayerPawn playerPawn = null) + { + if (!CanRollDiceAgain) { - if (currentPlayerTurn == playerTypes[playerTypes.Count - 1]) + Debug.Log($"currentPlayerTurn: {currentPlayerTypeTurn}"); + Debug.Log($"currentPlayerTurnIndex: {currentPlayerTurnIndex}"); + + if (playerTypes.Count == 1) + { + Debug.LogError($"GAME IS OVER"); + return; + } + + if (currentPlayerTypeTurn == playerTypes[playerTypes.Count - 1]) { currentPlayerTurnIndex = 0; - currentPlayerTurn = playerTypes[currentPlayerTurnIndex]; + currentPlayerTypeTurn = playerTypes[currentPlayerTurnIndex]; } else { currentPlayerTurnIndex++; - currentPlayerTurn = playerTypes[currentPlayerTurnIndex]; - Debug.Log($"currentPlayerTurn: {currentPlayerTurn}"); - Debug.Log($"currentPlayerTurnIndex: {currentPlayerTurnIndex}"); + currentPlayerTypeTurn = playerTypes[currentPlayerTurnIndex]; } } - var tempPos = playerGameDatasDict[currentPlayerTurn].playerCornerEntity.transform.position; + var tempPos = playerGameDatasDict[currentPlayerTypeTurn].playerCornerEntity.transform.position; pointerDebug.position = new Vector3(tempPos.x, 3f, tempPos.z); pointerMeshRend.material = turnMat; // pointerMeshRend.materials[0] = turnMat; + + if (playerPawn) + playerPawn.SetPlayerState(tilesManager.RetrieveTileBasedOnIndex(playerPawn.CurrentTileIndex).IsSafeZone ? PlayerState.InSafeZone : PlayerState.Moving); } private void MoveThroughTiles(PlayerPawn playerPawn, int index, int targetIndex) { - Tile tile = tilesManager.RetrieveTileBasedOnIndex(index); - playerPawn.MoveToTile( - tilesManager.RetrieveTileBasedOnIndex(index).transform.position, - onComplete: () => + Debug.Log($"Tile Index :: nextIndex: {index}, targetIndex: {targetIndex}"); + + Tile nextTile = tilesManager.RetrieveTileBasedOnIndex(index); + Vector3 targetPosition = tilesManager.RetrieveTileBasedOnIndex(index).CenterPlacementPosition; + + if (index == targetIndex) // is next index the targetIndex + { + Tile targetTile = tilesManager.RetrieveTileBasedOnIndex(targetIndex); + if (targetTile.IsSafeZone) { - if (playerPawn.GetPlayerState() == PlayerState.InFinishingPath || index == playerGameDatasDict[currentPlayerTurn].endIndex) + if (targetTile.PlayerTypesCount == 1) { - // MoveThroughTiles(playerPawn, index, targetIndex); - Debug.Log($"IsMovingThroughFinishingPath({currentPlayerTurn}): {index + 1} :: {playerGameDatasDict[currentPlayerTurn].endIndex}"); - MoveThroughFinishingPath(playerPawn, 0, targetIndex - index); - } - else if (index + 1 <= targetIndex) - { - MoveThroughTiles(playerPawn, index + 1, targetIndex); + if (!targetTile.ContainsPlayerType(currentPlayerTypeTurn)) // means it is a new player type, the second one + { + PlayerTypes initialPlayerType = targetTile.GetFirstPlayerType(); + var playerPawnsCount = targetTile.GetPlayerPawnsCountInTile(initialPlayerType); + + // rearrange already existing player from center position to it's saved transform + for (int idx = 0; idx < playerPawnsCount; idx++) + { + targetTile.IterateAndGetPlayerPawn(initialPlayerType, idx).MoveToTileSubPosition(targetTile.GetPlacementPoint(initialPlayerType).position); + } + + targetTile.InitPlayerPawn(playerPawn, currentPlayerTypeTurn); + targetPosition = targetTile.GetPlacementPoint(currentPlayerTypeTurn).position; + } + else + { + targetPosition = targetTile.CenterPlacementPosition; + } } else { - if (tile.PlayerPawn != null) + // TODO :: Check the data if it's consistent + if (!targetTile.ContainsPlayerType(currentPlayerTypeTurn)) { - // send this pawn back to base + targetTile.InitPlayerPawn(playerPawn, currentPlayerTypeTurn); + targetPosition = targetTile.GetPlacementPoint(currentPlayerTypeTurn).position; } + else + { + targetPosition = targetTile.GetPlacementPoint(currentPlayerTypeTurn).position; + } + } - tile.InitPlayerPawn(playerPawn); - SwitchPlayer(); + // TODO :: Introduce a swapping mechanism + } + else + { + // TODO :: Move code to onComplete callback + if (targetTile.PlayerPawn != null) // TODO :: Improve this logic, use a collection + { + // TODO :: send this pawn back to base + } + } + } + + playerPawn.MoveToTile( + targetPosition, + onComplete: () => + { + diceRolledValue--; + if (diceRolledValue > 0) + { + int nextTileIndex = GetNextGeneralTileIndex(playerPawn); + + if (playerPawn.GetPlayerState() == PlayerState.InFinishingPath || index == playerGameDatasDict[currentPlayerTypeTurn].endIndex) + { + // MoveThroughTiles(playerPawn, index, targetIndex); + Debug.Log($"TargetIdx: {targetIndex - index}"); + MoveThroughFinishingPath(playerPawn, 0, targetIndex - index); + } + else if (nextTileIndex <= targetIndex) + { + if (nextTileIndex == 0) + targetIndex = targetIndex - playerPawn.CurrentTileIndex; + + MoveThroughTiles(playerPawn, nextTileIndex, targetIndex); + } + } + else + { + nextTile.InitPlayerPawn(playerPawn, currentPlayerTypeTurn); + SwitchPlayer(playerPawn); + CanRollDice = true; } }, index); - - CanRollDice = true; - playerPawn.SetPlayerState(tilesManager.RetrieveTileBasedOnIndex(playerPawn.CurrentTileIndex).IsSafeZone ? PlayerState.InSafeZone : PlayerState.Moving); } private void MoveThroughFinishingPath(PlayerPawn playerPawn, int index, int targetIndex) { playerPawn.SetPlayerState(PlayerState.InFinishingPath); playerPawn.MoveToTile( - tilesManager.RetrievePositionForFinishingTile(currentPlayerTurn, index).position, + tilesManager.RetrievePositionForFinishingTile(currentPlayerTypeTurn, index).position, onComplete: () => { - Debug.Log($"index: {index}, targetIndex: {targetIndex}"); - if (index + 1 < targetIndex) + diceRolledValue--; + + Debug.Log($"DiceRolledValue: {diceRolledValue}"); + if (diceRolledValue > 0) { - // MoveThroughTiles(playerPawn, index, targetIndex); - MoveThroughFinishingPath(playerPawn, index + 1, targetIndex); + int tileIndex = GetNextFinishingTileIndex(playerPawn); + Debug.Log($"tileIndex: {tileIndex}, targetIndex: {targetIndex}"); + if (tileIndex <= targetIndex) + { + // MoveThroughTiles(playerPawn, index, targetIndex); + MoveThroughFinishingPath(playerPawn, tileIndex, targetIndex); + } } else { - SwitchPlayer(); + if (playerPawn.CurrentTileIndex == tilesManager.GetFinishingTileDataLength(currentPlayerTypeTurn) - 1) + { + playerPawn.SetPlayerState(PlayerState.HasFinished); + playerGameDatasDict[currentPlayerTypeTurn].totalPawnsFinished++; + + if (playerGameDatasDict[currentPlayerTypeTurn].totalPawnsFinished == playerGameDatasDict[currentPlayerTypeTurn].playerPawns.Count) + { + CanRollDiceAgain = false; + + SwitchPlayer(); + if (playerTypes.Contains(currentPlayerTypeTurn)) + playerTypes.Remove(currentPlayerTypeTurn); + + Debug.Log($"PlayerTypes: {playerTypes.Count}"); + } + else + { + CanRollDiceAgain = true; + } + } + else + { + SwitchPlayer(); + } + + CanRollDice = true; } }, index); diff --git a/Assets/Scripts/Gameplay/Player/PlayerPawn.cs b/Assets/Scripts/Gameplay/Player/PlayerPawn.cs index a78335c..a07a045 100644 --- a/Assets/Scripts/Gameplay/Player/PlayerPawn.cs +++ b/Assets/Scripts/Gameplay/Player/PlayerPawn.cs @@ -32,9 +32,9 @@ public class PlayerPawn : MonoBehaviour } } - public void CheckCurrentTileIndex(int maxTiles) + public void SetCurrentTileIndex(int tileIndex) { - CurrentTileIndex = CurrentTileIndex == maxTiles ? 0 : CurrentTileIndex; + CurrentTileIndex = tileIndex; } public void MoveToTile(Vector3 startingPoint, Action onComplete, int tileIndex) @@ -43,6 +43,11 @@ public class PlayerPawn : MonoBehaviour transform.DOMove(startingPoint, 0.1f).onComplete = () => onComplete?.Invoke(); } + public void MoveToTileSubPosition(Vector3 targetPoint) + { + transform.DOMove(targetPoint, 0.1f); + } + // when he is defeated public void MoveBackToHome() { diff --git a/Assets/Scripts/Input/DiceRoller.cs b/Assets/Scripts/Input/DiceRoller.cs index 175bc93..886feeb 100644 --- a/Assets/Scripts/Input/DiceRoller.cs +++ b/Assets/Scripts/Input/DiceRoller.cs @@ -4,6 +4,8 @@ using UnityEngine; public class DiceRoller : MonoBehaviour { + [SerializeField] private int diceTestValue = 0; + private InputManager inputManager; private void OnMouseDown() @@ -14,9 +16,18 @@ public class DiceRoller : MonoBehaviour OnDiceRolled(); } + private void Update() + { + inputManager = inputManager == null ? InterfaceManager.Instance?.GetInterfaceInstance() : inputManager; + if (!inputManager.GameplayManager.CanRollDice) return; + + if (Input.GetKeyDown(KeyCode.Space)) + OnDiceRolled(); + } + private void OnDiceRolled() { - int currentRolledVal = Random.Range(1, Ludo_3D_Constants.Max_Dice_Rolls + 1); + int currentRolledVal = diceTestValue != 0 ? diceTestValue : Random.Range(1, Ludo_3D_Constants.Max_Dice_Rolls + 1); inputManager.SetDiceRollValue(currentRolledVal); } } diff --git a/Assets/Scripts/Tile/Tile.cs b/Assets/Scripts/Tile/Tile.cs index e381473..50ca995 100644 --- a/Assets/Scripts/Tile/Tile.cs +++ b/Assets/Scripts/Tile/Tile.cs @@ -1,17 +1,106 @@ +using System.Collections.Generic; +using System.Linq; using UnityEngine; +[System.Serializable] +public class PlayerTileData +{ + public int playerCount; + public Transform placementTransform; + public List playerPawns; +} + public class Tile : MonoBehaviour { [SerializeField] private bool isSafeZone = false; - public PlayerPawn PlayerPawn + [SerializeField] private Transform centerPlacementPoint; + [SerializeField] private Transform[] placementPoints; + + private int lastOccupiedIndex = 0; + + public PlayerPawn PlayerPawn // Change implementation { get; private set; } + private Queue placementQueue = new Queue(); + private Dictionary playerTypesDict; + + public int PlayerTypesCount => playerTypesDict.Count; + public bool HasMoreThanOnePlayerType => playerTypesDict.Count > 1; public bool IsSafeZone => isSafeZone; - public void InitPlayerPawn(PlayerPawn playerPawn) + public Vector3 CenterPlacementPosition => centerPlacementPoint.position; + + public bool ContainsPlayerType(PlayerTypes playerType) => playerTypesDict.ContainsKey(playerType); + + public void Init(int playerTypesCount) + { + if (isSafeZone) + { + playerTypesDict = new Dictionary(); + foreach (var placement in placementPoints) + { + placementQueue.Enqueue(placement); + } + } + } + + public void InitPlayerPawn(PlayerPawn playerPawn, PlayerTypes playerType) { PlayerPawn = playerPawn; + if (isSafeZone) + { + if (!playerTypesDict.ContainsKey(playerType)) + { + playerTypesDict.Add( + playerType, + new PlayerTileData { playerCount = 1, placementTransform = placementQueue.Dequeue(), // TODO :: Change indexing logic + playerPawns = new List { playerPawn } + }); + } + else + { + playerTypesDict[playerType].playerCount++; + playerTypesDict[playerType].playerPawns.Add(playerPawn); + } + } + } + + public void UpdateSafeZonePlayerData(PlayerTypes playerType) + { + if (!IsSafeZone) return; + + if (playerTypesDict.ContainsKey(playerType)) + { + if (playerTypesDict[playerType].playerCount > 0) + { + playerTypesDict[playerType].playerCount--; + playerTypesDict[playerType].playerPawns.RemoveAt(playerTypesDict[playerType].playerPawns.Count - 1); + if (playerTypesDict[playerType].playerCount == 0) + { + placementQueue.Enqueue(playerTypesDict[playerType].placementTransform); + playerTypesDict.Remove(playerType); + lastOccupiedIndex--; + } + } + } + } + + public PlayerTypes GetFirstPlayerType() => playerTypesDict.Keys.FirstOrDefault(); + + public int GetPlayerPawnsCountInTile(PlayerTypes playerType) + { + return playerTypesDict[playerType].playerPawns.Count; + } + + public PlayerPawn IterateAndGetPlayerPawn(PlayerTypes playerType, int index) + { + return playerTypesDict[playerType].playerPawns[index]; + } + + public Transform GetPlacementPoint(PlayerTypes playerType) + { + return playerTypesDict[playerType].placementTransform; } } diff --git a/Assets/Scripts/Tile/TilesManager.cs b/Assets/Scripts/Tile/TilesManager.cs index e0cc9e6..af6d5dd 100644 --- a/Assets/Scripts/Tile/TilesManager.cs +++ b/Assets/Scripts/Tile/TilesManager.cs @@ -17,10 +17,6 @@ public class TilesManager : MonoBehaviour, IBootLoader, IDataLoader, IBase [SerializeField] private TileData[] tileDatas; private GameplayManager gameplayManager; - public int FinishingTileDataLength - { - get; private set; - } private Dictionary> finishingTileDataPairs = new Dictionary>(); @@ -42,15 +38,20 @@ public class TilesManager : MonoBehaviour, IBootLoader, IDataLoader, IBase finishingTileDataPairs[tileData.playerType].Add(child); } } - - // FinishingTileDataLength = finishingTileDataPairs.FirstOrDefault().Value.Count; + + foreach (var tile in generalTiles) + { + tile.Init(gameplayManager.PlayerTypesCollection.Count); + } } + public int GetFinishingTileDataLength(PlayerTypes playerType) => finishingTileDataPairs[playerType].Count; + public int GetGeneralTilesLength() => generalTiles.Length; public Tile RetrieveTileBasedOnIndex(int index) { - + Debug.Log($"RetrieveTileBasedOnIndex: Index: {index}"); return index == generalTiles.Length ? generalTiles[0] : generalTiles[index]; }