private void FrmMap_KeyDown(object sender, KeyEventArgs e)
        {
            MoveDir dir = MoveDir.NO_MOVE;

            switch (e.KeyCode)
            {
            case Keys.Left:
                dir = MoveDir.LEFT;
                break;

            case Keys.Right:
                dir = MoveDir.RIGHT;
                break;

            case Keys.Up:
                dir = MoveDir.UP;
                break;

            case Keys.Down:
                dir = MoveDir.DOWN;
                break;
            }
            if (dir != MoveDir.NO_MOVE)
            {
                character.Move(dir);
                if (game.State == GameState.FIGHTING)
                {
                    FrmArena frmArena = new FrmArena();
                    frmArena.Show();
                }
                if (game.State == GameState.BOSS_FIGHT)
                {
                    FrmArena frmArena = new FrmBossArena();
                    frmArena.Show();
                }
            }
        }
Exemple #2
0
        private void FrmMap_KeyDown(object sender, KeyEventArgs e)
        {
            // disallow input if we're in the middle of a fight
            if (game.State == GameState.FIGHTING)
            {
                return;
            }

            MoveDir dir = MoveDir.NO_MOVE;

            switch (e.KeyCode)
            {
            case Keys.Left:
                dir = MoveDir.LEFT;
                break;

            case Keys.Right:
                dir = MoveDir.RIGHT;
                break;

            case Keys.Up:
                dir = MoveDir.UP;
                break;

            case Keys.Down:
                dir = MoveDir.DOWN;
                break;

            case Keys.S:
                // SAVE HERE
                DialogResult result = MessageBox.Show("Do you want to save the current game state?", "SAVE GAME", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    Save.SaveGame();
                }
                break;

            case Keys.L:
                DialogResult response = MessageBox.Show("You are about to load a saved game. Is this correct?", "SAVE GAME", MessageBoxButtons.YesNo);
                if (response == DialogResult.Yes)
                {
                    var savelines = GameLibrary.Load.LoadGame();
                    Reload(savelines[0], savelines);
                }
                break;

            case Keys.Q:
                ExitGame();
                break;

            case Keys.I:
                FrmStats stats = new FrmStats();
                stats.Show();
                break;
            }
            if (dir != MoveDir.NO_MOVE)
            {
                // tell the character to move and check if the move was valid
                switch (character.Move(dir))
                {
                case Task.MOVE:
                    // check for enemy encounter
                    if (rand.NextDouble() < encounterChance)
                    {
                        encounterChance = 0.15;
                        Game.GetGame().ChangeState(GameState.FIGHTING);
                    }
                    else
                    {
                        encounterChance += 0.10;
                    }
                    if (game.State == GameState.FIGHTING)
                    {
                        FrmArena frmArena = new FrmArena();
                        frmArena.Show();
                    }
                    break;

                case Task.FIGHT_BOSS:
                    FrmBossArena frmBoss = new FrmBossArena();
                    frmBoss.Show();
                    break;

                case Task.LEAVE_LEVEL:
                    //this should give player option of which level to go to
                    int currentLevel = Game.GetGame().Level;
                    Game.GetGame().NextLevel();
                    if (currentLevel != Game.GetGame().Level)
                    {
                        ChangeMap("Resources/level" + Game.GetGame().Level + ".txt", Game.GetGame().Character);
                    }
                    break;

                case Task.EXIT_GAME:
                    ExitGame();
                    break;
                }
            }
        }