Added logic for switching player when player gets six through rolling dice 3 times.
This commit is contained in:
parent
a291dff121
commit
c3ab5552ea
@ -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);
|
||||
}
|
||||
|
||||
CanRollDiceAgain = true;
|
||||
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);
|
||||
@ -872,6 +904,12 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
||||
}
|
||||
else
|
||||
{
|
||||
if (CheckForMaxDiceRollAttempt())
|
||||
{
|
||||
SetCanRollDiceForUser(playerPawn.PlayerType, true);
|
||||
return;
|
||||
}
|
||||
|
||||
SwitchPlayer();
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user