Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. using namespace std;
  5.  
  6. struct Word
  7. {
  8. char word[8];
  9. int count;
  10. };
  11. void PrintDashes(int,char);
  12. void AddingWords();
  13. void NewGame();
  14. void GameSettings();
  15. Word words[10];
  16. int chances = 3;
  17. int wordCount = 5;
  18.  
  19. int main()
  20. {
  21. AddingWords();
  22. while (true)
  23. {
  24. int command = 0;
  25. cout << "Press '1' for starting new game " << endl;
  26. cout << "Press '2' for settings " << endl;
  27. cout << "Press '3' for exit " << endl;
  28. cin >> command;
  29.  
  30. if (command==1)
  31. {
  32.  
  33. NewGame();
  34.  
  35. }
  36. else if (command == 2)
  37. {
  38. cout << "Settings"<<endl;
  39. PrintDashes(20,'-');
  40. int settingCommand = 0;
  41.  
  42. cout << "Press '1' for changing the word count"<<endl;
  43. cout << "Press '2' for changing chances count" << endl;
  44. cin >> settingCommand;
  45.  
  46. if (settingCommand==1)
  47. {
  48. cout << "The current word count is "<<wordCount<<endl;
  49. cout << "Enter how much you want to make the word cout(word count must be between 3 and 7)"<<endl;
  50. cin >> wordCount;
  51.  
  52. cout << "The word count was changed to "<<wordCount<<endl;
  53. }
  54. else if (settingCommand == 2)
  55. {
  56. cout << "The current chances count is " << wordCount << endl;
  57. cout << "Enter how much you want to make chances cout(chances count must be between 3 and 7)" << endl;
  58. cin >> chances;
  59.  
  60. cout << "Chances count was changed to " << wordCount << endl;
  61. }
  62. }
  63. else if (command == 3)
  64. {
  65. return 0;
  66. }
  67.  
  68.  
  69. }
  70. }
  71.  
  72. void PrintDashes(int n,char l)
  73. {
  74. for (int i = 0; i < n; i++)
  75. {
  76. cout << l;
  77. }
  78. cout << endl;
  79. }
  80.  
  81. void NewGame()
  82. {
  83. srand(time(NULL));
  84. int randNum = rand() % 10;
  85. int wordCount = words[randNum].count;
  86. char tempChar[8];
  87. int chancesForGame = chances;
  88. for (int i = 0; i < wordCount; i++)
  89. {
  90. tempChar[i] = '_';
  91. }
  92. tempChar[wordCount] = '\0';
  93.  
  94. while (true)
  95. {
  96. PrintDashes(20,'=');
  97. cout << "The word is: ";
  98. cout << tempChar<<endl;
  99. PrintDashes(20, '=');
  100.  
  101. char letter;
  102. cout << "Enter letter which you think can contain the word" << endl;
  103. cin >> letter;
  104.  
  105. int findedLetters = 0;
  106.  
  107. for (int i = 0; i < wordCount; i++)
  108. {
  109. if (words[randNum].word[i] == letter)
  110. {
  111. tempChar[i] = words[randNum].word[i];
  112. findedLetters++;
  113. }
  114. }
  115. if (findedLetters == 0)
  116. {
  117. PrintDashes(30, '-');
  118. cout << "The letter '" << letter << "' don't exist in the given word"<<endl;
  119. chancesForGame--;
  120. if (chancesForGame==0)
  121. {
  122. cout << "GAME OVER! You couldn't guess the word!"<<endl;
  123. cout << "The word is '"<< words[randNum].word<<"'"<<endl;
  124. PrintDashes(30, '-');
  125. break;
  126. }
  127. PrintDashes(30, '-');
  128. }
  129. else
  130. {
  131. PrintDashes(30, '-');
  132. cout << "The word contains the letter '" << letter << "' " << findedLetters << " times" << endl;
  133. PrintDashes(30, '-');
  134. }
  135. }
  136. }
  137. void AddingWords()
  138. {
  139. words[0] = { "dog",3 };
  140. words[1] = { "flower",6 };
  141. words[2] = { "world",5 };
  142.  
  143. words[3] = { "sun",3 };
  144. words[4] = { "family",6 };
  145. words[5] = { "women",5 };
  146. words[6] = { "varna",5 };
  147. words[7] = { "earth",5 };
  148.  
  149. words[8] = { "beach",5 };
  150. words[9] = { "request",7 };
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement