Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. void RockPaperScissors()
  2. {
  3. //game is running.
  4. bool gameisRunning;
  5. gameisRunning = true;
  6. char ch;
  7. // setting variables for the scores, and turns.
  8. int player_score = 0;
  9. int playTurn = 0;
  10. // start of the game loop, the loop will be running until ch == n
  11. for (int i = 0; i < playTurn; i++)
  12. {
  13. if (gameisRunning == true)
  14. {
  15. std::string CPUChoices;
  16. //opens RPS.txt, this will implement the Computer moves.
  17. std::ifstream inFile;
  18. inFile.open("RPS.txt");
  19. char choice;
  20. std::cout << "Welcome to Rock, Paper, Scissors!" << std::endl;
  21. //Asking the player to make a choice.
  22. while (std::getline(inFile, CPUChoices) && gameisRunning)
  23. {
  24. std::cout << "Press R for Rock, P for Paper, S for Scissors:" << std::endl;
  25. playTurn++;
  26. std::cin >> choice;
  27.  
  28. std::cout << "The computer has chosen: " << CPUChoices << std::endl;
  29. //starting the sequence where 9 possible outcomes can happen.
  30. if (choice == 'R' && CPUChoices == "R")
  31. {
  32. std::cout << "Rock meets rock, it is a draw." << std::endl;
  33. continue;
  34. }
  35. else if (choice == 'R' && CPUChoices == "P")
  36. {
  37. std::cout << "Rock has been covered by paper, computer wins." << std::endl;;
  38. player_score--;
  39. }
  40. else if (choice == 'R' && CPUChoices == "S")
  41. {
  42. std::cout << "Rock beats scissors, player wins." << std::endl;;
  43. player_score++;
  44. }
  45. else if (choice == 'P' && CPUChoices == "R")
  46. {
  47. std::cout << "Paper covers rock, player wins." << std::endl;
  48. player_score++;
  49. }
  50. else if (choice == 'P' && CPUChoices == "P")
  51. {
  52. std::cout << "Paper meets paper, it is a draw." << std::endl;
  53. continue;
  54. }
  55. else if (choice == 'P' && CPUChoices == "S")
  56. {
  57. std::cout << "Paper has been cut by Scissors, computer wins." << std::endl;;
  58. player_score--;
  59. }
  60. else if (choice == 'S' && CPUChoices == "R")
  61. {
  62. std::cout << "Scissors have been crushed by the rock, computer wins." << std::endl;
  63. player_score--;
  64. }
  65. else if (choice == 'S' && CPUChoices == "P")
  66. {
  67. std::cout << "Scissors cuts paper, player wins." << std::endl;
  68. player_score++;
  69. }
  70. else if (choice == 'S' && CPUChoices == "S")
  71. {
  72. std::cout << "Scissors meets scissors, it is a draw." << std::endl;
  73. continue;
  74. }
  75. else
  76. {
  77. std::cout << "Player has not selected R, P, or S." << std::endl;
  78. std::cout << "The game ends on behalf of the user not introducing R, P or S." << std::endl;
  79. return;
  80. }
  81. }
  82. }
  83. }
  84. if (player_score == 0) std::cout << "It's a draw";
  85. if (player_score > 0) std::cout << "Player wins by " << player_score;
  86. if (player_score < 0)
  87. {
  88. player_score = player_score * -1;
  89. std::cout << "Computer wins by " << player_score;
  90. }
  91. inFile.close(); // close file after, playing a game of RPS.
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement