Ejemplo n.º 1
0
 private void HandleScore(TextBox scoreBox, Label points, Label otherPlayer)
 {
     try
     {
         if (0 > int.Parse(scoreBox.Text) | int.Parse(scoreBox.Text) > 27)
         {
             ScoreCheck.SetError(scoreBox, "Score must be between 0 and 27");
             scoreBox.Focus();
         }
         else
         {
             ScoreCheck.SetError(scoreBox, "");
             //Add the score written to the points
             points.Text = (int.Parse(points.Text) + int.Parse(scoreBox.Text)).ToString();
         }
     }
     catch (System.InvalidCastException ext)
     {
         //Something other than a number
         if (scoreBox.Text.Length > 0)
         {
             ScoreCheck.SetError(scoreBox, "Score must be a number");
         }
     }
     catch (Exception ex)
     {
         //Eek!
         MessageBox.Show("Something went wrong!  " + ex.Message);
     }
     //Check the score
     if (int.Parse(points.Text) > 120)
     {
         if (int.Parse(points.Text) / int.Parse(otherPlayer.Text) > 1.5)
         {
             WinMessage.Text = scoreBox.Name.Substring(0, scoreBox.Name.Length - 6) + " Skunked 'em!!!";
         }
         else
         {
             WinMessage.Text = scoreBox.Name.Substring(0, scoreBox.Name.Length - 6) + " Won!!";
         }
         WinMessage.Visible = true;
     }
 }