示例#1
0
 public void Stats(MazeStructure maze)
 {
     int spaceCount = maze.Items.Count(i => i.Type == MazeItemType.Space);
     int wallCount = maze.Items.Count(i => i.Type == MazeItemType.Wall);
     Console.WriteLine("Maze Stats");
     Console.WriteLine($"Spaces: {spaceCount}");
     Console.WriteLine($"Walls: {wallCount}");
 }
示例#2
0
文件: Explorer.cs 项目: OliDow/Maze
 public MazeExplorer(MazeStructure currentMaze)
 {
     CurrentMaze = currentMaze;
     MazeItem start = currentMaze.Items.FirstOrDefault(i => i.Type == MazeItemType.Start);
     if (start != null)
     {
         CurrentXCord = start.XCord;
         CurrentYCord = start.YCord;
     }
 }
示例#3
0
        public void ViewItem(MazeStructure maze, int xCord, int yCord)
        {
            var item = GetMazeItem(maze, xCord, yCord);
            if (item == null)
            {
                Console.WriteLine("That location does not exist in the maze");
            }
            else
            {
                Console.WriteLine($"Location {xCord}:{yCord} is {item.Type}");
            }


        }
示例#4
0
        public void GetMazeItem()
        {
            MazeStructure maze = new MazeStructure
            {
                Items = new List<MazeItem>
                {
                    new MazeItem(1,1,"s")
                }
            };

            var item =_mazeService.GetMazeItem(maze, 1, 1);

            Assert.AreEqual(MazeItemType.Start, item.Type);
        }
示例#5
0
 public void ViewMaze(MazeStructure maze)
 {
     string line = Empty;
     maze.Items.ToList().ForEach(i =>
     {
         if (i.XCord == 1)
         {
             Console.WriteLine(line);
             line = Empty;
         }
         line += MazeItemToText(i.Type);
     });
     // Print the last line
     Console.WriteLine(line);
 }
示例#6
0
 public MazeItem GetMazeItem(MazeStructure maze, int xCord, int yCord)
 {
     return maze.Items.FirstOrDefault(i => i.XCord == xCord && i.YCord == yCord);
 }
示例#7
0
文件: Program.cs 项目: OliDow/Maze
        static void Main(string[] args)
        {
            // Instantiate classes until we impliment some kind of DI.
            MazeService mazeService = new MazeService();
            MazeStructure maze = new MazeStructure
            {
                Items = mazeService.ReadMapFile("ExampleMaze.txt")
            };
            MazeExplorer explorer = new MazeExplorer(maze);

            ExplorerService explorerService = new ExplorerService();

            Console.WriteLine("Commands");
            Console.WriteLine("ViewMaze (vm)");
            Console.WriteLine("stat");
            Console.WriteLine("autocomplete (ac)");
            Console.WriteLine("turnleft (l)");
            Console.WriteLine("turnright (r)");
            Console.WriteLine("moveforward (mf)");
            Console.WriteLine("lookforward (lf)");
            Console.WriteLine("lookaround (la)");
            while (true)
            {
                string inputText = Console.ReadLine();
                string[] inputSplit = inputText.Split(' ');
                if (inputSplit.Length == 1)

                    switch (inputText.ToLower())
                    {
                        case "viewmaze":
                        case "vm":
                            mazeService.ViewMaze(maze);
                            break;
                        case "stats":
                            mazeService.Stats(maze);
                            break;
                        case "autocomplete":
                        case "ac":
                            explorerService.AutoComplete(explorer);
                            break;
                        case "turnleft":
                        case "l":
                            explorerService.DoAction(explorer, ExplorerAction.TurnLeft);
                            break;
                        case "turnright":
                        case "r":
                            explorerService.DoAction(explorer, ExplorerAction.TurnRight);
                            break;
                        case "moveforward":
                        case "f":
                            explorerService.DoAction(explorer, ExplorerAction.MoveForward);
                            break;
                        case "lookforward":
                        case "lf":
                            explorerService.DoAction(explorer, ExplorerAction.LookForward);
                            break;
                        case "lookaround":
                        case "la":
                            explorerService.DoAction(explorer, ExplorerAction.LookAround);
                            break;
                    }

                if (inputText.ToLower().StartsWith("viewitem"))
                {

                    if (inputSplit.Length != 3)
                    {
                        Console.WriteLine("Viewitem accepts 2 paramaters");
                    }
                    else
                    {
                        int xCord;
                        int yCord;
                        if (int.TryParse(inputSplit[1], out xCord) &&
                            int.TryParse(inputSplit[2], out yCord))
                        {
                            mazeService.ViewItem(maze, xCord, yCord);
                        }
                    }
                }
            }
        }
示例#8
0
 public void SetUp()
 {
     _explorerService = new ExplorerService();
     _maze = new MazeStructure
     {
         Items = new List<MazeItem>
         {
             new MazeItem(1,1,"s"),
             new MazeItem(2,1," "),
             new MazeItem(3,1,"x")
         }
     };
      _explore = new MazeExplorer(_maze);
 }