diff --git a/Assets/Scenes/Game.unity b/Assets/Scenes/Game.unity index b76522b..39cfbcc 100644 --- a/Assets/Scenes/Game.unity +++ b/Assets/Scenes/Game.unity @@ -22667,6 +22667,7 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 5608193481571390226} + - component: {fileID: 5608193481571390228} m_Layer: 5 m_Name: GameOverPopup m_TagString: Untagged @@ -22674,6 +22675,31 @@ GameObject: m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 +--- !u!114 &5608193481571390228 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5608193481571390227} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 178d988f5211b4ef5b8c2df230b708d4, type: 3} + m_Name: + m_EditorClassIdentifier: + popupScaleContent: {fileID: 5608193481571390226} + zoomDuration: 0.5 + popupType: 5 + popupScalerType: 1 + canvasGroup: {fileID: 0} + fadeDuration: 0 + playAgainBtn: {fileID: 5608193482985030359} + mainMenuBtn: {fileID: 5608193483181475110} + texts: + - {fileID: 5608193483287721217} + - {fileID: 28556636} + - {fileID: 300136906} + - {fileID: 1260155923} --- !u!1 &5608193481588389864 GameObject: m_ObjectHideFlags: 0 @@ -26175,7 +26201,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 0 + m_IsActive: 1 --- !u!222 &5608193482973815122 CanvasRenderer: m_ObjectHideFlags: 0 @@ -27386,7 +27412,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!222 &5608193483354237948 CanvasRenderer: m_ObjectHideFlags: 0 @@ -27538,7 +27564,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!222 &5608193483406443892 CanvasRenderer: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Gameplay/GameModeHandler.cs b/Assets/Scripts/Gameplay/GameModeHandler.cs index ee93c89..0ae054a 100644 --- a/Assets/Scripts/Gameplay/GameModeHandler.cs +++ b/Assets/Scripts/Gameplay/GameModeHandler.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using UnityEngine; @@ -7,11 +8,28 @@ public enum GameModeType Bot, } +[Serializable] +public class PVPModeData +{ + public List types; + public List names; +} + +[Serializable] +public class BotModeData +{ + public PlayerData playerData; + public int botCount; +} + public class GameModeHandler : MonoBehaviour, IBase, IBootLoader, IDataLoader { private GameplayManager gameplayManager; - public GameModeType GameModeType + private PVPModeData pvpModeData; + private BotModeData botModeData; + + public GameModeType CurrentGameModeType { get; private set; } @@ -26,15 +44,39 @@ public class GameModeHandler : MonoBehaviour, IBase, IBootLoader, IDataLoader gameplayManager = InterfaceManager.Instance.GetInterfaceInstance(); } - public void InitPVPModeData(List types) + public void InitPVPModeData(List types, List names) { - GameModeType = GameModeType.PVP; - gameplayManager.InitPlayerTypesForPVP(types); + pvpModeData = new PVPModeData + { + types = types, names = names + }; + + CurrentGameModeType = GameModeType.PVP; + gameplayManager.InitPlayerTypesForPVP(types, names); } - public void InitBotModeData(PlayerType selectedPlayer, int botCount) + public void InitBotModeData(PlayerData playerData, int botCount) { - GameModeType = GameModeType.Bot; - gameplayManager.InitPlayerTypesForBotMatch(selectedPlayer, botCount); + botModeData = new BotModeData + { + playerData = playerData, + botCount = botCount + }; + + CurrentGameModeType = GameModeType.Bot; + gameplayManager.InitPlayerTypesForBotMatch(playerData, botCount); + } + + public void OnGameRestarted() + { + switch (CurrentGameModeType) + { + case GameModeType.PVP: + InitPVPModeData(pvpModeData.types, pvpModeData.names); + break; + case GameModeType.Bot: + InitBotModeData(botModeData.playerData, botModeData.botCount); + break; + } } } diff --git a/Assets/Scripts/Gameplay/GameplayManager.cs b/Assets/Scripts/Gameplay/GameplayManager.cs index 9d5f7d9..317ab3f 100644 --- a/Assets/Scripts/Gameplay/GameplayManager.cs +++ b/Assets/Scripts/Gameplay/GameplayManager.cs @@ -5,33 +5,6 @@ using DG.Tweening; using TMPro; using UnityEngine; -public enum PlayerType -{ - Player1 = 0, - Player2 = 1, - Player3 = 2, - Player4 = 3 -} - -[System.Serializable] -public class PlayerGameData -{ - public PlayerType playerType; - public int startIndex; - public int endIndex; - public Transform playersParent; - public Dictionary playerPawnsDict; - public int totalPawnsInHome = 0; - public int totalPawnsFinished = 0; -} - -[System.Serializable] -public enum MatchType -{ - PVP, - Bot -} - public enum BotMove { FinishingPathMove = 0, @@ -59,18 +32,18 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader private PlayerType currentPlayerTypeTurn; private int currentPlayerTurnIndex = 0; + private List allPlayerTypes = new List(); private List botTypesInGame = new List(); - private List playerRankings = new List(); + + private List playerDatas = new List(); - // private Dictionary playerPawnsDict = new Dictionary>(); private Dictionary playerGameDatasDict = new Dictionary(); - - // botRuntimeMovementData: where can the bot move if a particular dice value is thrown, and based on the value set the bot move for each using a predictive approach and select based on the the priority private Dictionary> botRuntimeMovementData = new Dictionary>(); private TilesManager tilesManager; + private GameManager gameManager; private int diceRolledValue; @@ -84,6 +57,13 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader { get; private set; } + + public int TotalPlayersInGame + { + get; private set; + } + + public List PlayerDatas => playerDatas; public List PlayerTypesCollection => allPlayerTypes; public void Initialize() @@ -95,16 +75,24 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader public void InitializeData() { tilesManager = InterfaceManager.Instance.GetInterfaceInstance(); - - // InitPlayerTypesForBotMatch(PlayerType.Player1, 3); - // InitPlayerTypesForPVP(new List { PlayerType.Player1, PlayerType.Player2}) + gameManager = InterfaceManager.Instance.GetInterfaceInstance(); } - // TODO :: Call when the UI selection is made and game starts - public void InitPlayerTypesForPVP(List types) + public void InitPlayerTypesForPVP(List types, List names) { - // TODO :: 2P, 3P, 4P allPlayerTypes = new List(types); + playerDatas.Clear(); + + TotalPlayersInGame = types.Count; + + for (int i=0; i RollDiceForBot(rollVal)); - diceRollHandler.HandleDiceViewForBot((rollVal) => RollDiceForBot(rollVal), diceValue == 0 ? UnityEngine.Random.Range(1, Ludo_3D_Constants.Max_Dice_Rolls + 1) : diceValue); + diceRollHandler.HandleDiceViewForBot((rollVal) => RollDiceForBot(rollVal)); + // diceRollHandler.HandleDiceViewForBot((rollVal) => RollDiceForBot(rollVal), diceValue == 0 ? UnityEngine.Random.Range(1, Ludo_3D_Constants.Max_Dice_Rolls + 1) : diceValue); } public void OnPawnSelected(PlayerPawn playerPawn) @@ -950,17 +955,18 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader if (allPlayerTypes.Contains(currentPlayerTypeTurn)) { - playerRankings.Add(currentPlayerTypeTurn); allPlayerTypes.Remove(currentPlayerTypeTurn); + playerDatas[(int)currentPlayerTypeTurn].ranking = TotalPlayersInGame - allPlayerTypes.Count; } if (allPlayerTypes.Count == 1) { // Game is over - playerRankings.Add(allPlayerTypes[0]); - allPlayerTypes.Remove(0); + allPlayerTypes.RemoveAt(0); + playerDatas[(int)currentPlayerTypeTurn].ranking = TotalPlayersInGame - allPlayerTypes.Count; // Show Game Over panel + gameManager.OnGameStateChanged(GameState.GameOver); return; } @@ -1019,5 +1025,15 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader playerPawn.GetComponentInChildren().SetPlayerCount(count); } + public void ResetData() + { + playerDatas = null; + botTypesInGame = null; + allPlayerTypes = null; + botRuntimeMovementData = null; + playerGameDatasDict = null; + playerDatas = null; + availPlayers = null; + } } diff --git a/Assets/Scripts/Gameplay/Player/PlayerBase.cs b/Assets/Scripts/Gameplay/Player/PlayerBase.cs index 9172f78..b188032 100644 --- a/Assets/Scripts/Gameplay/Player/PlayerBase.cs +++ b/Assets/Scripts/Gameplay/Player/PlayerBase.cs @@ -24,7 +24,7 @@ public class PlayerBase : MonoBehaviour { for (int idx = 0; idx < basePlacementDatas.Length; idx++) { - playerPawns[idx].Init(basePlacementDatas[idx].playerBaseId, playerType); + playerPawns[idx].Init(basePlacementDatas[idx], playerType); } } diff --git a/Assets/Scripts/Gameplay/Player/PlayerGameData.cs b/Assets/Scripts/Gameplay/Player/PlayerGameData.cs new file mode 100644 index 0000000..94094ad --- /dev/null +++ b/Assets/Scripts/Gameplay/Player/PlayerGameData.cs @@ -0,0 +1,30 @@ +using System.Collections.Generic; +using UnityEngine; + +public enum PlayerType +{ + Player1 = 0, + Player2 = 1, + Player3 = 2, + Player4 = 3 +} + +[System.Serializable] +public class PlayerGameData +{ + public PlayerType playerType; + public int startIndex; + public int endIndex; + public Transform playersParent; + public Dictionary playerPawnsDict; + public int totalPawnsInHome = 0; + public int totalPawnsFinished = 0; +} + +[System.Serializable] +public class PlayerData +{ + public PlayerType playerType; + public string playerName; + public int ranking = 0; +} \ No newline at end of file diff --git a/Assets/Scripts/Gameplay/Player/PlayerGameData.cs.meta b/Assets/Scripts/Gameplay/Player/PlayerGameData.cs.meta new file mode 100644 index 0000000..88bb650 --- /dev/null +++ b/Assets/Scripts/Gameplay/Player/PlayerGameData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e9f4a588284ad4839bff99f31d6d402c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Gameplay/Player/PlayerPawn.cs b/Assets/Scripts/Gameplay/Player/PlayerPawn.cs index 8d97dfb..9a2912d 100644 --- a/Assets/Scripts/Gameplay/Player/PlayerPawn.cs +++ b/Assets/Scripts/Gameplay/Player/PlayerPawn.cs @@ -135,10 +135,12 @@ public class PlayerPawn : MonoBehaviour gameplayManager = gameplayManager ?? InterfaceManager.Instance.GetInterfaceInstance(); } - public void Init(int id, PlayerType playerType) + public void Init(BasePlacementData basePlacementData, PlayerType playerType) { - PlayerId = id; + PlayerId = basePlacementData.playerBaseId; PlayerType = playerType; + + MoveBackToHome(basePlacementData.placementTransform); } public void ShowPlayerCountCanvas(bool show) diff --git a/Assets/Scripts/Input/DiceRollHandler.cs b/Assets/Scripts/Input/DiceRollHandler.cs index 10f4c7b..0f02e47 100644 --- a/Assets/Scripts/Input/DiceRollHandler.cs +++ b/Assets/Scripts/Input/DiceRollHandler.cs @@ -34,8 +34,8 @@ public class DiceRollHandler : MonoBehaviour SoundManager soundManager = InterfaceManager.Instance?.GetInterfaceInstance(); soundManager?.PlayGameSoundClip(SoundType.Dice); - OnUserDiceRollComplete(GetDiceTestVal()); - // diceView.Roll(onComplete: (rolledVal) => OnUserDiceRollComplete(rolledVal), false); + // OnUserDiceRollComplete(GetDiceTestVal()); + diceView.Roll(onComplete: (rolledVal) => OnUserDiceRollComplete(rolledVal), false); } public void HandleDiceViewForBot(Action onComplete) diff --git a/Assets/Scripts/State/GameManager.cs b/Assets/Scripts/State/GameManager.cs index b346a79..1ad3fa3 100644 --- a/Assets/Scripts/State/GameManager.cs +++ b/Assets/Scripts/State/GameManager.cs @@ -4,11 +4,13 @@ public enum GameState { InMenu, InGame, + GameOver, } public class GameManager : MonoBehaviour, IBase, IBootLoader, IDataLoader { private UIManager uiManager; + private GameplayManager gameplayManager; public GameState GameState { @@ -23,21 +25,26 @@ public class GameManager : MonoBehaviour, IBase, IBootLoader, IDataLoader public void InitializeData() { uiManager = InterfaceManager.Instance.GetInterfaceInstance(); + gameplayManager = InterfaceManager.Instance.GetInterfaceInstance(); - GameState = GameState.InMenu; - OnGameStateChanged(GameState); + OnGameStateChanged(GameState.InMenu); } public void OnGameStateChanged(GameState gameState) { + GameState = gameState; switch (gameState) { case GameState.InMenu: + gameplayManager.ResetData(); uiManager.OnInMenuScreen(); break; case GameState.InGame: uiManager.OnInGameScreen(); break; + case GameState.GameOver: + uiManager.OnGameOver(); + break; } } } diff --git a/Assets/Scripts/UI/Managers/UIManager.cs b/Assets/Scripts/UI/Managers/UIManager.cs index 9d4949a..978863b 100644 --- a/Assets/Scripts/UI/Managers/UIManager.cs +++ b/Assets/Scripts/UI/Managers/UIManager.cs @@ -6,6 +6,7 @@ public class UIManager : MonoBehaviour, IBase, IBootLoader, IDataLoader { private GameplayManager gameplayManager; private ScreenManager screenManager; + private PopupManager popupManager; public void Initialize() { @@ -15,6 +16,7 @@ public class UIManager : MonoBehaviour, IBase, IBootLoader, IDataLoader public void InitializeData() { gameplayManager = InterfaceManager.Instance.GetInterfaceInstance(); + popupManager = InterfaceManager.Instance.GetInterfaceInstance(); } public void OnDiceViewInteracted() @@ -35,8 +37,9 @@ public class UIManager : MonoBehaviour, IBase, IBootLoader, IDataLoader screenManager.ShowScreen(ScreenType.InGameHUDScreen); } - public void UpdateSelectedPlayerCount(int playersCount) + public void OnGameOver() { - + popupManager.GetPopup(PopupType.GameOverPopup).InitData(gameplayManager.PlayerDatas); + popupManager.ShowPopup(PopupType.GameOverPopup); } } diff --git a/Assets/Scripts/UI/Pages/Bases/PopupBase.cs b/Assets/Scripts/UI/Pages/Bases/PopupBase.cs index 6be650d..359cf59 100644 --- a/Assets/Scripts/UI/Pages/Bases/PopupBase.cs +++ b/Assets/Scripts/UI/Pages/Bases/PopupBase.cs @@ -9,7 +9,8 @@ public enum PopupType PvAIModePopup, OptionsPopup, InstructionsPopup, - PauseMenuPopup + PauseMenuPopup, + GameOverPopup } public enum PopupScalerType diff --git a/Assets/Scripts/UI/Pages/PopUp/GameOverPopup.cs b/Assets/Scripts/UI/Pages/PopUp/GameOverPopup.cs new file mode 100644 index 0000000..b5f5cf5 --- /dev/null +++ b/Assets/Scripts/UI/Pages/PopUp/GameOverPopup.cs @@ -0,0 +1,65 @@ +using System.Collections; +using System.Collections.Generic; +using TMPro; +using UnityEngine; +using UnityEngine.UI; + +public class GameOverPopup : PopupBase +{ + [SerializeField] private Button playAgainBtn; + [SerializeField] private Button mainMenuBtn; + + [SerializeField] private TextMeshProUGUI[] texts; + + private GameModeHandler gameModeHandler; + private ScreenManager screenManager; + private PopupManager popupManager; + + private void OnEnable() + { + playAgainBtn.onClick.AddListener(OnPlayAgainClicked); + mainMenuBtn.onClick.AddListener(OnMainMenuClicked); + } + + private void OnDisable() + { + playAgainBtn.onClick.RemoveAllListeners(); + mainMenuBtn.onClick.RemoveAllListeners(); + } + + public void OnPlayAgainClicked() + { + HidePopup(); + + gameModeHandler = gameModeHandler == null ? InterfaceManager.Instance.GetInterfaceInstance() : gameModeHandler; + gameModeHandler.OnGameRestarted(); + } + + private void HidePopup() + { + popupManager = popupManager == null ? InterfaceManager.Instance.GetInterfaceInstance() : popupManager; + popupManager.HidePopup(popupType); + } + + public void OnMainMenuClicked() + { + HidePopup(); + + screenManager = screenManager == null ? InterfaceManager.Instance.GetInterfaceInstance() : screenManager; + screenManager.ShowScreen(ScreenType.MenuScreen); + } + + public void InitData(List playerDatas) + { + for (int i = 0; i < playerDatas.Count; i++) + { + if (i == 0) + { + texts[i].text = $"{playerDatas[i].playerName} Wins"; + continue; + } + + texts[i].text = $"{(i+1)}. {playerDatas[i].playerName}"; + } + } +} diff --git a/Assets/Scripts/UI/Pages/PopUp/GameOverPopup.cs.meta b/Assets/Scripts/UI/Pages/PopUp/GameOverPopup.cs.meta new file mode 100644 index 0000000..9bade98 --- /dev/null +++ b/Assets/Scripts/UI/Pages/PopUp/GameOverPopup.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 178d988f5211b4ef5b8c2df230b708d4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/UI/Pages/PopUp/PvAIModePopup.cs b/Assets/Scripts/UI/Pages/PopUp/PvAIModePopup.cs index 6ed6439..97570d1 100644 --- a/Assets/Scripts/UI/Pages/PopUp/PvAIModePopup.cs +++ b/Assets/Scripts/UI/Pages/PopUp/PvAIModePopup.cs @@ -33,6 +33,7 @@ public class PvAIModePopup : PopupBase private ScreenManager screenManager; private SoundManager soundManager; private GameModeHandler gameModeHandler; + private GameManager gameManager; private int selectedPlayerCount; private PlayerType playerType; @@ -58,6 +59,7 @@ public class PvAIModePopup : PopupBase private void Start() { OnPlayerCountSelected(2, twoPlayerBtn); + OnColorSelected(PlayerType.Player1, redBtn); } private void OnDisable() @@ -105,7 +107,10 @@ public class PvAIModePopup : PopupBase popupManager.HidePopup(popupType); gameModeHandler = gameModeHandler == null ? InterfaceManager.Instance.GetInterfaceInstance() : gameModeHandler; - gameModeHandler.InitBotModeData(playerType, selectedPlayerCount - 1); + gameModeHandler.InitBotModeData(new PlayerData{ playerType = playerType, playerName = playerName }, selectedPlayerCount - 1); + + gameManager = gameManager == null ? InterfaceManager.Instance.GetInterfaceInstance() : gameManager; + gameManager.OnGameStateChanged(GameState.InGame); } private void OnClick_CloseButton() diff --git a/Assets/Scripts/UI/Pages/PopUp/PvPModePopup.cs b/Assets/Scripts/UI/Pages/PopUp/PvPModePopup.cs index 4a68f82..2d16876 100644 --- a/Assets/Scripts/UI/Pages/PopUp/PvPModePopup.cs +++ b/Assets/Scripts/UI/Pages/PopUp/PvPModePopup.cs @@ -150,7 +150,7 @@ public class PvPModePopup : PopupBase popupManager.HidePopup(popupType); gameModeHandler = gameModeHandler == null ? InterfaceManager.Instance.GetInterfaceInstance() : gameModeHandler; - gameModeHandler.InitPVPModeData(playerNameMap.Keys.ToList()); + gameModeHandler.InitPVPModeData(playerNameMap.Keys.ToList(), playerNameMap.Values.ToList()); } private void OnClick_SwitchButton()