From c1000e27ce75d6adc0d1a635b9911a99d2cd3f4d Mon Sep 17 00:00:00 2001 From: Martinho Fernandes Date: Thu, 6 Feb 2014 23:31:57 +0100 Subject: [PATCH] Stuff --- Dagon/Dagon.csproj | 1 + Dagon/Dungeon.cs | 41 ++++++++++++++++++------------------- Dagon/Game.cs | 50 ++++++++++++++++++++++++++++++++++++++++++++-- Dagon/IDrawable.cs | 7 +++++++ Dagon/Ideas.txt | 5 +++-- Dagon/Player.cs | 4 ++-- Dagon/Program.cs | 4 +++- 7 files changed, 85 insertions(+), 27 deletions(-) create mode 100644 Dagon/IDrawable.cs diff --git a/Dagon/Dagon.csproj b/Dagon/Dagon.csproj index f9ff5bb..0c82187 100644 --- a/Dagon/Dagon.csproj +++ b/Dagon/Dagon.csproj @@ -42,6 +42,7 @@ + diff --git a/Dagon/Dungeon.cs b/Dagon/Dungeon.cs index b383729..8411a1e 100644 --- a/Dagon/Dungeon.cs +++ b/Dagon/Dungeon.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; - -namespace Dagon +namespace Dagon { public enum TileKind { @@ -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>(); + _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]; } @@ -85,6 +81,11 @@ private void CarveRoom(Point topLeft, Point bottomRight) } } } + + public Dungeon Clone() + { + return new Dungeon(this); + } } public struct Point diff --git a/Dagon/Game.cs b/Dagon/Game.cs index b85bc9a..5e8770b 100644 --- a/Dagon/Game.cs +++ b/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 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}; + } } } \ No newline at end of file diff --git a/Dagon/IDrawable.cs b/Dagon/IDrawable.cs new file mode 100644 index 0000000..a7171e5 --- /dev/null +++ b/Dagon/IDrawable.cs @@ -0,0 +1,7 @@ +namespace Dagon +{ + public interface IDrawable + { + void Draw(Window window); + } +} \ No newline at end of file diff --git a/Dagon/Ideas.txt b/Dagon/Ideas.txt index 09619f5..6645bc5 100644 --- a/Dagon/Ideas.txt +++ b/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? \ No newline at end of file diff --git a/Dagon/Player.cs b/Dagon/Player.cs index a09b1fd..99063d3 100644 --- a/Dagon/Player.cs +++ b/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) { diff --git a/Dagon/Program.cs b/Dagon/Program.cs index f6c25ed..74330c8 100644 --- a/Dagon/Program.cs +++ b/Dagon/Program.cs @@ -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