Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <time.h>
- #include <cstdlib>
- #include <limits>
- #include <sstream>
- using namespace std;
- class Horse
- {
- private:
- int position;
- public:
- Horse();
- void advance();
- int getPosition();
- };
- class Race
- {
- private:
- int length;
- Horse h[5];
- public:
- Race();
- Race(int length);
- void printLane(int horseNum);
- void start();
- };
- Horse::Horse()
- {
- Horse::position = 0;
- }
- void Horse::advance()
- {
- int moveHorse = rand() % 2;
- if (moveHorse == 1)
- {
- position++;
- }
- }
- int Horse::getPosition()
- {
- return position;
- }
- Race::Race()
- {
- int length = 10;
- }
- Race::Race(int length)
- {
- length = length;
- }
- void Race::printLane(int horseNum)
- {
- int trackPosition = h[horseNum].getPosition();
- for (int j = 0; j < 10; j++)
- {
- if (j == h[horseNum].getPosition())
- {
- cout << horseNum << " ";
- }
- else
- {
- cout << ". ";
- }
- }
- cout << endl;
- }
- void Race::start()
- {
- bool keepGoing = true;
- while (keepGoing == true)
- {
- for (int i = 0; i < 5; i++)
- {
- if (h[i].getPosition() == (9))
- {
- printLane(i);
- keepGoing = false;
- cout << "Horse " << horseNum << " won!" << endl;
- }
- else
- {
- printLane(i);
- }
- cout << endl;
- }
- for (int j = 0; j <= 5; j++)
- {
- h[j].advance();
- }
- cout << endl << "Press any key to continue" << endl;
- cin.ignore();
- }
- }
- int main()
- {
- srand(time(NULL));
- Race test;
- test.start();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement