Ejemplo n.º 1
0
        private void ParseMaze(IReadOnlyCollection <string> lines)
        {
            Maze   = new Maze();
            Crates = new List <Crate>();

            var y = lines.Count;

            foreach (var line in lines)
            {
                var x = 1;
                foreach (var character in line.ToCharArray())
                {
                    var coordinate = new Location(x, y);
                    switch (character)
                    {
                    case '#':    //Wall
                        Maze.Map.Add(coordinate.ToString(), new Wall(coordinate));
                        break;

                    case '.':    //Empty floor
                        Maze.Map.Add(coordinate.ToString(), new Floor(coordinate));
                        break;

                    case 'o':    //Crate
                        Maze.Map.Add(coordinate.ToString(), new Floor(coordinate)
                        {
                            HasCrate = true
                        });
                        Crates.Add(new Crate(coordinate));
                        break;

                    case '@':    //Forklift
                        Maze.Map.Add(coordinate.ToString(), new Floor(coordinate)
                        {
                            HasForklift = true
                        });
                        Forklift = new Forklift(coordinate);
                        break;

                    case 'x':    //Destination
                        Maze.Map.Add(coordinate.ToString(), new Destination(coordinate));
                        break;

                    case ' ':    //Space
                        Maze.Map.Add(coordinate.ToString(), new Space(coordinate));
                        break;

                    case '~':    //Pitfall
                        Maze.Map.Add(coordinate.ToString(), new Pitfall(coordinate)
                        {
                            HasPitfall = true
                        });
                        break;

                    default:
                        throw new IndexOutOfRangeException();
                    }
                    x++;
                }
                y--;
            }
        }