Horse.cpp 445 B

12345678910111213141516171819202122232425262728293031323334
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdlib>
  4. #include <time.h>
  5. #include "Horse.h"
  6. Horse::Horse(){
  7. position = 0;
  8. isRacing = true;
  9. }
  10. int Horse::getPosition(){
  11. return position;
  12. }
  13. // flips a coin, advances ~50% of times
  14. void Horse::advance(){
  15. if (rand() % 2){ // either 0 or 1
  16. position++;
  17. }
  18. }
  19. bool Horse::getRacing(){
  20. return isRacing;
  21. }
  22. void Horse::race(){
  23. isRacing = true;
  24. }
  25. void Horse::dontRace(){
  26. isRacing = false;
  27. }