Skip to content

Commit

Permalink
Random rooms
Browse files Browse the repository at this point in the history
  • Loading branch information
Martinho Fernandes committed Feb 6, 2014
1 parent 87e5d1b commit 6f31fd4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
22 changes: 20 additions & 2 deletions Dagon/Dungeon.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace Dagon
using System;
using System.Collections.Generic;

namespace Dagon
{
public enum TileKind
{
Expand All @@ -23,7 +26,22 @@ public sealed class Dungeon
public Dungeon(int width, int height)
{
_tiles = new Tile[width, height];
CarveRoom(new Point(10, 10), new Point(20, 20));

var rooms = new List<Tuple<Point, Point>>();

var rng = new Random(2);
int nRooms = rng.Next(10, 30);
for (int i = 0; i < nRooms; i++)
{
int roomWidth = rng.Next(3, 6);
int roomHeight = rng.Next(3, 6);
int top = rng.Next(1, height - roomHeight);
int left = rng.Next(1, width - roomWidth);

var room = Tuple.Create(new Point(left, top), new Point(left + roomWidth, top + roomHeight));
rooms.Add(room);
CarveRoom(room.Item1, room.Item2);
}
}

public Tile this[int width, int height]
Expand Down
6 changes: 6 additions & 0 deletions Dagon/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,11 @@
public sealed class Player
{
public int Health { get; set; }
public Point Position { get; set; }

public void Draw(Window window)
{
window.Set(Position, '@');
}
}
}
13 changes: 10 additions & 3 deletions Dagon/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ internal class Program
{
private static void Main(string[] args)
{
var screen = new Window();
var dungeon = new Dungeon(screen.Width, screen.Height);
dungeon.Draw(screen);
var window = new Window();
var dungeon = new Dungeon(window.Width, window.Height);
dungeon.Draw(window);
var player = new Player {Position = new Point(15, 15)};
player.Draw(window);

// MUHAHAHAHAHA
for (;;)
{
}
}
}
}

0 comments on commit 6f31fd4

Please sign in to comment.