Beispiel #1
0
        private void AddToCorridor(int x, int y, Opening opening, int iteration)
        {
            bool createRoom = Random.Next(100) < buildParams.ChanceOfRoom;

            if (createRoom)
            {
                Room room = CreateRoom(x, y, opening.Orientation);
                if (room != null && !CheckCollisions(room))
                {
                    Rooms.Add(room);
                }
                else
                {
                    BacktrackingCorridors();
                }
            }
            if (!createRoom)
            {
                Orientation orientation = Orientation.Null;
                do
                {
                    orientation = (Orientation)Random.Next(1, 4) + 1;
                } while (opening.IsReverse(orientation));
                Opening newCorridorOpening = new Opening()
                {
                    X = x, Y = y, Orientation = orientation
                };
                if (x < Width && x >= 0 && y < Height && y >= 0)
                {
                    FillOpening(x, y, newCorridorOpening, iteration + 1);
                }
            }
            if (iteration == 0)
            {
                coordsForBacktracking.Clear();
            }
        }
Beispiel #2
0
        private void FillOpening(int x, int y, Opening opening, int iteration)
        {
            int  tiles      = Random.Next(buildParams.MinCorridorSize, buildParams.MaxCorridorSize);
            bool bHasToStop = false;
            int  i          = 0;

            while (!bHasToStop && i < tiles)
            {
                try
                {
                    if (x < Width && x >= 0 && y < Height && y >= 0 && !Map[x, y])
                    {
                        Map[x, y] = true;
                        coordsForBacktracking.Add(new Tuple <int, int>(x, y));
                        Corridors.Add(new Corridor(buildParams.TileImage)
                        {
                            X = x, Y = y
                        });
                        IncrementCoord(ref x, ref y, opening.Orientation);
                    }
                    else
                    {
                        bHasToStop = true;
                    }
                }
                catch (IndexOutOfRangeException)
                {
                    BacktrackingCorridors();
                    bHasToStop = true;
                }
                i++;
            }
            if (!bHasToStop)
            {
                AddToCorridor(x, y, opening, iteration);
            }
        }