From c3ab5552eafe3ceccfbeb3b19059f5337eb6d598 Mon Sep 17 00:00:00 2001 From: Ashby Issac Date: Thu, 29 Jan 2026 21:15:48 +0530 Subject: [PATCH] Added logic for switching player when player gets six through rolling dice 3 times. --- Assets/Scripts/Gameplay/GameplayManager.cs | 66 +++++++++++++++++----- 1 file changed, 52 insertions(+), 14 deletions(-) diff --git a/Assets/Scripts/Gameplay/GameplayManager.cs b/Assets/Scripts/Gameplay/GameplayManager.cs index ed3fe6e..d03313c 100644 --- a/Assets/Scripts/Gameplay/GameplayManager.cs +++ b/Assets/Scripts/Gameplay/GameplayManager.cs @@ -77,6 +77,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader } private bool CanRollDiceAgain = false; // used for when you get a 6 or when you reach the finish point + private int diceSixRollCounter = 0; public void Initialize() { @@ -92,8 +93,8 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader // initialize the player list from UI. - InitPlayerTypesForLAN(null); - //InitPlayerTypesForBotMatch(PlayerType.Player1, 3); + // InitPlayerTypesForLAN(null); + InitPlayerTypesForBotMatch(PlayerType.Player1, 3); } // TODO :: Call when the UI selection is made and game starts @@ -227,10 +228,11 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader if (botTypesInGame.Contains(currentPlayerTypeTurn)) return; OnDiceRolled(rolledVal); - CheckForPlayerSwitching(); + OnNoMovesLeft(); } - private void CheckForPlayerSwitching() + // Summary :: Function will be called and effective when a dice is rolled and no selection of pawns is made. + private void OnNoMovesLeft() { if (canSwitchPlayer && !CanRollDiceAgain) { @@ -238,11 +240,18 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader SwitchPlayer(); SetCanRollDiceForUser(currentPlayerTypeTurn, true); } - // else if (botTypesInGame.Contains(currentPlayerTypeTurn) && CanRollDiceAgain) - // { - // Debug.Log($"Invoking RollDiceForBot"); - // Invoke(nameof(RollDiceForBot), 1f); - // } + } + + private bool CheckForMaxDiceRollAttempt() + { + if (diceSixRollCounter == 3) + { + CanRollDiceAgain = false; + SwitchPlayer(); + return true; + } + + return false; } private void RollDiceForBot() @@ -254,7 +263,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader SelectPawnFromBotBase(); - CheckForPlayerSwitching(); + OnNoMovesLeft(); } // TODO :: Call right after the dice is rolled with the animation @@ -430,6 +439,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader // provide option to select a pawn from the list // also play a simple animation before selecting CanRollDiceAgain = true; + diceSixRollCounter++; pointerMeshRend.material = selectMat; foreach (var playerPawn in playerGameDatasDict[currentPlayerTypeTurn].playerPawnsDict) @@ -551,11 +561,16 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader onComplete: () => { playerGameDatasDict[playerGameData.playerType].totalPawnsInHome--; - - SetCanRollDiceForUser(playerPawn.PlayerType, true); UpdatePlayerState(playerPawn, PlayerState.InSafeZone); + if (CheckForMaxDiceRollAttempt()) + { + return; + } + if (playerPawn.IsBotPlayer) CheckDiceRollForBot(playerPawn); + else + SetCanRollDiceForUser(playerPawn.PlayerType, true); }, playerGameData.startIndex); @@ -651,6 +666,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader currentPlayerTypeTurn = allPlayerTypes[currentPlayerTurnIndex]; } + diceSixRollCounter = 0; diceText.text = $"{0}"; } @@ -745,8 +761,13 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader pawn.MoveBackToHome(playerBasePos); } + if (CheckForMaxDiceRollAttempt()) + { + nextTile.InitPlayerPawn(playerPawn, currentPlayerTypeTurn); + return; + } + CanRollDiceAgain = true; - if (playerPawn.IsBotPlayer) CheckDiceRollForBot(playerPawn); else @@ -754,6 +775,17 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader } nextTile.InitPlayerPawn(playerPawn, currentPlayerTypeTurn); + if (CheckForMaxDiceRollAttempt()) + { + return; + } + } + else + { + if (CheckForMaxDiceRollAttempt()) + { + return; + } } SwitchPlayer(playerPawn); @@ -867,11 +899,17 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader { CanRollDiceAgain = true; if (playerPawn.IsBotPlayer) - CheckDiceRollForBot(playerPawn); + CheckDiceRollForBot(playerPawn); } } else { + if (CheckForMaxDiceRollAttempt()) + { + SetCanRollDiceForUser(playerPawn.PlayerType, true); + return; + } + SwitchPlayer(); }