bekovski

p13

Feb 6th, 2018
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. /************************************************************************/
  2.     // Task 13.2a: Complete this class so that it correctly returns
  3.     // Checks if the moon is closer or further away from the specified distance
  4.     /************************************************************************/
  5.     class MoonCondition : public Condition {
  6.     public:
  7.        
  8.         State state;
  9.  
  10.         /**
  11.          * Performs the test for this condition.
  12.          */
  13.         virtual bool test() {
  14.             if (state == Wandering && moon->Position.distance(earth->Position) < 1) {
  15.                 return true;
  16.             }
  17.  
  18.             if (state == Following && moon->Position.distance(earth->Position) > 1) {
  19.                 return true;
  20.             }
  21.  
  22.             return false;
  23.         }
  24.     };
  25.  
  26.  
  27. /************************************************************************/
  28.         // Task 13.2b: After you have completed the MoonCondition object, instantiate it here
  29.         /************************************************************************/
  30.  
  31.         MoonCondition* ShouldFollow = new MoonCondition();
  32.         ShouldFollow->state = Wandering;
  33.         // This condition should trigger if the moon is closer than 1 unit to the Earth
  34.        
  35.         MoonCondition* ShouldWander = new MoonCondition();
  36.         ShouldWander->state = Following;
  37.         // This condition should trigger if the moon is further away than 1 unit from the Earth
Advertisement
Add Comment
Please, Sign In to add comment