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 IEnumerator ExitMarble(int marbleIndex, LudoGame game) { if (IsInPlay(marbleIndex)) { LudoMarble marble = m_Marbles[marbleIndex]; for (int i = 0; i < m_HomeSlots.Length; i++) { if (m_HomeSlots[i].m_Marble == null) { m_HomeSlots[i].m_Marble = marble; int playSlotIndex = game.Board.GetSlotIndex(m_PlayerIndex, marbleIndex); LudoSlot slot = game.Board.GetSlot(playSlotIndex); slot.m_Marble = null; yield return(StartCoroutine(marble.Move(m_HomeSlots[i]))); break; } } } else { yield break; } }
public IEnumerator EnterMarble(int marbleIndex, LudoGame game) { if (!IsInPlay(marbleIndex)) { LudoMarble marble = m_Marbles[marbleIndex]; for (int i = 0; i < m_HomeSlots.Length; i++) { if (m_HomeSlots[i].m_Marble == marble) { m_HomeSlots[i].m_Marble = null; PlayerSlots playerSlots = game.Board.GetPlayerSlots(this); LudoSlot slot = game.Board.GetSlot(playerSlots.m_StartSlot); slot.m_Marble = marble; yield return(StartCoroutine(marble.Move(slot))); break; } } } else { yield break; } }