Compare commits

...

3 Commits

Author SHA1 Message Date
f12bd32c55 Fix : Player count update and visual
- increased treasure size
2026-02-02 11:19:44 +05:30
6b5dd5d0f0 Bug fixes + Refactored/Restructurd changes + Dice roll logical changes.
Remove event deallocation function call in DiceView due to flow breakage because of timer in delay.
Added a debug test bool inside GameplayManager for testing dice logic without dice animation.
Fixed issue with additional steps being kept track for player (PlayerPawn.cs)
Bound restart logic for the Game over popup alone.
Added a maxDiceSixRollCounter for keeping track of how many times 6 can be rolled.
Fixed issue with wrong player being selected while restart is clicked.
Fixed indexing logical errors while finding possible tile data.
Fixed issue with player attacking another player and moving constantly.
Fixed issue with player not switching when there is no option for dice roll.
Handled dice roll logic when pawns are in finishing path.
Fixed indexing issue with availPlayers collection where wrong indexes were being selected for removing from the collection.
Fixed issue with tile data not resetting on restart.
Restructured logic for showing winners inside Game Over popup.
Restructured GameOverPopup and GameOverScreen with respect to showing/hiding screens/popups.
2026-01-31 20:33:50 +05:30
76659bc964 Addressed all pawns in finishing path scenarios. 2026-01-31 01:05:28 +05:30
12 changed files with 188 additions and 97 deletions

View File

@ -27,6 +27,8 @@ public class DiceView : MonoBehaviour, IBase
public void Roll(Action<int> onComplete, bool isBot) public void Roll(Action<int> onComplete, bool isBot)
{ {
Debug.Log($"Start rolling: {rolling}");
if (!rolling) if (!rolling)
{ {
Debug.Log($"isBot: {isBot}"); Debug.Log($"isBot: {isBot}");
@ -74,9 +76,8 @@ public class DiceView : MonoBehaviour, IBase
//TODO: Use the dice value as needed //TODO: Use the dice value as needed
Debug.Log($"Dice rolled: {value}"); Debug.Log($"Dice rolled: {value}");
onRollingComplete?.Invoke(value);
ResetDice(); ResetDice();
onRollingComplete?.Invoke(value);
} }
int GetDiceValue() int GetDiceValue()
@ -98,7 +99,7 @@ public class DiceView : MonoBehaviour, IBase
transform.localPosition = new Vector3(0, 20, 0); transform.localPosition = new Vector3(0, 20, 0);
rolling = false; rolling = false;
Invoke(nameof(ResetEvent), 0.5f); // Invoke(nameof(ResetEvent), 0.1f);
} }
private void ResetEvent() private void ResetEvent()

View File

@ -215,7 +215,7 @@ Canvas:
m_VertexColorAlwaysGammaSpace: 0 m_VertexColorAlwaysGammaSpace: 0
m_AdditionalShaderChannelsFlag: 25 m_AdditionalShaderChannelsFlag: 25
m_SortingLayerID: 0 m_SortingLayerID: 0
m_SortingOrder: 0 m_SortingOrder: 5
m_TargetDisplay: 0 m_TargetDisplay: 0
--- !u!114 &1334714064113256010 --- !u!114 &1334714064113256010
MonoBehaviour: MonoBehaviour:

View File

@ -8460,8 +8460,10 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 0483b263e22fc433caab31141efbe319, type: 3} m_Script: {fileID: 11500000, guid: 0483b263e22fc433caab31141efbe319, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
isDebugTest: 1
diceRollHandler: {fileID: 1013177415} diceRollHandler: {fileID: 1013177415}
diceValue: 6 diceValue: 6
maxDiceSixRollCounter: 2
diceText: {fileID: 953941044} diceText: {fileID: 953941044}
pointerDebug: {fileID: 102349503} pointerDebug: {fileID: 102349503}
pointerMeshRend: {fileID: 102349501} pointerMeshRend: {fileID: 102349501}
@ -11554,7 +11556,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
diceView: {fileID: 1619592888} diceView: {fileID: 1619592888}
diceTestValue: 6 diceTestValue: 1
--- !u!4 &1039618837 stripped --- !u!4 &1039618837 stripped
Transform: Transform:
m_CorrespondingSourceObject: {fileID: 5672526856521419272, guid: 4dc45edb05c8f4268aebcd5e9cbac783, type: 3} m_CorrespondingSourceObject: {fileID: 5672526856521419272, guid: 4dc45edb05c8f4268aebcd5e9cbac783, type: 3}
@ -23124,6 +23126,18 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z propertyPath: m_LocalEulerAnglesHint.z
value: 0 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4180996271043359930, guid: f7fae8d587c2e4afcbcd76b417afc521, type: 3}
propertyPath: m_LocalScale.x
value: 0.2
objectReference: {fileID: 0}
- target: {fileID: 4180996271043359930, guid: f7fae8d587c2e4afcbcd76b417afc521, type: 3}
propertyPath: m_LocalScale.y
value: 0.2
objectReference: {fileID: 0}
- target: {fileID: 4180996271043359930, guid: f7fae8d587c2e4afcbcd76b417afc521, type: 3}
propertyPath: m_LocalScale.z
value: 0.2
objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: f7fae8d587c2e4afcbcd76b417afc521, type: 3} m_SourcePrefab: {fileID: 100100000, guid: f7fae8d587c2e4afcbcd76b417afc521, type: 3}
--- !u!33 &4946864981684608825 --- !u!33 &4946864981684608825
@ -24566,7 +24580,7 @@ GameObject:
- component: {fileID: 5608193481910428234} - component: {fileID: 5608193481910428234}
- component: {fileID: 5608193481910428235} - component: {fileID: 5608193481910428235}
m_Layer: 5 m_Layer: 5
m_Name: Main Menu m_Name: MainMenuScreen
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
@ -25314,7 +25328,7 @@ GameObject:
- component: {fileID: 5608193482197189504} - component: {fileID: 5608193482197189504}
- component: {fileID: 5608193482197189506} - component: {fileID: 5608193482197189506}
m_Layer: 5 m_Layer: 5
m_Name: Game Over m_Name: GameOverScreen
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
@ -25334,6 +25348,8 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
screenType: 2 screenType: 2
shouldFade: 0 shouldFade: 0
playAgainBtn: {fileID: 5608193482985030359}
mainMenuBtn: {fileID: 5608193483181475110}
--- !u!222 &5608193482210820768 --- !u!222 &5608193482210820768
CanvasRenderer: CanvasRenderer:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -27072,7 +27088,7 @@ GameObject:
- component: {fileID: 5608193482973815122} - component: {fileID: 5608193482973815122}
- component: {fileID: 5608193482973815124} - component: {fileID: 5608193482973815124}
m_Layer: 5 m_Layer: 5
m_Name: Game m_Name: GameScreen
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
@ -27155,7 +27171,7 @@ GameObject:
- component: {fileID: 5608193482985030358} - component: {fileID: 5608193482985030358}
- component: {fileID: 5608193482985030359} - component: {fileID: 5608193482985030359}
m_Layer: 5 m_Layer: 5
m_Name: Retry Button m_Name: PlayAgainButton
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
@ -27657,7 +27673,7 @@ GameObject:
- component: {fileID: 5608193483181475113} - component: {fileID: 5608193483181475113}
- component: {fileID: 5608193483181475110} - component: {fileID: 5608193483181475110}
m_Layer: 5 m_Layer: 5
m_Name: Home Button m_Name: MainMenuButton
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0

View File

@ -25,7 +25,7 @@ public class BotModeData
public class GameModeHandler : MonoBehaviour, IBase, IBootLoader, IDataLoader public class GameModeHandler : MonoBehaviour, IBase, IBootLoader, IDataLoader
{ {
private GameplayManager gameplayManager; private GameplayManager gameplayManager;
private GameManager gameManager;
private PVPModeData pvpModeData; private PVPModeData pvpModeData;
private BotModeData botModeData; private BotModeData botModeData;
@ -41,6 +41,7 @@ public class GameModeHandler : MonoBehaviour, IBase, IBootLoader, IDataLoader
public void InitializeData() public void InitializeData()
{ {
gameManager = InterfaceManager.Instance.GetInterfaceInstance<GameManager>();
gameplayManager = InterfaceManager.Instance.GetInterfaceInstance<GameplayManager>(); gameplayManager = InterfaceManager.Instance.GetInterfaceInstance<GameplayManager>();
} }
@ -69,6 +70,8 @@ public class GameModeHandler : MonoBehaviour, IBase, IBootLoader, IDataLoader
public void OnGameRestarted() public void OnGameRestarted()
{ {
gameManager.OnGameStateChanged(GameState.InGame);
gameplayManager.ResetGameRestartData();
switch (CurrentGameModeType) switch (CurrentGameModeType)
{ {
case GameModeType.PVP: case GameModeType.PVP:

View File

@ -16,9 +16,14 @@ public enum BotMove
public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
{ {
[SerializeField] private bool isDebugTest = false;
public bool IsDebugTest => isDebugTest;
[SerializeField] DiceRollHandler diceRollHandler; [SerializeField] DiceRollHandler diceRollHandler;
[SerializeField] private int diceValue = 0; [SerializeField] private int diceValue = 0;
[SerializeField] private int maxDiceSixRollCounter = 2;
[SerializeField] private TextMeshProUGUI diceText; [SerializeField] private TextMeshProUGUI diceText;
@ -128,9 +133,6 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
} }
} }
foreach (var type in allPlayerTypes)
Debug.Log($"allPlayerTypes ::: {type}");
tilesManager.InitTilesData(); tilesManager.InitTilesData();
playerBaseHandler.InitPlayerTypes(allPlayerTypes); playerBaseHandler.InitPlayerTypes(allPlayerTypes);
InitCurrentGamePlayerInfo(); InitCurrentGamePlayerInfo();
@ -209,6 +211,9 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
public void InitCurrentGamePlayerInfo() public void InitCurrentGamePlayerInfo()
{ {
currentPlayerTypeTurn = allPlayerTypes[currentPlayerTurnIndex]; currentPlayerTypeTurn = allPlayerTypes[currentPlayerTurnIndex];
Debug.Log($"currentPlayerTypeTurn: {currentPlayerTypeTurn}");
SetCurrentSelectedPointer();
// initialize the board based on the player types // initialize the board based on the player types
playerGameDatasDict = new Dictionary<PlayerType, PlayerGameData>(); playerGameDatasDict = new Dictionary<PlayerType, PlayerGameData>();
@ -268,7 +273,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
private bool CheckForMaxDiceRollAttempt() private bool CheckForMaxDiceRollAttempt()
{ {
if (diceSixRollCounter == 3) if (diceSixRollCounter > maxDiceSixRollCounter) // TODO :: Reset after test
{ {
CanRollDiceAgain = false; CanRollDiceAgain = false;
SwitchPlayer(); SwitchPlayer();
@ -331,27 +336,21 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
// TODO :: Double check // TODO :: Double check
foreach (var key in botPawnsDictForCurrentPlayer.Keys) foreach (var key in botPawnsDictForCurrentPlayer.Keys)
{ {
Debug.Log($"b :: botPawnsDictForCurrentPlayer[key]: {botPawnsDictForCurrentPlayer[key]}"); Debug.Log($"b :: botPawnsDictForCurrentPlayer[key]: {key}, {botPawnsDictForCurrentPlayer[key]}");
// botPawnsDictForCurrentPlayer[key] = BotMove.NoMoves; // botPawnsDictForCurrentPlayer[key] = BotMove.NoMoves;
Debug.Log($"a :: botPawnsDictForCurrentPlayer[key]: {botPawnsDictForCurrentPlayer[key]}");
} }
Debug.Log($"Before Iterating"); Debug.Log($"Before Iterating");
foreach (var playerPawn in availPlayers) foreach (var playerPawn in availPlayers)
{ {
Debug.Log($"Iterating"); int possibleSteps = 0;
var possibleLandingIndex = playerPawn.CurrentTileIndex + diceRolledValue; Tile possibleTileData = null;
int lastIndex = tilesManager.GetGeneralTilesLength() - 1; if (playerPawn.GetPlayerState() != PlayerState.InFinishingPath)
int index = possibleLandingIndex > lastIndex ? possibleLandingIndex - lastIndex - 1 : possibleLandingIndex; FindPossibleTileData(playerPawn, out possibleSteps, out possibleTileData);
Tile possibleTileData = tilesManager.RetrieveTileBasedOnIndex(index);
Debug.Log($"AI playerPawn :: {playerPawn.name} :: state: {playerPawn.GetPlayerState()}, possibleLandingIndex: {possibleLandingIndex > playerGameDatasDict[currentPlayerTypeTurn].endIndex}"); if (playerPawn.GetPlayerState() == PlayerState.InFinishingPath || possibleSteps > playerGameDatasDict[currentPlayerTypeTurn].endIndex) // TODO :: have a better second check
Debug.Log($"AI playerPawn :: {playerPawn.name} :: possibleTileData.IsSafeZone: {possibleTileData.IsSafeZone}");
Debug.Log($"AI playerPawn :: {playerPawn.name} :: possibleTileData.PlayerPawn: {possibleTileData.HasPawnsAvailable}");
if (playerPawn.GetPlayerState() == PlayerState.InFinishingPath || possibleLandingIndex > playerGameDatasDict[currentPlayerTypeTurn].endIndex)
{ {
Debug.Log($"AI playerPawn :: {playerPawn.name} :: {playerPawn.PlayerId} :: inFinishingPath :: canSelectPlayer: {playerPawn.CanSelectPlayer}"); Debug.Log($"AI playerPawn :: {playerPawn.name} :: {playerPawn.PlayerId} :: inFinishingPath :: canSelectPlayer: {playerPawn.CanSelectPlayer}");
if (playerPawn.CanSelectPlayer) if (playerPawn.CanSelectPlayer)
@ -365,12 +364,12 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
botPawnsDictForCurrentPlayer[playerPawn.PlayerId] = BotMove.NoMoves; botPawnsDictForCurrentPlayer[playerPawn.PlayerId] = BotMove.NoMoves;
} }
} }
else if (possibleTileData.IsSafeZone) else if (possibleTileData != null && possibleTileData.IsSafeZone)
{ {
Debug.Log($"AI playerPawn :: {playerPawn.name} :: {playerPawn.PlayerId} :: safeMove"); Debug.Log($"AI playerPawn :: {playerPawn.name} :: {playerPawn.PlayerId} :: safeMove");
botPawnsDictForCurrentPlayer[playerPawn.PlayerId] = BotMove.SafeMove; botPawnsDictForCurrentPlayer[playerPawn.PlayerId] = BotMove.SafeMove;
} }
else if (possibleTileData.HasPawnsAvailable) else if (possibleTileData != null && possibleTileData.HasPawnsAvailable && possibleTileData.CurrentHoldingPlayerType != playerPawn.PlayerType)
{ {
Debug.Log($"AI playerPawn :: {playerPawn.name} :: {playerPawn.PlayerId} :: attackMove"); Debug.Log($"AI playerPawn :: {playerPawn.name} :: {playerPawn.PlayerId} :: attackMove");
botPawnsDictForCurrentPlayer[playerPawn.PlayerId] = BotMove.AttackMove; botPawnsDictForCurrentPlayer[playerPawn.PlayerId] = BotMove.AttackMove;
@ -417,8 +416,23 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
} }
} }
if (pawn != null)
{
Debug.Log($"AI playerPawn :: {pawn.name} :: SelectedPawn: {pawn.name}"); Debug.Log($"AI playerPawn :: {pawn.name} :: SelectedPawn: {pawn.name}");
OnPawnSelected(pawn); OnPawnSelected(pawn);
}
else
{
if (CheckForMaxDiceRollAttempt())
{
return;
}
if (CanRollDiceAgain)
HandleDiceRoll();
else
SwitchPlayer();
}
void InitPawnBasedOnState(BotMove botMove) void InitPawnBasedOnState(BotMove botMove)
{ {
@ -448,6 +462,20 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
} }
} }
private void FindPossibleTileData(PlayerPawn playerPawn, out int possibleSteps, out Tile possibleTileData)
{
possibleSteps = playerGameDatasDict[playerPawn.PlayerType].playerPawnsDict[playerPawn.PlayerId].StepsTaken + diceRolledValue;
int lastStepGenTileIdx = playerGameDatasDict[playerPawn.PlayerType].endIndex;
int possibleTileIndex = playerPawn.CurrentTileIndex + diceRolledValue;
int totalStepsInGeneralPath = tilesManager.GetGeneralTilesLength() - 1; // including the first safe zone
int lastTileIndex = tilesManager.GetGeneralTilesLength() - 1;
int index = possibleSteps > totalStepsInGeneralPath ? possibleTileIndex - lastStepGenTileIdx - 1
: possibleTileIndex > lastTileIndex ? possibleTileIndex - lastTileIndex - 1 : possibleTileIndex;
possibleTileData = possibleSteps > totalStepsInGeneralPath ? tilesManager.RetrieveFinishingTileBasedOnIndex(playerPawn.PlayerType, index) : tilesManager.RetrieveTileBasedOnIndex(index);
}
public void OnDiceRolled(int rolledVal) public void OnDiceRolled(int rolledVal)
{ {
SetCanRollDiceForUser(false); SetCanRollDiceForUser(false);
@ -518,7 +546,8 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
availPlayers[i].SetPlayerSelectionState(true); availPlayers[i].SetPlayerSelectionState(true);
} }
foreach (int i in indexesToRemove) availPlayers.RemoveAt(i); for (int idx = indexesToRemove.Count - 1; idx >= 0; idx--)
availPlayers.RemoveAt(idx);
// if (availPlayers.Count() < 1) // if (availPlayers.Count() < 1)
Debug.Log($"CustomAvailablePlayers: {customAvailPlayers}"); Debug.Log($"CustomAvailablePlayers: {customAvailPlayers}");
@ -536,11 +565,6 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
pawn.GetPlayerState() == PlayerState.Moving || pawn.GetPlayerState() == PlayerState.Moving ||
pawn.GetPlayerState() == PlayerState.InFinishingPath).ToList(); pawn.GetPlayerState() == PlayerState.InFinishingPath).ToList();
Debug.Log($"#### UpdatePlayerState in InitActivePlayers ");
foreach (var pawn in playerGameDatasDict[currentPlayerTypeTurn].playerPawnsDict.Values)
{
Debug.Log($"pawn: {pawn.name}, state: {pawn.GetPlayerState()}");
}
foreach (var player in availPlayers) // TODO :: Move from here foreach (var player in availPlayers) // TODO :: Move from here
{ {
DisplayPlayerCountOnTile(player, true); DisplayPlayerCountOnTile(player, true);
@ -575,7 +599,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
playerPawn.SetPlayerState(playerState); playerPawn.SetPlayerState(playerState);
} }
private void CheckDiceRollForBot(PlayerPawn playerPawn) private void CheckDiceRollForBot()
{ {
if (CanRollDiceAgain) if (CanRollDiceAgain)
{ {
@ -585,8 +609,10 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
private void HandleDiceRoll() private void HandleDiceRoll()
{ {
// diceRollHandler.HandleDiceViewForBot((rollVal) => RollDiceForBot(rollVal)); if (isDebugTest)
diceRollHandler.HandleDiceViewForBot((rollVal) => RollDiceForBot(rollVal), diceValue == 0 ? UnityEngine.Random.Range(1, Ludo_3D_Constants.Max_Dice_Rolls + 1) : diceValue); diceRollHandler.HandleDiceViewForBot((rollVal) => RollDiceForBot(rollVal), diceValue == 0 ? UnityEngine.Random.Range(1, Ludo_3D_Constants.Max_Dice_Rolls + 1) : diceValue);
else
diceRollHandler.HandleDiceViewForBot((rollVal) => RollDiceForBot(rollVal));
} }
public void OnPawnSelected(PlayerPawn playerPawn) public void OnPawnSelected(PlayerPawn playerPawn)
@ -615,7 +641,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
} }
if (playerPawn.IsBotPlayer) if (playerPawn.IsBotPlayer)
CheckDiceRollForBot(playerPawn); CheckDiceRollForBot();
else else
SetCanRollDiceForUser(true); SetCanRollDiceForUser(true);
@ -711,10 +737,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
InitActivePlayers(); InitActivePlayers();
Debug.Log($"after SwitchPlayer availPlayers: {availPlayers.Count}, playerPawn: {playerPawn}"); Debug.Log($"after SwitchPlayer availPlayers: {availPlayers.Count}, playerPawn: {playerPawn}");
foreach (var pawn in availPlayers) SetDisplayCountForAllAvailPlayers(false);
{
DisplayPlayerCountOnTile(pawn, false);
}
if (allPlayerTypes.Count == 1) if (allPlayerTypes.Count == 1)
{ {
@ -739,16 +762,12 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
diceText.text = $"{0}"; diceText.text = $"{0}";
InitActivePlayers(); InitActivePlayers();
foreach (var pawn in availPlayers) SetDisplayCountForAllAvailPlayers(true);
{
DisplayPlayerCountOnTile(pawn, true);
}
} }
SetCanRollDiceForUser(!botTypesInGame.Contains(currentPlayerTypeTurn)); SetCanRollDiceForUser(!botTypesInGame.Contains(currentPlayerTypeTurn));
Debug.Log($"CurrentPlayerTurn: {currentPlayerTypeTurn}"); Debug.Log($"CurrentPlayerTurn: {currentPlayerTypeTurn}");
var tempPos = playerBaseHandler.GetPlayerBase(currentPlayerTypeTurn).transform.position; SetCurrentSelectedPointer();
pointerDebug.position = new Vector3(tempPos.x, 3f, tempPos.z);
pointerMeshRend.material = turnMat; pointerMeshRend.material = turnMat;
// pointerMeshRend.materials[0] = turnMat; // pointerMeshRend.materials[0] = turnMat;
@ -762,6 +781,20 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
} }
} }
private void SetCurrentSelectedPointer()
{
var tempPos = playerBaseHandler.GetPlayerBase(currentPlayerTypeTurn).transform.position;
pointerDebug.position = new Vector3(tempPos.x, 3f, tempPos.z);
}
public void SetDisplayCountForAllAvailPlayers(bool state)
{
foreach (var pawn in availPlayers)
{
DisplayPlayerCountOnTile(pawn, state);
}
}
private void MoveThroughTiles(PlayerPawn playerPawn, int index, int targetIndex) private void MoveThroughTiles(PlayerPawn playerPawn, int index, int targetIndex)
{ {
Tile nextTile = tilesManager.RetrieveTileBasedOnIndex(index); Tile nextTile = tilesManager.RetrieveTileBasedOnIndex(index);
@ -842,17 +875,19 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
if (CheckForMaxDiceRollAttempt()) if (CheckForMaxDiceRollAttempt())
{ {
nextTile.InitPlayerPawn(playerPawn, currentPlayerTypeTurn); nextTile.InitPlayerPawn(playerPawn, currentPlayerTypeTurn);
DisplayPlayerCountOnTile(playerPawn, true);
return; return;
} }
CanRollDiceAgain = true; CanRollDiceAgain = true;
if (playerPawn.IsBotPlayer) if (!playerPawn.IsBotPlayer)
CheckDiceRollForBot(playerPawn);
else
SetCanRollDiceForUser(true); SetCanRollDiceForUser(true);
} }
nextTile.InitPlayerPawn(playerPawn, currentPlayerTypeTurn); nextTile.InitPlayerPawn(playerPawn, currentPlayerTypeTurn);
DisplayPlayerCountOnTile(playerPawn, true);
if (CheckForMaxDiceRollAttempt()) if (CheckForMaxDiceRollAttempt())
{ {
return; return;
@ -975,8 +1010,9 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
if (allPlayerTypes.Count == 1) if (allPlayerTypes.Count == 1)
{ {
// Game is over // Game is over
var lastFinishingPlayerType = allPlayerTypes[0];
allPlayerTypes.RemoveAt(0); allPlayerTypes.RemoveAt(0);
playerDatas.FirstOrDefault(data => data.playerType == currentPlayerTypeTurn).ranking = TotalPlayersInGame - allPlayerTypes.Count; playerDatas.FirstOrDefault(data => data.playerType == lastFinishingPlayerType).ranking = TotalPlayersInGame - allPlayerTypes.Count;
// Show Game Over panel // Show Game Over panel
gameManager.OnGameStateChanged(GameState.GameOver); gameManager.OnGameStateChanged(GameState.GameOver);
@ -992,7 +1028,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
{ {
CanRollDiceAgain = true; CanRollDiceAgain = true;
if (playerPawn.IsBotPlayer) if (playerPawn.IsBotPlayer)
CheckDiceRollForBot(playerPawn); CheckDiceRollForBot();
else else
SetCanRollDiceForUser(true); SetCanRollDiceForUser(true);
} }
@ -1024,7 +1060,6 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
tilesManager.RetrieveFinishingTileBasedOnIndex(playerPawn.PlayerType, playerPawn.CurrentTileIndex) tilesManager.RetrieveFinishingTileBasedOnIndex(playerPawn.PlayerType, playerPawn.CurrentTileIndex)
: tilesManager.RetrieveTileBasedOnIndex(playerPawn.CurrentTileIndex); : tilesManager.RetrieveTileBasedOnIndex(playerPawn.CurrentTileIndex);
Debug.Log($"Displaycount: {playerPawn.name} on tile: {tile.name}, show: {show}");
playerPawn.ShowPlayerCountCanvas(show); playerPawn.ShowPlayerCountCanvas(show);
if (!show) return; if (!show) return;
@ -1043,6 +1078,8 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
public void ResetData() public void ResetData()
{ {
ResetGameRestartData();
playerDatas = null; playerDatas = null;
botTypesInGame = null; botTypesInGame = null;
allPlayerTypes = null; allPlayerTypes = null;
@ -1052,4 +1089,9 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
playerDatas = null; playerDatas = null;
availPlayers = null; availPlayers = null;
} }
public void ResetGameRestartData()
{
currentPlayerTurnIndex = 0;
}
} }

View File

@ -101,7 +101,6 @@ public class PlayerPawn : MonoBehaviour
public void MoveToCustomTilePosition(Vector3 targetPoint) public void MoveToCustomTilePosition(Vector3 targetPoint)
{ {
StepsTaken++;
transform.DOMove(targetPoint, 1f); transform.DOMove(targetPoint, 1f);
} }

View File

@ -34,13 +34,15 @@ public class DiceRollHandler : MonoBehaviour
SoundManager soundManager = InterfaceManager.Instance?.GetInterfaceInstance<SoundManager>(); SoundManager soundManager = InterfaceManager.Instance?.GetInterfaceInstance<SoundManager>();
soundManager?.PlayGameSoundClip(SoundType.Dice); soundManager?.PlayGameSoundClip(SoundType.Dice);
if (inputManager.GameplayManager.IsDebugTest)
OnUserDiceRollComplete(GetDiceTestVal()); OnUserDiceRollComplete(GetDiceTestVal());
// diceView.Roll(onComplete: (rolledVal) => OnUserDiceRollComplete(rolledVal), false); else
diceView.Roll(onComplete: (rolledVal) => OnUserDiceRollComplete(rolledVal), false);
} }
public void HandleDiceViewForBot(Action<int> onComplete) public void HandleDiceViewForBot(Action<int> onComplete)
{ {
diceView.Roll(onComplete: (val) => onComplete?.Invoke(val), true); diceView.Roll(onComplete: onComplete, true);
} }
public void HandleDiceViewForBot(Action<int> onComplete, int val) public void HandleDiceViewForBot(Action<int> onComplete, int val)

View File

@ -10,6 +10,7 @@ public enum GameState
public class GameManager : MonoBehaviour, IBase, IBootLoader, IDataLoader public class GameManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
{ {
private UIManager uiManager; private UIManager uiManager;
private TilesManager tilesManager;
private GameplayManager gameplayManager; private GameplayManager gameplayManager;
public GameState GameState public GameState GameState
@ -25,6 +26,7 @@ public class GameManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
public void InitializeData() public void InitializeData()
{ {
uiManager = InterfaceManager.Instance.GetInterfaceInstance<UIManager>(); uiManager = InterfaceManager.Instance.GetInterfaceInstance<UIManager>();
tilesManager = InterfaceManager.Instance.GetInterfaceInstance<TilesManager>();
gameplayManager = InterfaceManager.Instance.GetInterfaceInstance<GameplayManager>(); gameplayManager = InterfaceManager.Instance.GetInterfaceInstance<GameplayManager>();
OnGameStateChanged(GameState.InMenu); OnGameStateChanged(GameState.InMenu);
@ -37,6 +39,7 @@ public class GameManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
{ {
case GameState.InMenu: case GameState.InMenu:
gameplayManager.ResetData(); gameplayManager.ResetData();
tilesManager.ResetData();
uiManager.OnInMenuScreen(); uiManager.OnInMenuScreen();
break; break;
case GameState.InGame: case GameState.InGame:

View File

@ -32,6 +32,7 @@ public class TilesManager : MonoBehaviour, IBootLoader, IDataLoader, IBase
public void InitTilesData() public void InitTilesData()
{ {
finishingTileDataPairs = new Dictionary<PlayerType, List<Tile>>();
foreach (var tileData in tileDatas) foreach (var tileData in tileDatas)
{ {
if (gameplayManager.PlayerTypesCollection.Contains(tileData.playerType)) if (gameplayManager.PlayerTypesCollection.Contains(tileData.playerType))
@ -52,10 +53,6 @@ public class TilesManager : MonoBehaviour, IBootLoader, IDataLoader, IBase
Debug.Log($"RetrieveTileBasedOnIndex: Index: {index}"); Debug.Log($"RetrieveTileBasedOnIndex: Index: {index}");
Tile tile = index == generalTiles.Length ? generalTiles[0] : generalTiles[index]; Tile tile = index == generalTiles.Length ? generalTiles[0] : generalTiles[index];
// if (tile.IsSafeZone)
// {
// return (SafeTile)tile;
// }
return tile; return tile;
} }
@ -65,8 +62,8 @@ public class TilesManager : MonoBehaviour, IBootLoader, IDataLoader, IBase
return finishingTileDataPairs[playerType][index]; return finishingTileDataPairs[playerType][index];
} }
public Transform RetrievePositionForFinishingTile(PlayerType playerType, int index) public void ResetData()
{ {
return finishingTileDataPairs[playerType][index].transform; finishingTileDataPairs.Clear();
} }
} }

View File

@ -24,7 +24,7 @@ public class ScreenBase : UIBase, IUIBase
public ScreenType ScreenType => screenType; public ScreenType ScreenType => screenType;
private ScreenManager screenManager; protected ScreenManager screenManager;
public void Initialize() public void Initialize()
{ {

View File

@ -1,5 +1,6 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
@ -12,7 +13,26 @@ public class GameOverPopup : PopupBase
[SerializeField] private TextMeshProUGUI[] texts; [SerializeField] private TextMeshProUGUI[] texts;
private GameModeHandler gameModeHandler; private GameModeHandler gameModeHandler;
private ScreenManager screenManager;
public void InitData(List<PlayerData> playerData)
{
for (int idx = 0; idx < texts.Length; idx++)
{
if (idx >= playerData.Count)
{
texts[idx].gameObject.SetActive(false);
continue;
}
if (playerData[idx].ranking == 1)
{
texts[playerData[idx].ranking - 1].text = $"{playerData[idx].playerName} Wins";
continue;
}
texts[playerData[idx].ranking - 1].text = $"{playerData[idx].ranking}. {playerData[idx].playerName}";
}
}
private void OnEnable() private void OnEnable()
{ {
@ -42,33 +62,5 @@ public class GameOverPopup : PopupBase
public void OnMainMenuClicked() public void OnMainMenuClicked()
{ {
HidePopup(); HidePopup();
screenManager = screenManager == null ? InterfaceManager.Instance.GetInterfaceInstance<ScreenManager>() : screenManager;
screenManager.ShowScreen(ScreenType.MenuScreen);
}
public void InitData(List<PlayerData> 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}";
}
foreach (var playerData in playerDatas)
{
if (playerData.ranking == 1)
{
texts[playerData.ranking - 1].text = $"{playerData.playerName} Wins";;
continue;
}
texts[playerData.ranking - 1].text = $"{playerData.ranking}. {playerData.playerName}";
}
} }
} }

View File

@ -1,8 +1,44 @@
using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.UI;
public class GameOverScreen : ScreenBase public class GameOverScreen : ScreenBase
{ {
[SerializeField] private Button playAgainBtn;
[SerializeField] private Button mainMenuBtn;
private GameModeHandler gameModeHandler;
private void OnEnable()
{
playAgainBtn.onClick.AddListener(OnPlayAgainClicked);
mainMenuBtn.onClick.AddListener(OnMainMenuClicked);
}
private void OnDisable()
{
playAgainBtn.onClick.RemoveAllListeners();
mainMenuBtn.onClick.RemoveAllListeners();
}
public void OnPlayAgainClicked()
{
HideScreen();
}
private void HideScreen()
{
screenManager.HideScreen(screenType);
}
public void OnMainMenuClicked()
{
HideScreen();
screenManager = screenManager == null ? InterfaceManager.Instance.GetInterfaceInstance<ScreenManager>() : screenManager;
screenManager.ShowScreen(ScreenType.MenuScreen);
screenManager.ShowScreen(ScreenType.MainMenuScreen);
}
} }