Example #1
0
        /// <summary>
        /// Close the multi players game.
        /// </summary>
        /// <param name="args">The arguments.</param>
        /// <param name="client">The client.</param>
        /// <returns>
        /// string: "singlePlayer" or "multiPlayer".
        /// </returns>
        public string Execute(string[] args, TcpClient client)
        {
            // Check the valid if the arguements.
            if (!this.CheckValid(args, client))
            {
                return("multiPlayer");
            }
            string          name = args[0];
            GameMultiPlayer game = model.FindGamePlaying(name);

            // Check if the game is in the list of games to play.
            if (game != null)
            {
                model.RemoveGamePlaying(name);
                Controller.SendToClient("close client do close", client);
                Controller.SendToClient("close the game by other client", game.OtherClient(client));
                if (!model.ClientOnGame(game.OtherClient(client)))
                {
                    Controller.SendToClient("singlePlayer", game.OtherClient(client));
                }
                if (!model.ClientOnGame(client))
                {
                    return("singlePlayer");
                }
                return("multiPlayer");
            }
            else
            {
                Controller.NestedErrors nested = new Controller.NestedErrors("Error exist game", client);
                return("multiPlayer");
            }
        }
Example #2
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");
        }
Example #3
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");
            }
        }