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; } }
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))); } } } }