public void Draw(Window window) { State.Dungeon.Draw(window); Player.Draw(window); foreach (Monster monster in State.Monsters) { monster.Draw(window); } }
private static void Main() { var window = new Window(); var game = new Game(window); var sw = Stopwatch.StartNew(); var lastTick = sw.ElapsedMilliseconds; var lastFuelTick = sw.ElapsedMilliseconds; while(true) { game.Draw(window); Thread.Sleep(100); if (sw.ElapsedMilliseconds > lastTick + 1000) { game.MoveMonsters(); lastTick = sw.ElapsedMilliseconds; continue; } if (sw.ElapsedMilliseconds > lastFuelTick + 5000) { game.Player.Fuel++; lastFuelTick = sw.ElapsedMilliseconds; } while (Console.KeyAvailable) { var k = Console.ReadKey(true); switch (k.KeyChar) { case 'w': game.MovePlayer(0, -1); break; case 'a': game.MovePlayer(-1, 0); break; case 's': game.MovePlayer(0, 1); break; case 'd': game.MovePlayer(1, 0); break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': game.Rewind(k.KeyChar - '0'); break; } } } }
public Game(Window window) { _window = window; var rng = new Random(); State = new GameState { Dungeon = new Dungeon(window.Width, window.Height), Monsters = Enumerable.Range(0, rng.Next(50)) .Select( _ => new Monster { Position = new Point(rng.Next(1, window.Width - 1), rng.Next(1, window.Height - 1)) }) .ToList(), }; State.Previous = State; // loopback Player = new Player {Position = new Point(5, 5), Fuel = 10}; Turns = 0; }
public void Draw(Window window) { for (int i = 0; i < Width; ++i) { for (int j = 0; j < Height; j++) { if (_tiles[i, j].Kind != TileKind.Open) window.Set(new Point(i, j), _tiles[i, j], ConsoleColor.White); } } }
public void Draw(Window window) { window.Set(Position, '@', ConsoleColor.Green); }
public void Draw(Window window) { window.Set(Position, 'X', ConsoleColor.Red); }