Ejemplo n.º 1
0
        //Deal with user input
        //Return code is if the command was successful and time increments (i.e. the player has done a time-using command like moving)
        private bool UserInput()
        {
            bool timeAdvances = false;

            KeyPress userKey = Keyboard.WaitForKeyPress(true);

            //Each state has different keys

            switch (inputState)
            {
            //Normal movement on the map
            case InputState.MapMovement:

                if (userKey.KeyCode == KeyCode.TCODK_CHAR)
                {
                    char keyCode = (char)userKey.Character;
                    switch (keyCode)
                    {
                    case 'x':
                        //Exit from game
                        runMapLoop   = false;
                        timeAdvances = true;
                        break;

                    case '.':
                        // Do nothing
                        timeAdvances = true;
                        break;

                    case 'i':
                        //Interact with feature
                        timeAdvances = InteractWithFeature();
                        if (!timeAdvances)
                        {
                            UpdateScreen();
                        }
                        break;

                    case 'j':
                        //Display the inventory
                        inputState = InputState.InventoryShow;
                        SetPlayerInventoryScreen();
                        UpdateScreen();
                        timeAdvances = false;
                        break;

                    case 'u':
                        //Use an inventory item
                        SetPlayerInventorySelectScreen();
                        UpdateScreen();
                        //This uses the generic 'select from inventory' input loop
                        //Time advances if the item was used successfully
                        timeAdvances = UseItem();
                        DisablePlayerInventoryScreen();
                        //Only update the screen if the player has another selection to make, otherwise it will be updated automatically before his next go
                        if (!timeAdvances)
                        {
                            UpdateScreen();
                        }
                        break;

                    case 'e':
                        //Select an item to equip
                        SetPlayerEquippedItemsSelectScreen();
                        UpdateScreen();
                        timeAdvances = EquipItem();
                        DisablePlayerEquippedItemsSelectScreen();
                        if (!timeAdvances)
                        {
                            UpdateScreen();
                        }
                        break;

                    case 'w':
                        //Display currently equipped items
                        SetPlayerEquippedItemsScreen();
                        UpdateScreen();
                        DisplayEquipment();
                        DisablePlayerEquippedItemsScreen();
                        UpdateScreen();
                        timeAdvances = false;
                        break;

                    case ',':
                        //Pick up item
                        timeAdvances = PickUpItem();
                        //Only update screen is unsuccessful, otherwise will be updated in main loop (can this be made general)
                        if (!timeAdvances)
                        {
                            UpdateScreen();
                        }
                        break;

                    case 'd':
                        //Drop item
                        SetPlayerInventorySelectScreen();
                        UpdateScreen();
                        timeAdvances = DropItem();
                        DisablePlayerInventoryScreen();
                        if (!timeAdvances)
                        {
                            UpdateScreen();
                        }
                        break;

                    //Debug events

                    case 's':
                        //Add a speed up event on the player
                        PlayerEffects.SpeedUp speedUp = new RogueBasin.PlayerEffects.SpeedUp(Game.Dungeon.Player, 500, 100);
                        Game.Dungeon.Player.AddEffect(speedUp);
                        UpdateScreen();
                        break;

                    case 'h':
                        //Add a healing event on the player
                        PlayerEffects.Healing healing = new RogueBasin.PlayerEffects.Healing(Game.Dungeon.Player, 10);
                        Game.Dungeon.Player.AddEffect(healing);
                        UpdateScreen();
                        break;

                    case 'z':
                        //Add an anti-healing event on the player
                        PlayerEffects.Healing zhealing = new RogueBasin.PlayerEffects.Healing(Game.Dungeon.Player, -10);
                        Game.Dungeon.Player.AddEffect(zhealing);
                        UpdateScreen();
                        break;

                    case 'o':
                        //Open door
                        timeAdvances = PlayerOpenDoor();
                        if (!timeAdvances)
                        {
                            UpdateScreen();
                        }
                        break;
                    }
                }
                else
                {
                    //Arrow keys for directions
                    switch (userKey.KeyCode)
                    {
                    case KeyCode.TCODK_KP1:
                        timeAdvances = dungeon.PCMove(-1, 1);
                        break;

                    case KeyCode.TCODK_KP3:
                        timeAdvances = dungeon.PCMove(1, 1);
                        break;

                    case KeyCode.TCODK_KP5:
                        //Don't move
                        timeAdvances = true;
                        break;

                    case KeyCode.TCODK_KP7:
                        timeAdvances = dungeon.PCMove(-1, -1);
                        break;

                    case KeyCode.TCODK_KP9:
                        timeAdvances = dungeon.PCMove(1, -1);
                        break;

                    case KeyCode.TCODK_LEFT:
                    case KeyCode.TCODK_KP4:
                        timeAdvances = dungeon.PCMove(-1, 0);
                        break;

                    case KeyCode.TCODK_RIGHT:
                    case KeyCode.TCODK_KP6:
                        timeAdvances = dungeon.PCMove(1, 0);
                        break;

                    case KeyCode.TCODK_UP:
                    case KeyCode.TCODK_KP8:
                        timeAdvances = dungeon.PCMove(0, -1);
                        break;

                    case KeyCode.TCODK_KP2:
                    case KeyCode.TCODK_DOWN:
                        timeAdvances = dungeon.PCMove(0, 1);
                        break;
                    }
                }
                break;

            //Inventory is displayed
            case InputState.InventoryShow:

                if (userKey.KeyCode == KeyCode.TCODK_CHAR)
                {
                    char keyCode = (char)userKey.Character;

                    //Exit out of inventory
                    if (keyCode == 'x')
                    {
                        inputState = InputState.MapMovement;
                        DisablePlayerInventoryScreen();
                        UpdateScreen();
                        timeAdvances = false;
                    }
                }

                break;

                //Select an item in the inventory
                //case InputState.InventoryShow:
                //    break;
            }

            return(timeAdvances);
        }
Ejemplo n.º 2
0
        //Deal with user input
        //Return code is if the command was successful and time increments (i.e. the player has done a time-using command like moving)
        private bool UserInput()
        {
            bool timeAdvances = false;

            KeyPress userKey = Keyboard.WaitForKeyPress(true);

            //Each state has different keys

            switch (inputState)
            {

                //Normal movement on the map
                case InputState.MapMovement:

                    if (userKey.KeyCode == KeyCode.TCODK_CHAR)
                    {
                        char keyCode = (char)userKey.Character;
                        switch (keyCode)
                        {
                            case 'x':
                                //Exit from game
                                runMapLoop = false;
                                timeAdvances = true;
                                break;
                            case '.':
                                // Do nothing
                                timeAdvances = true;
                                break;
                            case 'i':
                                //Interact with feature
                                timeAdvances = InteractWithFeature();
                                if (!timeAdvances)
                                    UpdateScreen();
                                break;
                            case 'j':
                                //Display the inventory
                                inputState = InputState.InventoryShow;
                                SetPlayerInventoryScreen();
                                UpdateScreen();
                                timeAdvances = false;
                                break;
                            case 'u':
                                //Use an inventory item
                                SetPlayerInventorySelectScreen();
                                UpdateScreen();
                                //This uses the generic 'select from inventory' input loop
                                //Time advances if the item was used successfully
                                timeAdvances = UseItem();
                                DisablePlayerInventoryScreen();
                                //Only update the screen if the player has another selection to make, otherwise it will be updated automatically before his next go
                                if(!timeAdvances)
                                    UpdateScreen();
                                break;
                            case 'e':
                                //Select an item to equip
                                SetPlayerEquippedItemsSelectScreen();
                                UpdateScreen();
                                timeAdvances = EquipItem();
                                DisablePlayerEquippedItemsSelectScreen();
                                if (!timeAdvances)
                                UpdateScreen();
                                break;
                            case 'w':
                                //Display currently equipped items
                                SetPlayerEquippedItemsScreen();
                                UpdateScreen();
                                DisplayEquipment();
                                DisablePlayerEquippedItemsScreen();
                                UpdateScreen();
                                timeAdvances = false;
                                break;

                            case ',':
                                //Pick up item
                                timeAdvances = PickUpItem();
                                //Only update screen is unsuccessful, otherwise will be updated in main loop (can this be made general)
                                if (!timeAdvances)
                                    UpdateScreen();
                                break;
                            case 'd':
                                //Drop item
                                SetPlayerInventorySelectScreen();
                                UpdateScreen();
                                timeAdvances = DropItem();
                                DisablePlayerInventoryScreen();
                                if (!timeAdvances)
                                    UpdateScreen();
                                break;

                            //Debug events

                            case 's':
                                //Add a speed up event on the player
                                PlayerEffects.SpeedUp speedUp = new RogueBasin.PlayerEffects.SpeedUp(Game.Dungeon.Player, 500, 100);
                                Game.Dungeon.Player.AddEffect(speedUp);
                                UpdateScreen();
                                break;
                            case 'h':
                                //Add a healing event on the player
                                PlayerEffects.Healing healing = new RogueBasin.PlayerEffects.Healing(Game.Dungeon.Player, 10);
                                Game.Dungeon.Player.AddEffect(healing);
                                UpdateScreen();
                                break;
                            case 'z':
                                //Add an anti-healing event on the player
                                PlayerEffects.Healing zhealing = new RogueBasin.PlayerEffects.Healing(Game.Dungeon.Player, -10);
                                Game.Dungeon.Player.AddEffect(zhealing);
                                UpdateScreen();
                                break;
                            case 'o':
                                //Open door
                                timeAdvances = PlayerOpenDoor();
                                if (!timeAdvances)
                                    UpdateScreen();
                                break;
                        }
                    }
                    else
                    {
                        //Arrow keys for directions
                        switch (userKey.KeyCode)
                        {
                            case KeyCode.TCODK_KP1:
                                timeAdvances = dungeon.PCMove(-1, 1);
                                break;

                            case KeyCode.TCODK_KP3:
                                timeAdvances = dungeon.PCMove(1, 1);
                                break;

                            case KeyCode.TCODK_KP5:
                                //Don't move
                                timeAdvances = true;
                                break;

                            case KeyCode.TCODK_KP7:
                                timeAdvances = dungeon.PCMove(-1, -1);
                                break;
                            case KeyCode.TCODK_KP9:
                                timeAdvances = dungeon.PCMove(1, -1);
                                break;

                            case KeyCode.TCODK_LEFT:
                            case KeyCode.TCODK_KP4:
                                timeAdvances = dungeon.PCMove(-1, 0);
                                break;
                            case KeyCode.TCODK_RIGHT:
                            case KeyCode.TCODK_KP6:
                                timeAdvances = dungeon.PCMove(1, 0);
                                break;
                            case KeyCode.TCODK_UP:
                            case KeyCode.TCODK_KP8:
                                timeAdvances = dungeon.PCMove(0, -1);
                                break;
                            case KeyCode.TCODK_KP2:
                            case KeyCode.TCODK_DOWN:
                                timeAdvances = dungeon.PCMove(0, 1);
                                break;
                        }
                    }
                    break;

                //Inventory is displayed
                case InputState.InventoryShow:

                    if (userKey.KeyCode == KeyCode.TCODK_CHAR)
                    {
                        char keyCode = (char)userKey.Character;

                        //Exit out of inventory
                        if (keyCode == 'x')
                        {
                            inputState = InputState.MapMovement;
                            DisablePlayerInventoryScreen();
                            UpdateScreen();
                            timeAdvances = false;
                        }
                    }

                    break;

                //Select an item in the inventory
                //case InputState.InventoryShow:
                //    break;
            }

            return timeAdvances;
        }