コード例 #1
0
        private void SelectTargetSlot()
        {
            LudoSlot startSlot = m_StartSlot;

            LudoSlot[] targets = m_TargetSlots;
            FreeSlots();

            if (targets.Length == 1)
            {
                int startSlotIndex = Board.GetSlotIndex(startSlot);
                if (startSlotIndex != LudoBoard.InvalidSlot)
                {
                    MoveMarble(startSlot.m_Marble, targets.Length);
                }
                else
                {
                    //start slot in home slots
                    EnterMarble(startSlot.m_Marble);
                }
            }
            else
            {
                MoveMarble(startSlot.m_Marble, targets.Length);
            }
        }
コード例 #2
0
        public LudoSlot[] GetMoveSlots(int playerIndex, int slotIndex, int move)
        {
            int targetSlotIndex = GetTargetSlotIndex(playerIndex, slotIndex, move);

            if (targetSlotIndex == InvalidSlot || move == 0)
            {
                return(null);
            }
            else
            {
                LudoSlot[] slots = new LudoSlot[move];
                if (slotIndex < m_PlaySlots.Length)
                {
                    if (targetSlotIndex < m_PlaySlots.Length)
                    {
                        SetPlaySlots(slotIndex, slots, 0, move);
                    }
                    else
                    {
                        int endIndex      = m_Players[playerIndex].m_Slots.m_EndSlot;
                        int playSlotCount = GetPlaySlotCount(slotIndex, endIndex);
                        SetPlaySlots(slotIndex, slots, 0, playSlotCount);
                        SetEndSlots(endIndex, slots, playSlotCount, move - playSlotCount);
                    }
                }
                else
                {
                    SetEndSlots(slotIndex, slots, 0, move);
                }

                return(slots);
            }
        }
コード例 #3
0
        private void CheckClick()
        {
            if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
            {
                Ray  ray   = Camera.main.ScreenPointToRay(Input.mousePosition);
                bool isHit = Physics.Raycast(ray, out RaycastHit hit, m_RayLength, m_ClickLayer.value);
                if (isHit)
                {
                    bool isSlot   = hit.collider.gameObject.CompareTag(BoardGameUtility.SlotTag);
                    bool isMarble = hit.collider.gameObject.CompareTag(BoardGameUtility.MarbleTag);

                    if (isSlot)
                    {
                        LudoSlot slot = hit.collider.GetComponent <LudoSlot>();
                        if (slot != null)
                        {
                            ClickSlot(slot);
                            return;
                        }
                    }
                    else if (isMarble)
                    {
                        LudoMarble marble = hit.collider.GetComponent <LudoMarble>();
                        if (marble != null)
                        {
                            ClickMarble(marble);
                            return;
                        }
                    }
                }

                FreeSlots();
            }
        }
コード例 #4
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;
            }
        }
コード例 #5
0
        public IEnumerator Move(LudoSlot target)
        {
            Tween moving = transform.DOMove(target.MarblePosition.position, m_MoveDuration);

            moving = SetupTween(moving);
            yield return(moving.Play().WaitForCompletion());
        }
コード例 #6
0
        private void ClickPlayOrEndSlot(LudoSlot slot, int playerIndex)
        {
            int  slotIndex     = Board.GetSlotIndex(slot);
            bool canMoveMarble = Board.CanMoveMarble(playerIndex, slot.m_Marble.m_MarbleIndex, Game.GetDice());

            if (canMoveMarble)
            {
                LudoSlot[] targets = Board.GetMoveSlots(playerIndex, slotIndex, Game.GetDice());
                SelectDecisionSlot(slot, targets);
            }
        }
コード例 #7
0
        private bool CanBeInSlot(int playerIndex, LudoSlot targetSlot)
        {
            if (targetSlot.m_Marble == null)
            {
                return(true);
            }

            int otherPlayerIndex = GetOwnerPlayerIndex(targetSlot.m_Marble);

            return(playerIndex != otherPlayerIndex);
        }
コード例 #8
0
        private int FindSlotIndex(LudoSlot[] slots, LudoSlot slot)
        {
            for (int i = 0; i < slots.Length; i++)
            {
                if (slots[i] == slot)
                {
                    return(i);
                }
            }

            return(InvalidSlot);
        }
コード例 #9
0
        private void SelectDecisionSlot(LudoSlot startSlot, LudoSlot[] targets)
        {
            m_StartSlot   = startSlot;
            m_TargetSlots = targets;

            startSlot.HightlightStrong();
            for (int i = 0; i < targets.Length - 1; i++)
            {
                targets[i].HightlightWeak();
            }
            targets[targets.Length - 1].HightlightStrong();
        }
コード例 #10
0
        private void ClickHomeSlot(LudoSlot homeSlot, int playerIndex)
        {
            bool canEnterMarble = Board.CanEnterMarble(playerIndex, homeSlot.m_Marble.m_MarbleIndex);

            if (canEnterMarble)
            {
                int      playerStartSlotIndex = m_CommandExecuter.Game.Board.GetPlayerData(playerIndex).m_Slots.m_StartSlot;
                LudoSlot playerStartSlot      = m_CommandExecuter.Game.Board.GetSlot(playerStartSlotIndex);
                SelectDecisionSlot(homeSlot, new LudoSlot[1] {
                    playerStartSlot
                });
            }
        }
コード例 #11
0
        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);
        }
コード例 #12
0
 private void FreeSlots()
 {
     if (m_StartSlot != null)
     {
         m_StartSlot.HightlightOff();
         m_StartSlot = null;
     }
     if (m_TargetSlots != null)
     {
         for (int i = 0; i < m_TargetSlots.Length; i++)
         {
             m_TargetSlots[i].HightlightOff();
         }
         m_TargetSlots = null;
     }
 }
コード例 #13
0
 private void ClickSlot(LudoSlot slot)
 {
     if (m_StartSlot == null)
     {
         TryDecisionSelect(slot);
     }
     else
     {
         bool targetSlotClicked = TryTargetSelect(slot);
         if (!targetSlotClicked)
         {
             FreeSlots();
             TryDecisionSelect(slot);
         }
     }
 }
コード例 #14
0
        private bool TryTargetSelect(LudoSlot slot)
        {
            for (int i = 0; i < m_TargetSlots.Length; i++)
            {
                if (m_TargetSlots[i] == slot)
                {
                    if (i == m_TargetSlots.Length - 1)
                    {
                        SelectTargetSlot();
                    }

                    return(true);
                }
            }

            return(false);
        }
コード例 #15
0
        public bool CanMoveMarble(int playerIndex, int marbleIndex, int move)
        {
            if (move < 0)
            {
                return(false);
            }

            int slotIndex = GetSlotIndex(playerIndex, marbleIndex);

            if (slotIndex != InvalidSlot)
            {
                int targetSlotIndex = GetTargetSlotIndex(playerIndex, slotIndex, move);
                if (targetSlotIndex != InvalidSlot)
                {
                    LudoSlot targetSlot = GetSlot(targetSlotIndex);
                    return(CanBeInSlot(playerIndex, targetSlot));
                }
            }

            return(false);
        }
コード例 #16
0
        private void ClickMarble(LudoMarble marble)
        {
            int slotIndex = Board.GetSlotIndex(Game.PlayerIndex, marble.m_MarbleIndex);

            if (slotIndex != LudoBoard.InvalidSlot)
            {
                LudoSlot slot = Board.GetSlot(slotIndex);
                ClickSlot(slot);
            }
            else
            {
                LudoSlot[] homeSlots = Board.GetOwnerPlayer(marble).HomeSlots;
                for (int i = 0; i < homeSlots.Length; i++)
                {
                    if (homeSlots[i].m_Marble == marble)
                    {
                        ClickSlot(homeSlots[i]);
                    }
                }
            }
        }
コード例 #17
0
        /// <summary>
        /// If slot is in play slots or end slots, retrun the its index. Otherwise return InvalidSlot value.
        /// </summary>
        public int GetSlotIndex(LudoSlot slot)
        {
            int slotIndex = FindSlotIndex(m_PlaySlots, slot);

            if (slotIndex == InvalidSlot)
            {
                for (int i = 0; i < m_Players.Length; i++)
                {
                    slotIndex = FindSlotIndex(m_Players[i].m_Slots.m_EndSlots, slot);
                    if (slotIndex != InvalidSlot)
                    {
                        return(m_PlaySlots.Length + PlayerMarbleCount * i + slotIndex);
                    }
                }
            }
            else
            {
                return(slotIndex);
            }

            return(InvalidSlot);
        }
コード例 #18
0
        public int GetTargetSlotIndex(int playerIndex, int slotIndex, int move)
        {
            if (move > m_PlaySlots.Length + 3)
            {
                return(InvalidSlot);
            }

            //get slot index from play slots or player end slots
            int targetSlotIndex;

            if (slotIndex < m_PlaySlots.Length)
            {
                targetSlotIndex = GetIndexInPlaySlots(playerIndex, slotIndex, move);
            }
            else
            {
                targetSlotIndex = GetIndexInEndSlots(playerIndex, slotIndex, move);
            }

            //check target slot not being filled with alley marble
            LudoSlot targetSlot = GetSlot(targetSlotIndex);

            if (targetSlot.m_Marble != null)
            {
                int otherPlayerIndex = GetOwnerPlayerIndex(targetSlot.m_Marble);
                if (playerIndex == otherPlayerIndex)
                {
                    return(InvalidSlot);
                }
                else
                {
                    return(targetSlotIndex);
                }
            }
            else
            {
                return(targetSlotIndex);
            }
        }
コード例 #19
0
 private void TryDecisionSelect(LudoSlot slot)
 {
     if (slot.m_Marble != null)
     {
         int playerIndex = Board.GetOwnerPlayerIndex(slot.m_Marble);
         //check click on player's own marble
         if (Game.PlayerIndex == playerIndex)
         {
             int slotIndex = Board.GetSlotIndex(slot);
             if (slotIndex != LudoBoard.InvalidSlot)
             {
                 ClickPlayOrEndSlot(slot, playerIndex);
                 return;
             }
             else
             {
                 ClickHomeSlot(slot, playerIndex);
                 return;
             }
         }
     }
 }
コード例 #20
0
        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;
            }
        }
コード例 #21
0
        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;
            }
        }