예제 #1
0
        public static DialogResult Show()

        {
            pauseForm = new PauseForm();
            pauseForm.ShowDialog();

            return(buttonResult);
        }
예제 #2
0
        private void GameScreen_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            //pause function
            if (e.KeyCode == Keys.Escape)
            {
                gameWatch.Stop();

                DialogResult result = PauseForm.Show();

                if (result == DialogResult.Cancel)
                {
                    gameWatch.Start();
                }
                else if (result == DialogResult.Abort)
                {
                    Form1.ChangeScreen(this, "MenuScreen");
                    this.Dispose();
                }
            }

            switch (e.KeyCode)
            {
            //moves the selector based on inputs
            case Keys.Right:
                gameSelector.Move("right", blocks);
                Refresh();
                break;

            case Keys.Left:
                gameSelector.Move("left", blocks);
                Refresh();
                break;

            case Keys.Up:
                gameSelector.Move("up", blocks);
                Refresh();
                break;

            case Keys.Down:
                gameSelector.Move("down", blocks);
                Refresh();
                break;

            //reveals the selected block
            case Keys.Enter:
                //resets the game
                if (gameSelector.index == -1)
                {
                    gameLose  = false;
                    gameWin   = false;
                    bombsLeft = bombNumber;
                    blocks.Clear();
                    CreateBlocks(blockSize, rowLength);
                    gameWatch.Reset();
                    moves      = 0;
                    score      = 0;
                    firstClick = true;
                }
                //only happens on the first selection the player makes
                else if (firstClick)
                {
                    //starts the timer
                    gameWatch.Start();
                    moves++;
                    //creates all bombs and the next to number
                    CreateBombs(bombNumber, gameSelector.index);
                    CreateNextTo();
                    //reveals the selected block
                    blocks[gameSelector.index].revealed = true;
                    blocks[gameSelector.index].RevealSurroundings(gameSelector.index);
                    //ensures this function doesn't happen again this game
                    firstClick = false;
                }
                //when the player reveals a bomb
                else if (blocks[gameSelector.index].bomb && blocks[gameSelector.index].flag == false)
                {
                    //play the death sound effect, stop the timer, set the game loss variable to true
                    player.Play();
                    gameLose = true;
                    gameWatch.Stop();
                    moves++;
                    //reveal the selected block
                    blocks[gameSelector.index].revealed = true;
                }
                //when the player reveals a block, they can't reveal a flagged block
                else if (blocks[gameSelector.index].flag == false)
                {
                    //reveal the block
                    blocks[gameSelector.index].revealed = true;
                    blocks[gameSelector.index].RevealSurroundings(gameSelector.index);
                    moves++;
                    //check to see if all the blocks that aren't bombs are revealed
                    bool winGame = true;
                    foreach (block b in blocks)
                    {
                        if (b.bomb == false && b.revealed == false)
                        {
                            winGame = false;
                        }
                    }
                    //if they are the player wins the game
                    if (winGame)
                    {
                        gameWin = true;
                        Refresh();
                        WinGame();
                    }
                }
                //redraw the screen
                Refresh();
                break;

            case Keys.Space:
                //do nothing if this is the first selection of the game
                if (firstClick || gameSelector.index == -1)
                {
                }
                //if the player selects an already flagged block
                else if (blocks[gameSelector.index].revealed == false && blocks[gameSelector.index].flag)
                {
                    //unflag the block and increase the displayed number of bombs left
                    blocks[gameSelector.index].flag = false;
                    bombsLeft++;
                }
                //if the player selects a block that isn't flaged or revealed
                else if (blocks[gameSelector.index].revealed == false && blocks[gameSelector.index].flag == false)
                {
                    //flag the block and decrease the displayed number of bombs left
                    blocks[gameSelector.index].flag = true;
                    bombsLeft--;
                }
                //redraw the screen
                Refresh();
                break;
            }
        }