예제 #1
0
파일: Form1.cs 프로젝트: nohe427/HeadFirst
        private void playBallButton_Click(object sender, EventArgs e)
        {
            BallEventArgs ballEventArgs = new BallEventArgs(
                (int)trajectory.Value, (int)distance.Value);

            ball.OnBallInPlay(ballEventArgs);
        }
예제 #2
0
 public void HitTheBall(BallEventArgs e)
 {
     if (hitBallCallback != null)
     {
         hitBallCallback(e);
     }
 }
예제 #3
0
 void Ball_BallInPlay(Object sender, BallEventArgs e)
 {
     if (e.Distance < 80 && e.Distance >= 60 && e.Trajectory < 10)
     {
         Console.WriteLine("I Poke it! ~Pitcher");
     }
 }
예제 #4
0
 void Ball_BallInPlay(Object sender, BallEventArgs e)
 {
     if (e.Distance >= 80 && e.Trajectory >= 20)
     {
         Console.WriteLine("I Catch the ball! ~Fan");
     }
 }
예제 #5
0
 private void playBallButton_Click(object sender, EventArgs e)
 {
     Bat bat = ball.GetNewBat();
     BallEventArgs ballEventArgs = new BallEventArgs(
         (int)trajectory.Value, (int)distance.Value);
     bat.HitTheBall(ballEventArgs);
 }
예제 #6
0
 public void HitTheBall(BallEventArgs e)
 {
     if (hitBallCallback != null)
     {
         hitBallCallback(e);
     }
 }
예제 #7
0
        private void playBallButton_Click(object sender, EventArgs e)
        {
            Bat           bat           = ball.GetNewBat();
            BallEventArgs ballEventArgs = new BallEventArgs(
                (int)trajectory.Value, (int)distance.Value);

            bat.HitTheBall(ballEventArgs);
        }
예제 #8
0
 public void OnBallInPlay(BallEventArgs e)
 {
     EventHandler<BallEventArgs> ballInPlay = BallInPlay;
     if (ballInPlay != null)
     {
         ballInPlay(this, e);
     }
 }
예제 #9
0
 void Ball_BallInPlay(Object sender, BallEventArgs e)
 {
     Console.WriteLine("Distance: " + e.Distance + " Trajectory: " + e.Trajectory);
     if ((e.Distance < 80 && e.Trajectory >= 10 && e.Trajectory < 20) || e.Distance < 60)
     {
         Console.WriteLine("You're Out! ~Umpire");
     }
 }
예제 #10
0
        public void OnBallInPlay(BallEventArgs e)
        {
            EventHandler <BallEventArgs> ballInPlay = BallInPlay;

            if (ballInPlay != null)
            {
                BallInPlay(this, e);
            }
        }
예제 #11
0
        protected void OnBallInPlay(BallEventArgs e)
        {
            EventHandler <BallEventArgs> ballInPlay = BallInPlay;

            if (ballInPlay != null)
            {
                ballInPlay(this, e);
            }
        }
        public void PlayBall()
        {
            Bat bat = ball.GetNewBat();
            BallEventArgs ballEventArgs = new BallEventArgs(Trajectory, Distance);
            bat.HitTheBall(ballEventArgs);

            // Below is the old implementation, until the event raiser was made protected.
            // In this way, the event can only be accessed by the Callback pattern set up in the bat object.
            // ball.OnBallInPlay(ballEventArgs);
        }
        public void PlayBall()
        {
            Bat           bat           = ball.GetNewBat();
            BallEventArgs ballEventArgs = new BallEventArgs(Trajectory, Distance);

            bat.HitTheBall(ballEventArgs);

            // Below is the old implementation, until the event raiser was made protected.
            // In this way, the event can only be accessed by the Callback pattern set up in the bat object.
            // ball.OnBallInPlay(ballEventArgs);
        }
예제 #14
0
        /// <summary>
        /// </summary>
        public void OnBallInPlayTest(BallEventArgs e)
        {
            EventHandler <BallEventArgs> ballInPlay = BallInPlayTest;

            if (ballInPlay != null)
            {
                Console.WriteLine("BallInPlayTest event params:[ angle: {0}; distance: {1} cm] \nEvent listeners: {2}", e.Angle, e.Distance,
                                  ballInPlay.GetInvocationList().Length);
                ballInPlay(this, e);
            }
            else
            {
                Console.WriteLine("Event BallInPlay have not listeners");
            }
        }
예제 #15
0
 void ball_BallInPlay(object sender, EventArgs e)
 {
     if (e is BallEventArgs)
     {
         BallEventArgs ballEventArgs = e as BallEventArgs;
         if ((ballEventArgs.Distance < 95) && (ballEventArgs.Trajectory < 60))
         {
             CatchBall();
         }
         else
         {
             CoverFirstBase();
         }
     }
 }
예제 #16
0
 void ball_BallInPlay(object sender, EventArgs e)
 {
     if (e is BallEventArgs)
     {
         BallEventArgs ballEventArgs = e as BallEventArgs;
         if (ballEventArgs.Distance > 400 && ballEventArgs.Trajectory > 30)
         {
             Console.WriteLine("Fan: Home run! I’m going for the ball!");
         }
         else
         {
             Console.WriteLine("Fan: Woo-hoo! Yeah!");
         }
     }
 }
예제 #17
0
 private void Ball_BallInPlay(object sender, EventArgs e)
 {
     pitchNumber++;
     if (e is BallEventArgs)
     {
         BallEventArgs ballEventArgs = e as BallEventArgs;
         if ((ballEventArgs.Distance > 400) && (ballEventArgs.Trajectory > 30))
         {
             GrabGloveAndCatchBall();
         }
         else
         {
             ScreamAndYell();
         }
     }
 }
예제 #18
0
        /// <summary>
        /// </summary>
        protected void OnBallInPlay(BallEventArgs e)
        {
            EventHandler ballInPlay = BallInPlay;

            if (ballInPlay != null)
            {
                StringBuilder info = new StringBuilder(
                    $"BallInPlay event params:[ angle: { e.Angle}; distance: {e.Distance} cm] \nEvent listeners: {ballInPlay.GetInvocationList().Length}");
                foreach (var element in ballInPlay.GetInvocationList())
                {
                    info.Append($"\n\t {element.Target.GetType().Name}");
                }
                Console.WriteLine(info);

                ballInPlay(this, e);
            }
            else
            {
                Console.WriteLine("Event BallInPlay have not listeners");
            }
        }
예제 #19
0
        private void btnPlayball_Click(object sender, EventArgs e)
        {
            totalClick++;
            bool isHitted = false;
            BallEventArgs ballEventArgs = new BallEventArgs()
            {
                Angle = double.Parse(txtAngle.Text),
                Distance = double.Parse(txtDistance.Text)
            };

            int randomNumber = ran.Next(1, 100);
            isHitted = (randomNumber >= 1 && randomNumber <= 100);

            if (totalClick <= 3)
            {
                txtResult.Text += string.Format("現在是第{0}次上場打擊\n", totalClick);
                if (isHitted)
                {
                    txtResult.Text += string.Format("打中了,仰角是{0},距離是{1}\n", ballEventArgs.Angle, ballEventArgs.Distance);
                    ball.OnBallInPlay(ballEventArgs);
                    foreach (var v in Role)
                    {
                        txtResult.Text += v.Name + "\n";
                        txtResult.Text += v.Message;
                    }
                }
                else
                {
                    txtResult.Text += string.Format("沒打中了,你還有{0}次機會\n", 3 - totalClick);
                }
            }
            else
            {
                MessageBox.Show("Gameover");
            }
        }
예제 #20
0
 public void OnBallInPlay(BallEventArgs ballEventArgs)
 {
     this.ballEventArgs.Angle = ballEventArgs.Angle;
     this.ballEventArgs.Distance = ballEventArgs.Distance;
     BallInPlay(this, this.ballEventArgs);
 }
예제 #21
0
 protected void OnBallInPlay(BallEventArgs e)
 {
     EventHandler<BallEventArgs> ballInPlay = BallInPlay;
     if (ballInPlay != null)
         ballInPlay(this, e);
 }
예제 #22
0
 private void Ball_BallInPlayTest(object sender, BallEventArgs e)
 {
     this.Said("[BallInPlayTest]");
 }
 public void PlayBall()
 {
     BallEventArgs ballEventArgs = new BallEventArgs(Trajectory, Distance);
     ball.OnBallInPlay(ballEventArgs);
 }
예제 #24
0
        public void PlayBall()
        {
            BallEventArgs ballEventArgs = new BallEventArgs(Trajectory, Distance);

            ball.OnBallInPlay(ballEventArgs);
        }
예제 #25
0
 private void playBallButton_Click(object sender, EventArgs e)
 {
     BallEventArgs ballEventArgs = new BallEventArgs(
         (int)trajectory.Value, (int)distance.Value);
     ball.OnBallInPlay(ballEventArgs);
 }