Advertisement
homer512

Nerissa's question

Apr 2nd, 2014
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. int findTile(char pchoice)
  2. {
  3.   const int tiles = 26;
  4.   if(pchoice == '_')
  5.     return -1;
  6.   for(int i = 0; i < tiles; i++)
  7.     if(playerTiles[i] == pchoice)
  8.       return i;
  9.   return -1;
  10. }
  11.  
  12. void decrementTile(int index)
  13. {
  14.   playerTiles[index].tilesLeft -= 1;
  15.   if(playerTiles[index].tilesLeft == 0)
  16.     playerTiles[index].tiles = '_';
  17. }
  18.  
  19. void printTile(int index)
  20. {
  21.   cout.put(playerTiles[index].tiles);
  22.   if(playerTiles[index].tilesLeft > 1)
  23.     cout << "(" << playerTiles[index].tilesLeft << ")";
  24. }
  25.  
  26. void printChoices()
  27. {
  28.   cout << "Select one of:";
  29.   const int tiles = 26;
  30.   for(int i = 0; i < tiles; i++)
  31.     if(playerTiles[i].tilesLeft > 0)
  32.       (cout << " ").put(playerTiles[i].tiles);
  33.   cout << endl;
  34. }
  35.  
  36. char askUser()
  37. {
  38.   string choice;
  39.   cout >> choice;
  40.   return choice[0];
  41. }
  42.  
  43. int userPick()
  44. {
  45.   for(;;) {
  46.     char selection = askUser();
  47.     int index = findTile(selection);
  48.     if(index < 0)
  49.       printChoices();
  50.     else
  51.       return index;
  52.   }
  53. }
  54.  
  55. void gameIteration()
  56. {
  57.   int index = userPick();
  58.   printTile(index);
  59.   decrementTile(index);
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement