-
-
Save anonymous/7c24f93d0bc9e0518c7e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Player { | |
private: | |
int _position = 0; | |
public: | |
int position() const { return _position; } | |
void setPosition( int position ) { _position = position; } | |
}; | |
static const int MAX_SPACES = 32; | |
int* g_board = new int[ MAX_SPACES ]; | |
// Returns a random number between 0 and 6 | |
int rollDice() { | |
return rand() % 7; | |
} | |
void takeTurn( Player& player ) { | |
int roll = rollDice(); | |
// Might want to check here for any sort of round the board | |
// events (additional money when they complete a lap?) | |
int position = player.position() + roll % MAX_SPACES; | |
player.setPosition( position ); | |
} | |
int main( int argc, const char* const argv[] ) { | |
Player p1; | |
takeTurn(p1); | |
std::cout << "Player is at " << p1.position() << std::endl; | |
takeTurn(p1); | |
std::cout << "Player is at " << p1.position() << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment