Esempio n. 1
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)));
                    }
                }
            }
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
 private IEnumerator RunQueuedCommands()
 {
     m_IsRunning      = true;
     m_Game.IsPlaying = true;
     while (m_Commands.Count > 0)
     {
         LudoCommand command = m_Commands.Dequeue();
         yield return(StartCoroutine(DoCommandProcess(command)));
     }
     m_IsRunning      = false;
     m_Game.IsPlaying = false;
 }
Esempio n. 4
0
        public void RunCommand(LudoCommand command)
        {
            bool isValid = IsValid(command);

            if (isValid)
            {
                m_Commands.Enqueue(command);
                if (!m_Game.IsPlaying && !m_IsRunning)
                {
                    StartCoroutine(RunQueuedCommands());
                }
            }
        }
Esempio n. 5
0
        public override void SendCommand(LudoCommand command, int turn)
        {
            PlayNetworkMessage networkMessage = new PlayNetworkMessage()
            {
                m_SessionId   = m_SessionId,
                m_PlayerIndex = command.m_PlayerIndex,
                m_MessageType = CommandUtility.PlayId,
                m_Command     = command,
                m_Turn        = turn,
            };

            SendToOtherClients(networkMessage);
            CheckBotTurns(turn);
        }
Esempio n. 6
0
        private void RunTurn()
        {
            int dice;

            do
            {
                dice = m_Dice.RollDice();
            } while (dice != LudoDice.InvalidDice);

            LudoAction[] actions = CreateActions();
            LudoCommand  command = new LudoCommand(m_PlayerIndex, actions);

            Game.Turn = Game.NextTurn;
            OrderCommand(command, Game.Turn);
        }
Esempio n. 7
0
        public override void SendCommand(LudoCommand command, int turn)
        {
            PlayNetworkMessage networkMessage = new PlayNetworkMessage()
            {
                m_SessionId   = m_SessionId,
                m_PlayerIndex = m_Game.CommandExecuter.PlayerIndex,
                m_MessageType = CommandUtility.PlayId,
                m_Command     = command,
                m_Turn        = turn
            };

            string message = JsonUtility.ToJson(networkMessage);

            TcpClientSingleton.Instance.TcpClient.SendMessage(message);
        }
Esempio n. 8
0
 protected void OrderCommand(LudoCommand command, int turn)
 {
     m_CommandExecuter.RunCommand(command);
     m_Network.SendCommand(command, turn);
 }
Esempio n. 9
0
        private bool IsValid(LudoCommand command)
        {
            bool isValid = command != null && command.m_PlayerIndex > -1 && command.m_PlayerIndex < 4;

            return(isValid && command.m_Actions != null && command.m_Actions.Length > 0);
        }
Esempio n. 10
0
 public abstract void SendCommand(LudoCommand command, int turn);