Beispiel #1
0
 public GenerateAnswer(SolveAnswer answer)
 {
     this.name  = answer.Name;
     this.maze  = answer.Maze.Replace('2', '0');
     this.start = answer.Start;
     this.end   = answer.End;
 }
Beispiel #2
0
        /// <summary>
        /// Converts a maze solution to a maze.
        /// swaps all 2's to 0's.
        /// </summary>
        /// <param name="sol">The sol.</param>
        /// <returns>JSON object of the final answer.</returns>
        private string ConvertSolutionToMaze(string sol)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            Answer      ans    = serializer.Deserialize <Answer>(sol);
            SolveAnswer solved = serializer.ConvertToType <SolveAnswer>(ans.Content);

            StringBuilder sb = new StringBuilder(solved.Maze);

            sb.Replace("2", "0", 0, sb.Length);
            solved.Maze = sb.ToString();

            return(new Answer().GetJSONAnswer(1, solved));
        }
Beispiel #3
0
        /// <summary>
        /// Builds a reply for the client.
        /// Creates a SolveAnswer class which then is translated to JSON format.
        /// </summary>
        /// <param name="maze">The maze.</param>
        /// <param name="name">The name of the maze.</param>
        /// <param name="solution">The solution of the maze.</param>
        /// <param name="type">The type of command.</param>
        /// <returns>
        /// The reply in JSON format.
        /// </returns>
        private string BuildReply(IMaze maze, string name, string solution, int type)
        {
            SolveAnswer ans = new SolveAnswer();

            JsonOptions.MazePosition start  = new JsonOptions.MazePosition();
            JsonOptions.MazePosition finish = new JsonOptions.MazePosition();

            start.Row  = maze.GetStartPosition().Row;
            start.Col  = maze.GetStartPosition().Colomn;
            finish.Row = maze.GetFinishPosition().Row;
            finish.Col = maze.GetFinishPosition().Colomn;

            StringBuilder sb = new StringBuilder(solution);

            sb.Replace("\n", "", 0, sb.Length);

            ans.Name  = name;
            ans.Maze  = sb.ToString();
            ans.Start = start;
            ans.End   = finish;

            return(new Answer().GetJSONAnswer(type, ans));
        }