Advertisement
Dennisaa

BallGame.cs - BallGame

Sep 19th, 2015
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApplication2 {
  4.    
  5.     public class BallGame {
  6.         public event EventHandler<BallHitEventArgs> BallHit;
  7.         public event EventHandler GameOver;
  8.  
  9.         public void HitBall(int mph, int compassDirection) {
  10.             Console.WriteLine("[PUBLISHER:] I have just the ball [{0} mph] [compass direction:{1}]", mph, compassDirection);
  11.             OnBallHit(mph, compassDirection);
  12.             Console.WriteLine("[PUBLISHER:] I am telling you this game is over");
  13.             OnGameOver();
  14.  
  15.  
  16.         }
  17.  
  18.         private void OnBallHit(int mph, int compassDirection) {
  19.             if (BallHit != null) {
  20.                 BallHit(this, new BallHitEventArgs(mph, compassDirection));
  21.             }
  22.         }
  23.  
  24.         private void OnGameOver() {
  25.             if (GameOver != null) {
  26.                 GameOver(this, EventArgs.Empty);
  27.             }
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement