コード例 #1
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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Start");
            Ball ball  = new Ball();
            Ball ball2 = new Ball();
            Bat  bat   = ball.GetNewBat();

            bat = ball.GetNewBat();

            Pitcher       pitcher       = new Pitcher(ball);
            Catcher       cathcer       = new Catcher(ball);
            Batter        batter        = new Batter(ball);
            FirstBaseman  firstBaseman  = new FirstBaseman(ball);
            SecondBaseman secondBaseman = new SecondBaseman(ball);
            ThirdBaseman  thirdBaseman  = new ThirdBaseman(ball);
            Fan           energeticFan  = new Fan(ball);
            Umpire        goodUmpire    = new Umpire(ball);


            bat.HitTheBall(new BallEventArgs(50, 80));
            bat.HitTheBall(new BallEventArgs(50, 80));
            //int[][] parmas = new int[][];
            ball.OnBallInPlayTest(new BallEventArgs(50, 80));
            bat.HitTheBall(new BallEventArgs(40, 200));
            bat.HitTheBall(new BallEventArgs(40, 200));
            Console.WriteLine();
            bat.HitTheBall(new BallEventArgs(40, 200));


            //Add listener many times:
            goodUmpire.StartLookingAtBall(ball);
            goodUmpire.StartLookingAtBall(ball);
            bat.HitTheBall(new BallEventArgs(30, 910));

            Console.WriteLine();
            goodUmpire.StopLookingAtBall();
            bat.HitTheBall(new BallEventArgs(30, 910));
            goodUmpire.StopLookingAtBall();
            goodUmpire.StopLookingAtBall();

            Console.WriteLine();

            bat.HitTheBall(new BallEventArgs(50, 80));
            Console.WriteLine();

            goodUmpire.StartWaitgingForHit(bat);
            goodUmpire.StartWaitgingForHit(bat);
            bat.HitTheBall(new BallEventArgs(50, 80));

            bat.HitTheBall(new BallEventArgs(50, 80));


            Console.ReadKey();
        }