Пример #1
0
 //when highscore button is clicked do the following
 private void btnHighscores_Click(object sender, EventArgs e)
 {
     //hide the menu form
     this.Hide();
     //create a new highscore form
     HighScoreForm frmHighScore = new HighScoreForm();
     //show highsore form
     frmHighScore.Show();
 }
Пример #2
0
        //Draws the scene
        private void DrawScene(Graphics grfx)
        {
            //drawTime++;
            //Only draw if it is time to update
            if (timeToUpdate == true)
            {
                grfx.DrawImage(background, 0, 0, DisplayRectangle.Width, DisplayRectangle.Height);
                //increases the drawTime variable by 1
                drawTime++;
                //Reset update status so it will wait for the
                //next appropriate time to update
                timeToUpdate = false;

                //draw the building on to the form
                building.Draw(grfx);

                //run a for loop for the windows to draw them as rows
                for (int column = 0; column < building.Windows.GetLength(0); column++)
                {
                    //run a for loop for the windows to draw them as columns
                    for (int row = 0; row < building.Windows.GetLength(1); row++)
                    {
                        //draw in the windows on to the building
                        building.Windows[column, row].Draw(grfx);
                    }
                }

                //mario is on the 6th frame of the animation or the 12th frame of animation
                if (mario.CurrentFrameIndex == 6 || mario.CurrentFrameIndex == 12)
                {
                    //set mario's width to 55 pixals
                    mario.Width = 55;
                    //set mario's height to 60 pixals
                    mario.Height = 60;
                }

                //if mario's frame of animation is the 13th one
                else if (mario.CurrentFrameIndex == 13)
                {
                   //set marios width to 20 pixals
                    mario.Width = 20;
                    //set mario's height to 20 pixals as well
                    mario.Height = 20;
                }
                //else wise for any other frame
                else
                {
                    //set mario's width to 25 pixals
                    mario.Width = 25;
                    //set mario's height to 60 pixals
                    mario.Height = 60;
                }
                //draw mario on the screen
                mario.Draw(grfx);

                //if draw time is up to 5
                if (drawTime == 5)
                {
                    //then bowser will be drawn
                    bowser.Draw(grfx);

                    //run an index for loop for the drawing of the birds
                    for (int index = 0; index < birds.Length; index++)
                    {
                        //draw each index of the birds in its array
                        birds[index].Draw(grfx);
                    }
                    //set draw time back to 0
                    drawTime = 0;
                }

                //else
                else
                {
                    //draw bowser without moving it to its next frame of animation
                    bowser.Draw(grfx, false);

                    //run a index for loop for all the birds
                    for (int index = 0; index < birds.Length; index++)
                    {
                        //draws the bird without moving it to its next frame of animation
                        birds[index].Draw(grfx,false);
                    }
                }

                //run an index for loop for the fireballs
                for (int index = 0; index < fireballs.Length; index++)
                {
                    //draws the fireball
                    fireballs[index].Draw(grfx);
                }

                //run a index for loop to draw the walls on to the game form
                for (int index = 0; index < walls.Length; index++)
                {
                    //draw each of the walls
                    walls[index].Draw(grfx);
                }

                //if mushrooms can be displayed on the screen
                if (displayMushrooms == true)
                {
                    //run a index for loops for the mushrooms
                    for (int index = 0; index < mushrooms.Length; index++)
                    {
                        //draw mushroom of all index
                        mushrooms[index].Draw(grfx);
                    }
                }

                //run a index for loop for the lives and draw them onto the form
                for (int index = 0; index < lives.Length; index++)
                {
                    //draw each index of the lives
                    lives[index].Draw(grfx);
                }
            }

            //if mario has no more lives
            if (mario.Lives == 0)
            {
                //the game is over
                gameOver = true;
                //and mario will fall down the building
                mario.Y += 20;
            }

            //if all the windows on the building have been fixed
            if (CountNumFixedWindows(building.Windows) == building.Windows.Length)
            {
                //the game is over
                gameOver = true;
                //and bowser has not been shot from the canon yet
                if (shotOnce == false)
                {
                    //shoot bowser from the conon using the animation subprogram
                    bowser.ShootFromCanon();
                    //and set browser to has been shot
                    shotOnce = true;
                }
                //if bowser is animated to fly
                if (bowser.CurrentFrameIndex == 6)
                {
                    //launch him across the screen
                    bowser.X -= 20;
                }
            }

            //if the game is over
            if (gameOver == true)
            {
                //remove all the fireballs from the screen
                fireballs = new Fireball[0];
                //remove all the mushrooms from the screen
                mushrooms = new Mushroom[0];
                //remove all the birds from the screen
                birds = new Bird[0];
            }

            //If mario has fallen below the screen (aka he is dead)
            if (mario.Y > DisplayRectangle.Height)
            {
                //add the score to the highscore form (which will be determined if it is kept or not by the highschore form)
                HighScoreForm frmHighScore = new HighScoreForm(currentScore);
                //goes to the menu
                GoToMenu();
            }

            //after bowser leaves the screen after being lanuched
            if (bowser.X < 0)
            {
                //increase the diffculty of the frame rate
                difficultyTime -= 5;
                //if the diffuclty time is already below 5
                if (difficultyTime < 5)
                {
                    //set it 5
                    difficultyTime = 5;
                }
                //increase the number of birds by one
                numBirds++;
                //increase the speed of the birds
                birdSpeed += 5;

                //If the level that is being played is part of the main (infinite) game...
                if (levelToPlay == "infiniteGame.txt")
                {
                    //using streamwriter add the diffculity to its text file respectfully so it can be used
                    //by the game to set the properties of the game
                    using (StreamWriter sw = new StreamWriter(levelToPlay, false))
                    {
                        //write to the first line the difficulty of frame rate
                        sw.WriteLine(difficultyTime.ToString());
                        //to the next line write the number of walls
                        sw.WriteLine(numWalls.ToString());
                        //to the next line write the number of mushrooms
                        sw.WriteLine(numMushrooms.ToString());
                        //to the next lne write the number of birds
                        sw.WriteLine(numBirds.ToString());
                        //to the next time write the speed of the birds
                        sw.WriteLine(birdSpeed.ToString());
                    }
                    //to save the current score as the gameform changes write it to the current text file
                    //which is overwritable
                    using (StreamWriter sw = new StreamWriter("currentScore.txt", false))
                    {
                        //write on the first line
                        sw.WriteLine(currentScore.ToString());
                    }
                    //go to menu
                    GoToMenu();
                    //create a new game form
                    GameForm frmGame = new GameForm(frmMenu, levelToPlay);
                    //and show it has the next level
                    frmGame.Show();
                }
                //If the level being played is not part of the main(infinite) game
                else
                {
                    GoToMenu(); //go to the menu
                }
            }
        }