Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. void RockPaperScissors()
  2. { //game is running.
  3. int gameisRunning;
  4. gameisRunning = true;
  5. char ch;
  6. // setting variables for the scores, and turns.
  7. int player_win_tally= 0;
  8. int draw = 0;
  9. int comp_win_tally = 0;
  10. int playTurn = 5;
  11. int Turnfinish = 5;
  12. // start of the game loop, the loop will be running until ch == n
  13. for (int i = 0; i < playTurn; i++) {
  14. if (gameisRunning == true) {
  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) || i != 4) {
  23. std::cout << "Press R for Rock, P for Paper, S for Scissors:" << std::endl;
  24. playTurn++;
  25. std::cin >> choice;
  26.  
  27. std::cout << "The computer has chosen: " << CPUChoices << std::endl;
  28. //starting the sequence where 9 possible outcomes can happen.
  29. if (choice == 'R' && CPUChoices == "R") {
  30. std::cout << "Rock meets rock, it is a draw." << std::endl;
  31. draw++;
  32. } else if (choice == 'R' && CPUChoices == "P") {
  33. std::cout << "Rock has been covered by paper, computer wins." << std::endl;;
  34. comp_win_tally++;
  35. } else if (choice == 'R' && CPUChoices == "S") {
  36. std::cout << "Rock beats scissors, player wins." << std::endl;;
  37. player_win_tally++;
  38. } else if (choice == 'P' && CPUChoices == "R") {
  39. std::cout << "Paper covers rock, player wins." << std::endl;
  40. player_win_tally++;
  41. } else if (choice == 'P' && CPUChoices == "P") {
  42. std::cout << "Paper meets paper, it is a draw." << std::endl;
  43. draw++;
  44. } else if (choice == 'P' && CPUChoices == "S") {
  45. std::cout << "Paper has been cut by Scissors, computer wins." << std::endl;;
  46. comp_win_tally++;
  47. } else if (choice == 'S' && CPUChoices == "R") {
  48. std::cout << "Scissors have been crushed by the rock, computer wins." << std::endl;
  49. comp_win_tally++;
  50. } else if (choice == 'S' && CPUChoices == "P") {
  51. std::cout << "Scissors cuts paper, player wins." << std::endl;
  52. player_win_tally++;
  53. } else if (choice == 'S' && CPUChoices == "S") {
  54. std::cout << "Scissors meets scissors, it is a draw." << std::endl;
  55. draw++;
  56. } else {
  57. std::cout << "Player has not selected R, P, and S." << std::endl;
  58. }
  59. if (i == 4) {
  60. std::cout << "Player:" << player_win_tally << std::endl;
  61. ;std::cout << "Draws:" << draw << std::endl;
  62. std::cout << "CPU:" << comp_win_tally << std::endl;
  63. return;
  64. }
  65. }
  66. inFile.close(); // close file after, playing a game of RPS.
  67. }
  68. }
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement