Beispiel #1
0
        /// <summary>
        /// Executes the specified arguments.
        /// </summary>
        /// <param name="args">The arguments.</param>
        /// <param name="ch">The ch.</param>
        /// <param name="client">The client.</param>
        /// <returns>string of list command</returns>
        public override string Execute(string[] args, ClientOfServer client = null)
        {
            string list = JsonConvert.SerializeObject(model.List());

            client.WriteToClient(list);
            client.DisconnectFromServer();
            return(list);
        }
Beispiel #2
0
        public override string Execute(string[] args, ClientOfServer client = null)
        {
            Direction move = (Direction)Enum.Parse(typeof(Direction), args[0]);
            Tuple <ClientOfServer, PlayerDirection> otherPlayerInfo = model.Play(move, client);
            ClientOfServer otherPlayer = otherPlayerInfo.Item1;

            otherPlayer.WriteToClient(otherPlayerInfo.Item2.ToJSON());
            return(null);
        }
Beispiel #3
0
        /// <summary>
        /// Executes the specified arguments to start.
        /// </summary>
        /// <param name="args">The arguments.</param>
        /// <param name="ch">The ch.</param>
        /// <param name="client">The client.</param>
        /// <returns>string of the solve maze</returns>
        public override string Execute(string[] args, ClientOfServer client = null)
        {
            string       name      = args[0];
            int          typeSolve = int.Parse(args[1]);
            MazeSolution s         = model.Solve(name, typeSolve);

            client.WriteToClient(s.ToJSON());
            client.DisconnectFromServer();
            return(s.ToJSON());
        }
Beispiel #4
0
        /// <summary>
        /// Executes the specified arguments Generate Maze Command.
        /// </summary>
        /// <param name="args">The arguments.</param>
        /// <param name="ch">The ch.</param>
        /// <param name="client">The client.</param>
        /// <returns></returns>
        public override string Execute(string[] args, ClientOfServer client = null)
        {
            string name = args[0];
            int    rows = int.Parse(args[1]);
            int    cols = int.Parse(args[2]);
            Maze   maze = model.GenerateMaze(name, rows, cols);

            client.WriteToClient(maze.ToJSON());
            client.DisconnectFromServer();
            return(maze.ToJSON());
        }
        public override string Execute(string[] args, ClientOfServer client = null)
        {
            Tuple <ClientOfServer, PlayerDirection> otherPlayerInfo = model.Play(args[0], client);
            ClientOfServer otherPlayer = otherPlayerInfo.Item1;

            //using (NetworkStream stream = otherPlayer.GetStream())
            //using (StreamWriter writer = new StreamWriter(stream))
            //{
            //    writer.AutoFlush = true;
            //    writer.Write(otherPlayerInfo.Item2.ToJSON());
            //}
            otherPlayer.WriteToClient(otherPlayerInfo.Item2.ToJSON());
            return(null);
        }
        /// <summary>
        /// Handles the client.
        /// </summary>
        /// <param name="client">The client.</param>
        public void HandleClient(ClientOfServer client)
        {
            new Task(() => {
                while (client.IsConnected())
                {
                    // Receive the command from the client.
                    string commandLine = client.ReadFromClient();

                    if (!string.IsNullOrEmpty(commandLine))
                    {
                        Console.WriteLine("Received command: {0}", commandLine);

                        // Send the result to the client.
                        string result = controller.ExecuteCommand(commandLine, client);
                        client.WriteToClient(result);
                    }
                }
            }).Start();
        }