Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Flappy Bird Crashes after Die (format exception vas unhandled)

flappy bird crash unhandled

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1 googooli86

googooli86

    CC Lurker

  • New Member
  • Pip
  • 9 posts

Posted 02 April 2015 - 05:50 AM

Hello.

 

My game crashes after die.

I get the following error: Format Exception Was Unhandled.

What the game is trying to do is to read the final score and show a message box with current score and the "highest score".

 

Here is my code:

 

 
 private void ReadAndShowScore()
        {
            using (StreamReader reader = new StreamReader("Score.ini"))
            {
                score = int.Parse(reader.ReadToEnd());
                reader.Close();
                if (int.Parse(lbl_score.Text) == 0 | int.Parse(lbl_score.Text) > 0)
                {
                    scoredifferent = score - int.Parse(lbl_score.Text) + 1;
                }
                if (score < int.Parse(lbl_score.Text))
                {
                    MessageBox.Show(string.Format("Congratulations, you have made a higher score than {0}.\r\n The new highscore is: {1}", score, lbl_score.Text), "Flappy Bird", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    using (StreamWriter writer = new StreamWriter("Score.ini"))
                    {
                        writer.Write(lbl_score.Text);
                        writer.Close();
                    }
                }
                if (score > int.Parse(lbl_score.Text))
                {
                    MessageBox.Show(string.Format("You still had to get {0}\r\n Highscore is: {1}", scoredifferent, score), "Flappy Bird", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                if (score == int.Parse(lbl_score.Text))
                {
                    MessageBox.Show(string.Format("You did exactly {0} (max score). Try to get higher next time.", score), "Flappy Bird", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }

Edited by googooli86, 02 April 2015 - 05:51 AM.


#2 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts

Posted 02 April 2015 - 07:13 PM

the problem is with int.parse, when you try to parse a non-number.

Use int.TryParse instead.






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download