Beispiel #1
0
        public string Execute(string[] args, TcpClient client)
        {
            if (!CheckValid(args, client))
            {
                return("multiPlayer");
            }
            string direction = args[0];
            // Get the game of the client who press play.
            GameMultiPlayer game = model.FindGameByClient(client);

            // Check the direction.
            if (!directions.Contains(direction))
            {
                Controller.NestedErrors error = new Controller.NestedErrors("The dirction is incorrect", client);
                return("multiPlayer");
            }
            // Check if the game exist.
            if (game != null)
            {
                NestedPlay nested = new NestedPlay(game.GetMaze().Name, direction);
                Controller.SendToClient(JsonConvert.SerializeObject(nested), game.OtherClient(client));
            }
            else
            {
                // The game dosnt exits. Send message to the client.
                Controller.NestedErrors error = new Controller.NestedErrors("you need to start a game", client);
            }
            return("multiPlayer");
        }
Beispiel #2
0
        /// <summary>
        /// Execute the specified args and client.
        /// </summary>
        /// <returns>The execute.</returns>
        /// <param name="args">Arguments.</param>
        /// <param name="client">Client.</param>
        public string Execute(string[] args, TcpClient client)
        {
            string          direction = args[0];
            GameMultiPlayer game      = model.FindGameByClient(client);

            if (!directions.Contains(direction))
            {
                Controller.NestedErrors error = new Controller.NestedErrors("The dirction is incorrect}", client);
                return("multiPlayer");
            }
            if (game != null)
            {
                NestedPlay nested = new NestedPlay(game.GetMaze().Name, direction);
                Controller.SendToClient(JsonConvert.SerializeObject(nested), game.OtherClient(client));
                return("multiPlayer");
            }
            else
            {
                Controller.SendToClient("{Erorr: you need to start a game}", client);
                return("singlePlayer");
            }
        }