Ejemplo n.º 1
0
        //Event handler for RLNet update event
        private static void OnRootConsoleUpdate(object Sender, UpdateEventArgs e)
        {
            //Creates a new variable to store whether the player has moved
            //      Used to determine where to move the player's symbol if
            //      the player has moved
            bool didPlayerAct = false;
            //Creates a keypress variable to store the last key pressed by
            //      the user
            RLKeyPress keyPress = rootConsole.Keyboard.GetKeyPress();

            Commands.IsPlayerTurn = true;
            if (Commands.IsPlayerTurn)
            {
                //If there is a keypress
                if (keyPress != null)
                {
                    //If the player presses up or W
                    if (keyPress.Key == RLKey.Up || keyPress.Key == RLKey.W)
                    {
                        //Move the player up and update didPlayerMove
                        didPlayerAct = Commands.MovePlayer(Direction.Up);
                    }
                    //If the player presses down or S
                    else if (keyPress.Key == RLKey.Down || keyPress.Key == RLKey.S)
                    {
                        //Move the player down and update didPlayerMove
                        didPlayerAct = Commands.MovePlayer(Direction.Down);
                    }
                    //If the player presses left or A
                    else if (keyPress.Key == RLKey.Left || keyPress.Key == RLKey.A)
                    {
                        //Move the player left and update didPlayerMove
                        didPlayerAct = Commands.MovePlayer(Direction.Left);
                    }
                    //If the player presses right or D
                    else if (keyPress.Key == RLKey.Right || keyPress.Key == RLKey.D)
                    {
                        //Move the player right and update didPlayerMove
                        didPlayerAct = Commands.MovePlayer(Direction.Right);
                    }
                    //If the player presses E
                    else if (keyPress.Key == RLKey.E)
                    {
                        //Checks to see if the player is standing on the stairs
                        //      to go down to the next level
                        if (DungeonMap.CanPlayerGoDown())
                        {
                            //Create a new map for the second floor of the dungeon
                            MapGenerator mapGenerator = new MapGenerator(mapWidth, mapHeight, 40, 14, 7, ++mapLevel);
                            DungeonMap = mapGenerator.CreateMap();
                            //Creates a new command instance to contorl the player
                            Commands = new Commands();
                            //Updates the console title to reflect the dungeon level
                            rootConsole.Title = $"Shiv - Level 1 - Seed: {mapSeed} - Level: {mapLevel}";
                            //Renders the screen
                            didPlayerAct = true;
                        }

                        //checks to see if the player is within 1 tile of the item
                        if (DungeonMap.CanPlayerOpenChest())
                        {
                            //If the player opens the chest, set the icon to be the
                            //      open chest and have open chest properties
                            DungeonMap.ChestClosed = DungeonMap.ChestOpen;

                            ItemGenerator = new ItemGenerator();
                            ItemGenerator.GenerateRandomItem();
                            ItemGenerator.UpdatePlayerStats();

                            //Renders the screen
                            didPlayerAct = true;
                        }
                    }
                    //If the player presses escape
                    else if (keyPress.Key == RLKey.Escape)
                    {
                        //Close the game
                        rootConsole.Close();
                    }
                }

                //If the player moved
                if (didPlayerAct)
                {
                    //Render the game screen
                    renderRequired = true;

                    Commands.EndPlayerturn();
                }
                else
                {
                    Commands.ActivateMonsters();
                    renderRequired = true;
                }
            }
        }