Skip to content

Instantly share code, notes, and snippets.

Created December 2, 2013 02:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/7c24f93d0bc9e0518c7e to your computer and use it in GitHub Desktop.
Save anonymous/7c24f93d0bc9e0518c7e to your computer and use it in GitHub Desktop.
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