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 bool CanRollDiceAgain = false; // used for when you get a 6 or when you reach the finish point
|
||||||
|
private int diceSixRollCounter = 0;
|
||||||
|
|
||||||
public void Initialize()
|
public void Initialize()
|
||||||
{
|
{
|
||||||
@ -92,8 +93,8 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
|||||||
|
|
||||||
// initialize the player list from UI.
|
// initialize the player list from UI.
|
||||||
|
|
||||||
InitPlayerTypesForLAN(null);
|
// InitPlayerTypesForLAN(null);
|
||||||
//InitPlayerTypesForBotMatch(PlayerType.Player1, 3);
|
InitPlayerTypesForBotMatch(PlayerType.Player1, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO :: Call when the UI selection is made and game starts
|
// 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;
|
if (botTypesInGame.Contains(currentPlayerTypeTurn)) return;
|
||||||
|
|
||||||
OnDiceRolled(rolledVal);
|
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)
|
if (canSwitchPlayer && !CanRollDiceAgain)
|
||||||
{
|
{
|
||||||
@ -238,11 +240,18 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
|||||||
SwitchPlayer();
|
SwitchPlayer();
|
||||||
SetCanRollDiceForUser(currentPlayerTypeTurn, true);
|
SetCanRollDiceForUser(currentPlayerTypeTurn, true);
|
||||||
}
|
}
|
||||||
// else if (botTypesInGame.Contains(currentPlayerTypeTurn) && CanRollDiceAgain)
|
}
|
||||||
// {
|
|
||||||
// Debug.Log($"Invoking RollDiceForBot");
|
private bool CheckForMaxDiceRollAttempt()
|
||||||
// Invoke(nameof(RollDiceForBot), 1f);
|
{
|
||||||
// }
|
if (diceSixRollCounter == 3)
|
||||||
|
{
|
||||||
|
CanRollDiceAgain = false;
|
||||||
|
SwitchPlayer();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RollDiceForBot()
|
private void RollDiceForBot()
|
||||||
@ -254,7 +263,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
|||||||
|
|
||||||
SelectPawnFromBotBase();
|
SelectPawnFromBotBase();
|
||||||
|
|
||||||
CheckForPlayerSwitching();
|
OnNoMovesLeft();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO :: Call right after the dice is rolled with the animation
|
// 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
|
// provide option to select a pawn from the list
|
||||||
// also play a simple animation before selecting
|
// also play a simple animation before selecting
|
||||||
CanRollDiceAgain = true;
|
CanRollDiceAgain = true;
|
||||||
|
diceSixRollCounter++;
|
||||||
pointerMeshRend.material = selectMat;
|
pointerMeshRend.material = selectMat;
|
||||||
|
|
||||||
foreach (var playerPawn in playerGameDatasDict[currentPlayerTypeTurn].playerPawnsDict)
|
foreach (var playerPawn in playerGameDatasDict[currentPlayerTypeTurn].playerPawnsDict)
|
||||||
@ -551,11 +561,16 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
|||||||
onComplete: () =>
|
onComplete: () =>
|
||||||
{
|
{
|
||||||
playerGameDatasDict[playerGameData.playerType].totalPawnsInHome--;
|
playerGameDatasDict[playerGameData.playerType].totalPawnsInHome--;
|
||||||
|
|
||||||
SetCanRollDiceForUser(playerPawn.PlayerType, true);
|
|
||||||
UpdatePlayerState(playerPawn, PlayerState.InSafeZone);
|
UpdatePlayerState(playerPawn, PlayerState.InSafeZone);
|
||||||
|
if (CheckForMaxDiceRollAttempt())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (playerPawn.IsBotPlayer)
|
if (playerPawn.IsBotPlayer)
|
||||||
CheckDiceRollForBot(playerPawn);
|
CheckDiceRollForBot(playerPawn);
|
||||||
|
else
|
||||||
|
SetCanRollDiceForUser(playerPawn.PlayerType, true);
|
||||||
|
|
||||||
}, playerGameData.startIndex);
|
}, playerGameData.startIndex);
|
||||||
|
|
||||||
@ -651,6 +666,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
|||||||
currentPlayerTypeTurn = allPlayerTypes[currentPlayerTurnIndex];
|
currentPlayerTypeTurn = allPlayerTypes[currentPlayerTurnIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
diceSixRollCounter = 0;
|
||||||
diceText.text = $"{0}";
|
diceText.text = $"{0}";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -745,8 +761,13 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
|||||||
pawn.MoveBackToHome(playerBasePos);
|
pawn.MoveBackToHome(playerBasePos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (CheckForMaxDiceRollAttempt())
|
||||||
|
{
|
||||||
|
nextTile.InitPlayerPawn(playerPawn, currentPlayerTypeTurn);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
CanRollDiceAgain = true;
|
CanRollDiceAgain = true;
|
||||||
|
|
||||||
if (playerPawn.IsBotPlayer)
|
if (playerPawn.IsBotPlayer)
|
||||||
CheckDiceRollForBot(playerPawn);
|
CheckDiceRollForBot(playerPawn);
|
||||||
else
|
else
|
||||||
@ -754,6 +775,17 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
|||||||
}
|
}
|
||||||
|
|
||||||
nextTile.InitPlayerPawn(playerPawn, currentPlayerTypeTurn);
|
nextTile.InitPlayerPawn(playerPawn, currentPlayerTypeTurn);
|
||||||
|
if (CheckForMaxDiceRollAttempt())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (CheckForMaxDiceRollAttempt())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SwitchPlayer(playerPawn);
|
SwitchPlayer(playerPawn);
|
||||||
@ -867,11 +899,17 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
|||||||
{
|
{
|
||||||
CanRollDiceAgain = true;
|
CanRollDiceAgain = true;
|
||||||
if (playerPawn.IsBotPlayer)
|
if (playerPawn.IsBotPlayer)
|
||||||
CheckDiceRollForBot(playerPawn);
|
CheckDiceRollForBot(playerPawn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (CheckForMaxDiceRollAttempt())
|
||||||
|
{
|
||||||
|
SetCanRollDiceForUser(playerPawn.PlayerType, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SwitchPlayer();
|
SwitchPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user