コード例 #1
0
ファイル: Bat.cs プロジェクト: emersonschulze/CSharp-Livro
 public void HitTheBall(BallEventArgs e)
 {
     if (hitBallCalback != null)
     {
         //hitBallCalback(e);
     }
 }
コード例 #2
0
ファイル: Ball.cs プロジェクト: emersonschulze/CSharp-Livro
 public void OnBallInPlay(BallEventArgs e)
 {
     if (BallInPlay != null)
     {
         BallInPlay(this, e);
     }
 }
コード例 #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Aqui os argumentos do evento são inicializados
            BallEventArgs ballEventArgs = new BallEventArgs((int)Trajetoria.Value, (int)Distancia.Value);

            //Aqui o evento é chamado junto com os argumentos inseridos como parâmetros
            ball.OnBallInPlay(ballEventArgs);
        }
コード例 #4
0
 private void Ball_BallInPlay(object sender, EventArgs e)
 {
     //Condição para ver se 'e'  também é referente a BallEventArgs
     if (e is BallEventArgs)
     {
         //Aqui acontece uma coerção em que 'e' é convertido em BallEventArgs
         BallEventArgs ballEventArgs = e as BallEventArgs;
         //Logo em seguida as atributos de ballEventArgs são acessados e utilizados
         if ((ballEventArgs.Distance < 400) && (ballEventArgs.Trajectory < 30))
         {
             HomeRun();
         }
         else
         {
             Scream();
         }
     }
 }
コード例 #5
0
 private void ball_BallInPlay(object sender, EventArgs e)
 {
     //Condição para ver se 'e'  também é referente a BallEventArgs
     if (e is BallEventArgs)
     {
         //Aqui acontece uma coerção em que 'e' é convertido em BallEventArgs
         BallEventArgs ballEventArgs = e as BallEventArgs;
         //Logo em seguida as atributos de ballEventArgs são acessados e utilizados
         if ((ballEventArgs.Distance < 95) && (ballEventArgs.Trajectory < 60))
         {
             CatchBall();
         }
         else
         {
             CoverFirstBase();
         }
     }
 }