Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int findTile(char pchoice)
- {
- const int tiles = 26;
- if(pchoice == '_')
- return -1;
- for(int i = 0; i < tiles; i++)
- if(playerTiles[i] == pchoice)
- return i;
- return -1;
- }
- void decrementTile(int index)
- {
- playerTiles[index].tilesLeft -= 1;
- if(playerTiles[index].tilesLeft == 0)
- playerTiles[index].tiles = '_';
- }
- void printTile(int index)
- {
- cout.put(playerTiles[index].tiles);
- if(playerTiles[index].tilesLeft > 1)
- cout << "(" << playerTiles[index].tilesLeft << ")";
- }
- void printChoices()
- {
- cout << "Select one of:";
- const int tiles = 26;
- for(int i = 0; i < tiles; i++)
- if(playerTiles[i].tilesLeft > 0)
- (cout << " ").put(playerTiles[i].tiles);
- cout << endl;
- }
- char askUser()
- {
- string choice;
- cout >> choice;
- return choice[0];
- }
- int userPick()
- {
- for(;;) {
- char selection = askUser();
- int index = findTile(selection);
- if(index < 0)
- printChoices();
- else
- return index;
- }
- }
- void gameIteration()
- {
- int index = userPick();
- printTile(index);
- decrementTile(index);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement