Horse Racing (3)

  1. Modify your horse racing homework and implement it with a class CHorse.
  2. Each horse has two (private) data members x and y.
  3. The class CHorse has a static (P.397) public data member: m_count. It is used to count the number of horses on the screen. So you'll need to increment it in your constructor (as in Ex7_12.cpp).
  4. Define the following member functions:
    1. CHorse() - constructor
      • If the constructor is invoked with no argument, the horse will be randomly placed in a track (suppose we have 8 tracks).
      • If a track number is specified in the argument, place the horse in this track.
        • If the number is larger than 8, you should substract 8 from it.
        • For example, if the argument is 9, you should place the horse in track 1.
        • If the argument is 24, you should place the horse in track 8.
      • A newly created horse will always be placed at the starting position of the track, which is defined as a constant START in the program.
    2. Show()
      • Display a horse according to its x,y value.
      • When a horse is approaching the final destination, change its color to red to indicate that it is sprinting.
    3. Hide()
      • Erase a horse from its current position.
    4. Forward()
      • Increase x if horses are running to the right;
        decrease x if horses are running to the left.
    5. Final() - a Boolean function which determined whether this horse reaches the final destination.
  5. Save your definition about the class CHorse in a file "horse.h". Test it with a main program which creates horses sequentially from 1 to 8. Save it as "horse-1.cpp" in the same directory. Compile the program by "g++ horse-1.cpp -lcurses". The program may run as follows.
    Horses Created Sequentially
  6. Test it with another main program which creates horses randomly between 1 and 8. Save the main program as "horse-2.cpp" in the same directory. Compile the program by "g++ horse-2.cpp -lcurses". The program may run as follows.
    Horses Created Randomly
  7. Now play it with this main program which is more similar to a horse racing game. Save the main program as "horse-5.cpp" in the same directory. Compile the program by "g++ horse-5.cpp -lcurses". The program may run as follows.
    Horse Racing