Example #1
0
        private LudoAction GetAction(int dice)
        {
            if (dice == LudoDice.InvalidDice)
            {
                return(null);
            }

            if (dice != 6)
            {
                return(TryMoveAction(dice));
            }

            int randomAction = Random.Range(0, 2);

            if (randomAction == 0)
            {
                LudoAction action = TryMoveAction(dice);;
                if (action != null)
                {
                    return(action);
                }
            }

            return(TryEnterAction());
        }
Example #2
0
        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)));
                    }
                }
            }
        }
        private void PlayTurn(LudoAction action)
        {
            LudoCommand command = new LudoCommand(Game.PlayerIndex, new LudoAction[1] {
                action
            });

            m_CommandExecuter.RunCommand(command);
            Game.DropDice();
            m_Network.SendCommand(command, Game.Turn);
        }
Example #4
0
        private LudoAction[] CreateActions()
        {
            int dice;

            m_CreatedActions.Clear();
            do
            {
                dice = m_Dice.DropDice();
                LudoAction action = GetAction(dice);
                if (action != null)
                {
                    m_CreatedActions.Add(action);
                }
            } while (dice != LudoDice.InvalidDice);

            LudoAction[] actions = null;
            if (m_CreatedActions.Count > 0)
            {
                actions = m_CreatedActions.ToArray();
            }
            m_CreatedActions.Clear();
            return(actions);
        }
Example #5
0
        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);
        }
        private void EnterMarble(LudoMarble marble)
        {
            LudoAction action = new LudoAction(LudoAction.ActionType.EnterBoard, marble.m_MarbleIndex);

            PlayTurn(action);
        }
        private void MoveMarble(LudoMarble marble, int move)
        {
            LudoAction action = new LudoAction(LudoAction.ActionType.Move, marble.m_MarbleIndex, move);

            PlayTurn(action);
        }