static void Main(string[] args) { var running = true; while (running) { Console.Write("Enter a number for the angle (or anything else to quit): "); if (int.TryParse(Console.ReadLine(), out int angle)) { Console.Write("Enter a number for the distance (or anything else to quit): "); if (int.TryParse(Console.ReadLine(), out int distance)) { BallEventArgs ballEventArgs = new BallEventArgs(angle, distance); ball.OnBallInPlay(ballEventArgs); } else { running = false; } } else { running = false; } } Console.WriteLine("Thanks for playing!"); }
public void OnBallInPlay(BallEventArgs e) { EventHandler ballInPlay = BallInPlay; if (ballInPlay != null) { ballInPlay(this, e); } }
void BallInPlayEventHandler(object sender, BallEventArgs e) { pitchNumber++; if ((e.Distance < 95) && (e.Angle < 60)) { Console.WriteLine($"Pitch #{pitchNumber}: I caught the ball"); } else { Console.WriteLine($"Pitch #{pitchNumber}: I covered first base"); } }
void ball_BallInPlay(object sender, EventArgs e) { pitchNumber++; if (e is BallEventArgs) { BallEventArgs ballEventArgs = e as BallEventArgs; if ((ballEventArgs.Distance < 95) && (ballEventArgs.Trajectory < 60)) { CatchBall(); } else { CoverFirstBase(); } } }
void ball_BallInPlay(object sender, EventArgs e) { pitchNumber++; if (e is BallEventArgs) { BallEventArgs ballEventArgs = e as BallEventArgs; if (ballEventArgs.Distance > 400 && ballEventArgs.Trajectory > 30) { FanSays.Add("Pitch #" + pitchNumber + ": Home run! I'm going for the ball!"); } else { FanSays.Add("Pitch #" + pitchNumber + ": Woo-hoo! Yeah!"); } } }
protected void OnBallInPlay(BallEventArgs e) => BallInPlay?.Invoke(this, e);
public void OnBallInPlay(BallEventArgs e) { EventHandler ballInPlay = BallInPlay; if (ballInPlay != null) ballInPlay(this, e); }
public void PlayBall() { BallEventArgs ballEventArgs = new BallEventArgs(Trajectory, Distance); ball.OnBallInPlay(ballEventArgs); }
public void OnBallInPlay(BallEventArgs e) => BallInPlay?.Invoke(this, e);
public void PlayBall() { BallEventArgs ballEventArgs = new BallEventArgs(Trajectory, Distance); ball.OnBallInPlay(ballEventArgs); }