Exemple #1
0
        public string Execute(string[] args, TcpClient client)
        {
            if (!this.CheckValid(args, client))
            {
                // Check if the client is on other game to keep the connection.
                if (model.ClientOnGame(client))
                {
                    return("multiPlayer");
                }
                return("singlePlayer");
            }
            string              name           = args[0];
            string              typeAlgorithem = args[1];
            AdapterSolution     adpterSolution = null;
            Solution <Position> s = null;

            // Solve the maze by BFS - 0, DFS - 1.
            switch (typeAlgorithem)
            {
            case "0":
                s = model.solveMazeBFS(name);     // BFS solution.
                break;

            case "1":
                s = model.solveMazeDFS(name);     // DFS solution.
                break;
            }
            // If the solution is not null send the solution to the client. Else send a message.
            if (s != null)
            {
                adpterSolution = new AdapterSolution(s, name);
                Controller.SendToClient(adpterSolution.ToJson(), client);
            }
            else
            {
                Controller.NestedErrors nested = new Controller.NestedErrors("maze not exist", client);
            }
            if (model.ClientOnGame(client))
            {
                return("multiPlayer");
            }
            return("singlePlayer");
        }
Exemple #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)
        {
            if (!this.CheckValid(args, client))
            {
                return("singlePlayer");
            }
            string              name           = args[0];
            string              typeAlgorithem = args[1];
            string              result;
            AdapterSolution     adpterSolution = null;
            Solution <Position> s = null;

            switch (typeAlgorithem)
            {
            case "0":
                s = model.solveMazeBFS(name);
                break;

            case "1":
                s = model.solveMazeDFS(name);
                break;
            }
            if (s != null)
            {
                adpterSolution = new AdapterSolution(s, name, s.SolutionSize());
                result         = adpterSolution.ToJson();
            }
            else
            {
                result = "error exist maze";
            }
            Controller.SendToClient(result, client);
            if (model.ClientOnGame(client))
            {
                return("multiPlayer");
            }
            return("singlePlayer");
        }