Ejemplo n.º 1
0
        private void ParseCommand(Command command)
        {
            //Decide what to do with command
            Console.WriteLine("Parsing command " + command.Type + " from Player " + command.PlayerId + " '" + command.Data + "'");

            // Player command is a command issued by the player
            // Only handled by server
            if (network.IsServer() && GameStarted() && command.Type == Command.CommandType.Player)
            {
                ParsePlayerCommand(command);
            }
            else if (network.IsServer() && !GameStarted() && command.Type == Command.CommandType.Player)
            {
                ParsePlayerLobbyCommand(command);
            }
            else if (network.IsServer() && !GameStarted() && command.Type == Command.CommandType.Player)
            {
                network.SendCommand(new Command(Command.CommandType.Text, "Wait for the host to start the game.", command.PlayerId));
                return;
            }
            else if (network.IsServer() && command.Type == Command.CommandType.PlayerJoined)
            {
                int id = int.Parse(command.Data);
                players[id] = new Player("player_" + id);
                Debug.WriteLine("added Player with name " + players[id].name);
            }
            else if (command.Type == Command.CommandType.PlayerJoined)
            {
                myPlayerId = int.Parse(command.Data);
                Console.WriteLine("My player id: " + myPlayerId);
                players[myPlayerId] = new Player("SELF");
            }
            else if (command.Type == Command.CommandType.Text)
            {
                ((ChatScene)game.GetScene(TojamGame.GameScenes.Chat)).AddMessage(command.Data, command.SourcePlayerId);
            }
            else if (command.Type == Command.CommandType.PlayerInfo)
            {
                Command.ParsePlayerInfoCommand(players[myPlayerId], command.Data);
            }
            else if (GameStarted() && command.Type == Command.CommandType.PictureEvent)
            {
                CarPicture.PictureEvent evt = Command.ParsePictureEventCommand(command.Data);
                ChatScene chatScene         = (ChatScene)this.game.GetScene(TojamGame.GameScenes.Chat);
                chatScene.GetCarPicture().TriggerEvent(evt);
            }
        }
Ejemplo n.º 2
0
        public static CarPicture.PictureEvent ParsePictureEventCommand(String data)
        {
            String[] values    = data.Split(',');
            String   eventName = values[0];
            Dictionary <String, Object> arguments = new Dictionary <string, object>();

            Debug.WriteLine("Event " + eventName + ":");
            for (int i = 1; i < values.Length; i++)
            {
                String[] keyVal = values[i].Split(':');
                Debug.WriteLine("  " + keyVal[0] + ": " + keyVal[1]);
                arguments[keyVal[0]] = keyVal[1];
            }

            CarPicture.PictureEvent e = new CarPicture.PictureEvent();
            e.name      = eventName;
            e.arguments = arguments;
            return(e);
        }