public static void Main() { // This must be the exact name of the bitmap font file we are using or it will error. string fontFileName = "terminal8x8.png"; // Tell RLNet to use the bitmap font that we specified and that each tile is 8 x 8 pixels // Establish the seed for the random number generator from the current time int seed = (int)DateTime.UtcNow.Ticks; Random = new DotNetRandom(seed); // The title will appear at the top of the console window string consoleTitle = $"RougeSharp V3 Tutorial - Level {_mapLevel} - Seed {seed}"; CommandSystem = new CommandSystem(); _rootConsole = new RLRootConsole(fontFileName, _screenWidth, _screenHeight, 8, 8, 1f, consoleTitle); _mapConsole = new RLConsole(_mapWidth, _mapHeight); _messageConsole = new RLConsole(_messageWidth, _messageHeight); _statConsole = new RLConsole(_statWidth, _statHeight); _inventoryConsole = new RLConsole(_inventoryWidth, _inventoryHeight); _mapConsole.SetBackColor(0, 0, _mapWidth, _mapHeight, Colors.FloorBackground); _mapConsole.Print(1, 1, "", Colors.TextHeading); // Create a new MessageLog and print the random seed used to generate the level MessageLog = new MessageLog(); MessageLog.Add("The rogue arrives on level 1"); MessageLog.Add($"Level created with seed '{seed}'"); _inventoryConsole.SetBackColor(0, 0, _inventoryWidth, _inventoryHeight, Swatch.DbWood); _inventoryConsole.Print(1, 1, "Inventory", Colors.TextHeading); SchedulingSystem = new SchedulingSystem(); MapGenerator mapGenerator = new MapGenerator(_mapWidth, _mapHeight, 20, 13, 7, _mapLevel); DungeonMap = mapGenerator.CreateMap(); DungeonMap.UpdatePlayerFieldOfView(); // Set up a handler for RLNET's Update event _rootConsole.Update += OnRootConsoleUpdate; // Set up a handler for RLNET's Render event _rootConsole.Render += OnRootConsoleRender; // Begin RLNET's game loop _rootConsole.Run(); }
// Event handler for RLNET's Update event private static void OnRootConsoleUpdate(object sender, UpdateEventArgs e) { bool didPlayerAct = false; RLKeyPress keyPress = _rootConsole.Keyboard.GetKeyPress(); if (CommandSystem.IsPlayerTurn) { if (keyPress != null) { if (keyPress.Key == RLKey.Up) { didPlayerAct = CommandSystem.MovePlayer(Direction.Up); } else if (keyPress.Key == RLKey.Down) { didPlayerAct = CommandSystem.MovePlayer(Direction.Down); } else if (keyPress.Key == RLKey.Left) { didPlayerAct = CommandSystem.MovePlayer(Direction.Left); } else if (keyPress.Key == RLKey.Right) { didPlayerAct = CommandSystem.MovePlayer(Direction.Right); } else if (keyPress.Key == RLKey.Escape) { _rootConsole.Close(); } else if (keyPress.Key == RLKey.Period) { if (DungeonMap.CanMoveDownToNextLevel()) { MapGenerator mapGenerator = new MapGenerator(_mapWidth, _mapHeight, 20, 13, 7, ++_mapLevel); DungeonMap = mapGenerator.CreateMap(); MessageLog = new MessageLog(); CommandSystem = new CommandSystem(); _rootConsole.Title = $"RougeSharp RLNet Tutorial - Level {_mapLevel}"; didPlayerAct = true; } } else if (keyPress.Key == RLKey.W) { CommandSystem.PlayerWait(); didPlayerAct = true; MessageLog.Add("Player Waited a Turn"); } } if (didPlayerAct) { _renderRequired = true; CommandSystem.EndPlayerTurn(); } } else { CommandSystem.ActivateMonsters(); _renderRequired = true; } }