home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 11 Learning / 04 Mommersteeg / Tennis / Observer.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-09-23  |  1.9 KB  |  55 lines

  1. //----------------------------------------------------------------------------------------------
  2. // Sequential Prediction Demo: The positioning pattern
  3. // 
  4. // Author:  Fri Mommersteeg
  5. // Date:    10-09-2001
  6. // File:    Observer.h
  7. //----------------------------------------------------------------------------------------------
  8.  
  9. #ifndef __OBSERVER_H
  10. #define __OBSERVER_H
  11.  
  12. //----------------------------------------------------------------------------------------------
  13. // Include files
  14. //----------------------------------------------------------------------------------------------
  15.  
  16. #include "array.h"
  17.  
  18. //----------------------------------------------------------------------------------------------
  19. // Event list of messages sent by subjects
  20. //----------------------------------------------------------------------------------------------
  21.  
  22. #define HIT_GROUND_EVENT    1
  23. #define HIT_BALL_EVENT        2
  24. #define BALL_ROLLING_EVENT    3
  25.  
  26. //----------------------------------------------------------------------------------------------
  27. // CObserver: an observer can receive notifications from subjects
  28. //----------------------------------------------------------------------------------------------
  29.  
  30. class CObserver {
  31. public:
  32.     virtual BOOL        Notify(int msg, DWORD param) = 0;
  33. };
  34.  
  35. //----------------------------------------------------------------------------------------------
  36. // CSubject: a subject maintains a list of registered observers, and notifies them of events
  37. //----------------------------------------------------------------------------------------------
  38.  
  39. class CSubject {
  40.  
  41. public:
  42.     void        RegisterObserver(CObserver * pObserver); 
  43.     void        UnregisterObserver(CObserver * pObserver);
  44.     BOOL        NotifyAll(int msg, DWORD param = 0);
  45.  
  46. protected:
  47.     CArray <CObserver*>    observers;
  48. };
  49.  
  50. //----------------------------------------------------------------------------------------------
  51. #endif // __OBSERVER_H
  52.  
  53.  
  54.  
  55.