Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Room4"/> class.
 /// </summary>
 /// <param name="north">The north.</param>
 /// <param name="south">The south.</param>
 /// <param name="east">The east.</param>
 /// <param name="west">The west.</param>
 /// <remarks></remarks>
 public Room4(Room4 north, Room4 south, Room4 east, Room4 west)
 {
     NorthRoom = north;
     SouthRoom = south;
     WestRoom = west;
     EastRoom = east;
 }
Beispiel #2
0
        /// <summary>
        /// Erzeugt ein neues Labyrinth
        /// </summary>
        /// <remarks>Verwendet den im Konstruktor gesetzten Generator</remarks>
        public void GenerateNew(int width, int height)
        {
            Contract.Requires(width > 0 && height > 0);
            Wall4[,] walls = _generator.Generate(width, height);

            // Dictionary vorbereiten
            ConcurrentDictionary<IRoom4, Tuple<int, int>> lookup = new ConcurrentDictionary<IRoom4, Tuple<int, int>>();

            // Räume erzeugen
            Room4[,] rooms = new Room4[width, height];
            for (int y = 0; y < height; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                    Wall4 currentWall = walls[x, y];
                    Room4 currentRoom = new Room4();
                    currentRoom.Tag = new Tuple<int, int>(x, y);

                    // 2..n Zeile: Raum darüber setzen
                    // Die letzte Zeile hat keine Räume darunter, womit alle
                    // vertikalen Verbindungsfälle abgedeckt werden.
                    if (y > 0)
                    {
                        if (!currentWall.ContainsWall(Wall4.North))
                        {
                            Room4 roomAbove = rooms[x, y - 1];
                            currentRoom.NorthRoom = roomAbove;
                            roomAbove.SouthRoom = currentRoom;
                        }
                    }

                    // 2..n Spalte: Raum links daneben setzen
                    // Die letzte Spalte hat keine Räume rechtsseitig, womit alle
                    // horizontalen Verbindungsfälle abgedeckt werden.
                    if (x > 0)
                    {
                        if (!currentWall.ContainsWall(Wall4.West))
                        {
                            Room4 left = rooms[x - 1, y];
                            currentRoom.WestRoom = left;
                            left.EastRoom = currentRoom;
                        }
                    }

                    // Raum speichern
                    rooms[x, y] = currentRoom;

                    // Tabelle bauen
                    var position = new Tuple<int, int>(x, y);
                    lookup.AddOrUpdate(currentRoom, position, (room, old) => position);
                }
            }

            // Und setzen.
            _roomIndexLookup = lookup;
            _rooms = rooms;
            _walls = walls;

            // Feuer frei.
            OnMazeChanged(new MazeEventArgs(this));
        }