Advertisement
Guest User

Untitled

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