private IEnumerator DoCommandProcess(LudoCommand command) { for (int i = 0; i < command.m_Actions.Length; i++) { LudoAction action = command.m_Actions[i]; LudoBoardPlayer boardPlayer = m_Game.Board.GetPlayerData(command.m_PlayerIndex).m_Player; if (action.m_ActionType == (int)LudoAction.ActionType.EnterBoard) { bool canEnter = m_Game.Board.CanEnterMarble(command.m_PlayerIndex, action.m_MarbleIndex); if (canEnter) { yield return(StartCoroutine(boardPlayer.EnterMarble(action.m_MarbleIndex, m_Game))); } } else if (action.m_ActionType == (int)LudoAction.ActionType.ExitBoard) { yield return(StartCoroutine(boardPlayer.ExitMarble(action.m_MarbleIndex, m_Game))); } else { bool canMove = m_Game.Board.CanMoveMarble(command.m_PlayerIndex, action.m_MarbleIndex, action.m_Move); if (canMove) { yield return(StartCoroutine(boardPlayer.MoveMarble(action.m_MarbleIndex, action.m_Move, m_Game))); } } } }
public IEnumerator MoveMarble(int marbleIndex, int move, LudoGame game) { if (IsInPlay(marbleIndex) && move > 0) { LudoMarble marble = m_Marbles[marbleIndex]; int currentSlotIndex = game.Board.GetSlotIndex(m_PlayerIndex, marbleIndex); LudoSlot currentSlot = game.Board.GetSlot(currentSlotIndex); int targetSlotIndex = game.Board.GetTargetSlotIndex(m_PlayerIndex, currentSlotIndex, move); if (targetSlotIndex != LudoBoard.InvalidSlot) { LudoSlot targetSlot = game.Board.GetSlot(targetSlotIndex); LudoMarble targetMarble = targetSlot.m_Marble; LudoSlot[] moveSlots = game.Board.GetMoveSlots(m_PlayerIndex, currentSlotIndex, move); currentSlot.m_Marble = null; targetSlot.m_Marble = marble; yield return(StartCoroutine(marble.MovePlaySlots(moveSlots))); if (targetMarble != null) { //exit opponent's marble LudoBoardPlayer opponent = game.Board.GetOwnerPlayer(targetMarble); yield return(StartCoroutine(opponent.ExitMarble(targetMarble.m_MarbleIndex, game))); } } else { yield break; } } else { yield break; } }
public PlayerSlots GetPlayerSlots(LudoBoardPlayer player) { for (int i = 0; i < m_Players.Length; i++) { if (m_Players[i].m_Player == player) { return(m_Players[i].m_Slots); } } return(null); }
public bool CanEnterMarble(int playerIndex, int marbleIndex) { LudoBoardPlayer boardPlayer = m_Players[playerIndex].m_Player; bool isMarbleInPlay = boardPlayer.IsInPlay(marbleIndex); if (!isMarbleInPlay) { int enterSlotIndex = m_Players[playerIndex].m_Slots.m_StartSlot; LudoSlot enterSlot = GetSlot(enterSlotIndex); return(CanBeInSlot(playerIndex, enterSlot)); } return(false); }
public bool CanMoveAnyMarble(int playerIndex, int move) { LudoBoardPlayer boardPlayer = m_Players[playerIndex].m_Player; for (int i = 0; i < boardPlayer.MarbleCount; i++) { bool canEnterMarble = CanMoveMarble(playerIndex, boardPlayer.GetMarble(i).m_MarbleIndex, move); if (canEnterMarble) { return(true); } } return(false); }
public int GetOwnerPlayerIndex(LudoMarble marble) { for (int i = 0; i < m_Players.Length; i++) { LudoBoardPlayer player = m_Players[i].m_Player; for (int j = 0; j < player.MarbleCount; j++) { LudoMarble playerMarble = player.GetMarble(j); if (playerMarble == marble) { return(i); } } } return(InvalidPlayerIndex); }
private LudoAction TryEnterAction() { m_ChosenMarbles.Clear(); LudoBoardPlayer boardPlayer = Board.GetPlayerData(m_PlayerIndex).m_Player; for (int i = 0; i < boardPlayer.MarbleCount; i++) { bool canEnterMarble = Board.CanEnterMarble(m_PlayerIndex, i); if (canEnterMarble) { m_ChosenMarbles.Add(i); } } if (m_ChosenMarbles.Count > 0) { int marbleIndex = Random.Range(0, m_ChosenMarbles.Count); LudoAction action = new LudoAction(LudoAction.ActionType.EnterBoard, marbleIndex); m_ChosenMarbles.Clear(); return(action); } return(null); }