Ejemplo n.º 1
0
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else
     {
         Destroy(this.gameObject);
     }
 }
Ejemplo n.º 2
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;
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// <see cref="ScoreReferee"/>'s constructor.
 /// </summary>
 /// <param name="pause">How to pause the game whenever a player scores.</param>
 /// <param name="end">How to end the game.</param>
 /// <param name="isOver">How to check if the score should end the match.</param>
 /// <param name="subscribeToScore">How to subscribe to the match scoring.</param>
 protected ScoreReferee(Pauser pause, Action end, ScoreCheck isOver, Action <Scorer> subscribeToScore)
     : base(pause, end, subscribeToScore)
 {
     _isOver = isOver;
 }