Skip to content

Commit

Permalink
Stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Martinho Fernandes committed Feb 6, 2014
1 parent 6f31fd4 commit c1000e2
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 27 deletions.
1 change: 1 addition & 0 deletions Dagon/Dagon.csproj
Expand Up @@ -42,6 +42,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Dungeon.cs" />
<Compile Include="IDrawable.cs" />
<Compile Include="Player.cs" />
<Compile Include="Window.cs" />
<Compile Include="Game.cs" />
Expand Down
41 changes: 21 additions & 20 deletions Dagon/Dungeon.cs
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;

namespace Dagon
namespace Dagon
{
public enum TileKind
{
Expand All @@ -19,31 +16,30 @@ public struct Tile
}
}

public sealed class Dungeon
public sealed class Dungeon : IDrawable
{
private readonly Tile[,] _tiles;

public Dungeon(int width, int height)
public Dungeon(Dungeon other)
{
_tiles = new Tile[width, height];

var rooms = new List<Tuple<Point, Point>>();
_tiles = new Tile[other.Width, other.Height];

var rng = new Random(2);
int nRooms = rng.Next(10, 30);
for (int i = 0; i < nRooms; i++)
for (int i = 0; i < Width; 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);
for (int j = 0; j < Height; j++)
{
_tiles[i, j] = other[i, j];
}
}
}

public Dungeon(int width, int height)
{
_tiles = new Tile[width, height];

CarveRoom(new Point(1, 1), new Point(width - 1, height - 1));
}

public Tile this[int width, int height]
{
get { return _tiles[width, height]; }
Expand Down Expand Up @@ -85,6 +81,11 @@ private void CarveRoom(Point topLeft, Point bottomRight)
}
}
}

public Dungeon Clone()
{
return new Dungeon(this);
}
}

public struct Point
Expand Down
50 changes: 48 additions & 2 deletions Dagon/Game.cs
@@ -1,9 +1,55 @@
namespace Dagon
using System.Collections.Generic;
using System.Linq;

namespace Dagon
{
public class Game
{
public Game()
{
State = new GameState();
}

public Player Player { get; set; }

public Game Previous { get; set; }
public GameState State { get; set; }

private void StartAction()
{
State = State.Clone();
}
}

public class GameState
{
public Dungeon Dungeon { get; set; }
public IList<Monster> Monsters { get; set; }

public GameState Previous { get; set; }

public GameState Clone()
{
return new GameState
{
Dungeon = Dungeon.Clone(),
Monsters = Monsters.Select(m => m.Clone()).ToList(),
Previous = this,
};
}
}

public class Monster : IDrawable
{
public Point Position { get; set; }

public void Draw(Window window)
{
window.Set(Position, 'X');
}

public Monster Clone()
{
return new Monster {Position = Position};
}
}
}
7 changes: 7 additions & 0 deletions Dagon/IDrawable.cs
@@ -0,0 +1,7 @@
namespace Dagon
{
public interface IDrawable
{
void Draw(Window window);
}
}
5 changes: 3 additions & 2 deletions Dagon/Ideas.txt
@@ -1,7 +1,8 @@
Standard fare roguelike with a time travelling mechanic. Single player, randomly-generated content, no saving.
Clone of robots.

All previous state information is saved except for player information.

The player has a time travelling ability that I won't bother balancing because fun. Said ability allows the player to move back into any previous state.
The player has a time travelling ability that I won't bother balancing because fun.
Said ability allows the player to move back into any previous state.

If enough time left, forked timestreams?
4 changes: 2 additions & 2 deletions Dagon/Player.cs
@@ -1,9 +1,9 @@
namespace Dagon
{
public sealed class Player
public sealed class Player : IDrawable
{
public int Health { get; set; }
public Point Position { get; set; }
public int Turns { get; set; }

public void Draw(Window window)
{
Expand Down
4 changes: 3 additions & 1 deletion Dagon/Program.cs
Expand Up @@ -5,9 +5,11 @@ internal class Program
private static void Main(string[] args)
{
var window = new Window();

var dungeon = new Dungeon(window.Width, window.Height);
dungeon.Draw(window);
var player = new Player {Position = new Point(15, 15)};

dungeon.Draw(window);
player.Draw(window);

// MUHAHAHAHAHA
Expand Down

0 comments on commit c1000e2

Please sign in to comment.