Example #1
0
        // Event handler for Update event
        private static void OnRootConsoleUpdate(object sender, UpdateEventArgs e)
        {
            //might move this junk out of consoleupdate to clean up, but this moves char for now
            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, 50, 5, 13, ++_mapLevel);
                            DungeonMap         = mapGenerator.CreateMap();
                            MessageLog         = new MessageLog();
                            CommandSystem      = new CommandSystem();
                            _rootConsole.Title = $"DungeonZ Level {_mapLevel}";
                            didPlayerAct       = true;
                        }
                    }
                }

                if (didPlayerAct)
                {
                    _renderRequired = true;
                    CommandSystem.EndPlayerTurn();
                }
            }
            else
            {
                CommandSystem.ActivateMonsters();
                _renderRequired = true;
            }
        }
Example #2
0
        public static void Play()
        {
            // fixed test seed 1138043851
            int seed = (int)DateTime.UtcNow.Ticks;

            Random = new DotNetRandom(seed);

            string fontFileName = "terminal16x16_gs_ro.png";
            string consoleTitle = $"DungeonZ Level {_mapLevel}";


            _rootConsole      = new RLRootConsole(fontFileName, _screenWidth, _screenHeight, 16, 16, 1.5f, consoleTitle);
            _mapConsole       = new RLConsole(_mapWidth, _mapHeight);
            _messageConsole   = new RLConsole(_messageWidth, _messageHeight);
            _statConsole      = new RLConsole(_statWidth, _statHeight);
            _inventoryConsole = new RLConsole(_inventoryWidth, _inventoryHeight);

            CommandSystem = new CommandSystem();
            MessageLog    = new MessageLog();
            MessageLog.Add($"{Player.Name} arrives on level 1");
            SchedulingSystem = new SchedulingSystem();
            MapGenerator mapGenerator = new MapGenerator(_mapWidth, _mapHeight, 50, 5, 13, _mapLevel);

            DungeonMap = mapGenerator.CreateMap();
            DungeonMap.UpdatePlayerFieldOfView();
            //messages have to be added after createmap to have access to player



            //register to delegate
            _rootConsole.Update += OnRootConsoleUpdate;
            _rootConsole.Render += OnRootConsoleRender;

            //these console methods have to be run before the update and render below
            _inventoryConsole.SetBackColor(0, 0, _inventoryWidth, _inventoryHeight, Swatch.DbWood);
            _inventoryConsole.Print(1, 1, "Inventory", Colors.TextHeading);

            // Run RLNet game loop
            _rootConsole.Run();
        }