Ejemplo n.º 1
0
        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;
            }
        }