예제 #1
0
        public static void Main()
        {
            MessageLog       = new MessageLog();
            CommandSystem    = new CommandSystem();
            SchedulingSystem = new SchedulingSystem();

            int seed = (int)DateTime.UtcNow.Ticks;

            Random = new DotNetRandom(seed);
            MessageLog.Add($"Level created with seed {seed}");

            //this must be the exact name of the bitmap font file we are using
            var fontFileName = "terminal8x8.png";
            //this title will appear at the top of the console window
            var consoleTitle = "Roguesharp Tutorial - Level 1 - Seed {seed}";

            _rootConsole = new RLRootConsole(fontFileName, _screenWidth, _screenHeight, 8, 8, 1f, consoleTitle);


            MapGenerator mapGenerator = new MapGenerator(_mapWidth, _mapHeight, 20, 13, 7);

            DungeonMap = mapGenerator.CreateMap();
            DungeonMap.updatePlayerFieldOfView();
            MessageLog.Add($"Map generated and player added");


            // Initialize the sub consoles that we will Blit to the root console
            _mapConsole       = new RLConsole(_mapWidth, _mapHeight);
            _messageConsole   = new RLConsole(_messageWidth, _messageHeight);
            _statConsole      = new RLConsole(_statWidth, _statHeight);
            _inventoryConsole = new RLConsole(_inventoryWidth, _inventoryHeight);
            //set up a handler for the update event
            _rootConsole.Update += OnRootConsoleUpdate;
            _rootConsole.Render += OnRootConsoleRender;

            _currentState  = _gameStates.MainMenu;
            renderRequired = true;

            _rootConsole.Run();
        }
예제 #2
0
        private static void OnRootConsoleUpdate(object sender, UpdateEventArgs e)
        {
            bool       didUnitAct    = false;
            bool       didPlayerAct  = false;
            bool       didMenuUpdate = false;
            RLKeyPress keyPress      = _rootConsole.Keyboard.GetKeyPress();

            if (_currentState == _gameStates.MainMenu)
            {
                _mapConsole.SetBackColor(0, 0, _mapWidth, _mapHeight, RLColor.Black);
                _mapConsole.Print(1, 1, "Press G to start a new game", Colors.TextHeading);
                renderRequired = true;

                if (keyPress != null)
                {
                    if (keyPress.Key == RLKey.G)
                    {
                        _currentState = _gameStates.InGame;
                        //on a state change we need to redraw the interface
                        guiRedraw = true;
                    }
                }

                //draw menu
            }
            else if (_currentState == _gameStates.InGame)
            {
                //handle player input when we're ingame

                if (CommandSystem.isPlayerTurn)
                {
                    if (keyPress != null)
                    {
                        switch (keyPress.Key)
                        {
                        case RLKey.Up:
                            didPlayerAct = CommandSystem.MovePlayer(Directions.Up);
                            break;

                        case RLKey.Down:
                            didPlayerAct = CommandSystem.MovePlayer(Directions.Down);
                            break;

                        case RLKey.Left:
                            didPlayerAct = CommandSystem.MovePlayer(Directions.Left);
                            break;

                        case RLKey.Right:
                            didPlayerAct = CommandSystem.MovePlayer(Directions.Right);
                            break;

                        case RLKey.Escape:
                            _rootConsole.Close();
                            break;
                        }

                        if (didPlayerAct)
                        {
                            renderRequired = true;
                            mapRedraw      = true;
                            CommandSystem.EndPlayerTurn();
                        }
                    }
                }
                else if (!CommandSystem.isPlayerTurn)
                {
                    CommandSystem.ActivateMonsters();
                    renderRequired = true;
                }

                //draw gui if not drawn
                if (guiRedraw)
                {
                    _mapConsole.Clear();
                    _mapConsole.SetBackColor(0, 0, _mapWidth, _mapHeight, Colors.FloorBackground);
                    mapRedraw = true;

                    _messageConsole.Clear();
                    _messageConsole.SetBackColor(0, 0, _messageWidth, _messageHeight, Swatch.DbDeepWater);


                    _statConsole.Clear();
                    _statConsole.SetBackColor(0, 0, _statWidth, _statHeight, Swatch.DbOldStone);

                    _inventoryConsole.Clear();
                    _inventoryConsole.SetBackColor(0, 0, _inventoryWidth, _inventoryHeight, Swatch.DbWood);
                    _inventoryConsole.Print(1, 1, "Inventory", Colors.TextHeading);

                    renderRequired = true;
                    guiRedraw      = false;
                }

                if (mapRedraw)
                {
                    MessageLog.Draw(_messageConsole);
                    DungeonMap.Draw(_mapConsole, _statConsole);
                    Player.Draw(_mapConsole, DungeonMap);
                    Player.DrawStats(_statConsole);
                    renderRequired = true;
                    mapRedraw      = false;
                }
            }
        }