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); }
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; }
public void RunCommand(LudoCommand command) { bool isValid = IsValid(command); if (isValid) { m_Commands.Enqueue(command); if (!m_Game.IsPlaying && !m_IsRunning) { StartCoroutine(RunQueuedCommands()); } } }
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); }
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); }
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); }
protected void OrderCommand(LudoCommand command, int turn) { m_CommandExecuter.RunCommand(command); m_Network.SendCommand(command, turn); }
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); }
public abstract void SendCommand(LudoCommand command, int turn);