Ejemplo n.º 1
0
		/// <summary>
		/// Allows the game to perform any initialization it needs to before starting to run.
		/// This is where it can query for any required services and load any non-graphic
		/// related content.  Calling base.Initialize will enumerate through any components
		/// and initialize them as well.
		/// </summary>
		protected override void Initialize ()
		{
			// TODO: Add your initialization logic here
			var creationStrategy = new RogueSharp.MapCreation.RandomRoomsMapCreationStrategy<Map>(50, 30, 100, 7, 3);
			_map = Map.Create (creationStrategy);
			base.Initialize ();
				
		}
Ejemplo n.º 2
0
        private void GenerateMap()
        {
            // Create the map.
            RogueSharp.MapCreation.IMapCreationStrategy <RogueSharp.Map> mapCreationStrategy
                = new RogueSharp.MapCreation.RandomRoomsMapCreationStrategy <RogueSharp.Map>(Width, Height, 100, 15, 4);

            rogueMap = RogueSharp.Map.Create(mapCreationStrategy);
            rogueFOV = new RogueSharp.FieldOfView(rogueMap);

            // Create the local cache of the map data.
            mapData = new MapObjects.MapObjectBase[Width, Height];

            // Loop through the map information generated by RogueSharp and create out cached visuals of that data.
            foreach (var cell in rogueMap.GetAllCells())
            {
                if (cell.IsWalkable)
                {
                    // Our local information about each map square.
                    mapData[cell.X, cell.Y] = new MapObjects.Floor();

                    // Copy the appearance we've defined for Floor or Wall or whatever to the actual console data that is being rendered.
                    mapData[cell.X, cell.Y].RenderToCell(this[cell.X, cell.Y], false, false);
                }
                else
                {
                    rogueMap.SetCellProperties(cell.X, cell.Y, false, false);
                    mapData[cell.X, cell.Y] = new MapObjects.Wall();
                    mapData[cell.X, cell.Y].RenderToCell(this[cell.X, cell.Y], false, false);

                    // A wall blocks LOS
                    rogueMap.SetCellProperties(cell.X, cell.Y, false, cell.IsWalkable);
                }
            }

            RogueSharp.Random.IRandom random = new RogueSharp.Random.DotNetRandom();

            // Position the player somewhere on a walkable square.
            while (true)
            {
                int x = random.Next(Width - 1);
                int y = random.Next(Height - 1);
                if (rogueMap.IsWalkable(x, y))
                {
                    Player.Position = new Point(x, y);

                    // Center the view area.
                    TextSurface.RenderArea = new Rectangle(Player.Position.X - (TextSurface.RenderArea.Width / 2),
                                                           Player.Position.Y - (TextSurface.RenderArea.Height / 2),
                                                           TextSurface.RenderArea.Width, TextSurface.RenderArea.Height);

                    Player.RenderOffset = this.Position - TextSurface.RenderArea.Location;

                    break;
                }
            }
        }
Ejemplo n.º 3
0
        public CaveFloorMap(int width, int height)
        {
            this.random = new RogueSharp.Random.DotNetRandom();
            // If you specify width=20, RogueSharp's map x-index goes from 0..20 inclusive. That's not what we want. Hence, -1
            this.width  = width - 1;
            this.height = height - 1;

            var mapCreationStrategy = new RogueSharp.MapCreation.RandomRoomsMapCreationStrategy <RogueSharp.Map>(width, height, 100, 15, 4);

            //var mapCreationStrategy = new RogueSharp.MapCreation.CaveMapCreationStrategy<RogueSharp.Map>(width, height, 40, 2, 1);
            this.tileData = RogueSharp.Map.Create(mapCreationStrategy);

            this.stairsDown = new Entities.Stairs();
            this.stairsDown.Move(this.FindEmptyPosition());

            this.playerStartPosition = this.FindEmptyPosition();
            var distanceSquared = Math.Pow(Math.Min(this.width, this.height), 2);
            int tries           = 0;

            // Approximate distance must be the width of the map or more. Try it 100 times, then quit.
            while (tries <= 100 && Math.Pow(this.playerStartPosition.X - this.stairsDown.X, 2) + Math.Pow(this.playerStartPosition.Y - this.stairsDown.Y, 2) <= distanceSquared)
            {
                this.playerStartPosition = this.FindEmptyPosition();
                distanceSquared          = Math.Pow(Math.Min(this.width, this.height), 2);
                tries += 1;
            }

            if (random.Next(100) <= Config.Instance.Get <int>("PushPuzzleProbability"))
            {
                this.GeneratePushPuzzle();
            }

            this.GenerateLockedDoorsAndKeys();

            if (random.Next(100) <= Config.Instance.Get <int>("SwitchPuzzleProbability"))
            {
                this.GenerateSwitchPuzzle();
            }

            this.GenerateMonsters();
        }