Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. int rock = 1, scissor = 2, paper = 3, player, computer = 0, playerScore = 0, computerScore = 0, rounds = 1;
  7. char again = 'n';
  8. cout << "1 for rock, 2 for scissor, 3 for paper" << endl;
  9. do {
  10. playerScore = 0; computerScore = 0; rounds = 1;
  11. while (rounds <= 7 && playerScore < 4 && computerScore < 4) {
  12. cout << endl << "round " << rounds << ":" << endl;
  13. rounds++;
  14. cout << "Your move:";
  15. cin >> player;
  16.  
  17. //Check invaild input
  18. while (player < 1 || player > 3) {
  19. cout << "Invalid move!, Please input 1 for rock, 2 for scissor, 3 for paper" << endl;
  20. cin >> player;
  21. }
  22.  
  23. //........Cheating code..........
  24. if (playerScore < 3) {
  25. computer = rand() % 3;
  26. }
  27.  
  28. else {
  29. computerScore++;
  30. if (player == 1) {
  31. computer = 3;
  32.  
  33. }
  34. else if (player == 3) {
  35. computer = 2;
  36.  
  37. }
  38. else if (player == 2) {
  39. computer = 1;
  40.  
  41. }
  42. cout << "Computer's move: " << computer << endl;
  43. cout << "YOU LOSE!" << endl;
  44. cout << "player score " << playerScore << endl;
  45. cout << "computer score " << computerScore << endl;
  46. }
  47.  
  48. //...........Regular run............
  49. if (playerScore < 3) {
  50. cout << "Computer's move:" << computer << endl;
  51.  
  52. //Check who won
  53. //show Computer won
  54. if (player == 1 && computer == 3) {
  55. computerScore++;
  56. cout << "YOU LOSE!!" << endl;
  57. cout << "player score: " << playerScore << endl;
  58. cout << "computer score: " << computerScore << endl;
  59. }
  60. //show player Won
  61. else if (player == 1 && computer == 2)
  62. {
  63. playerScore++;
  64. cout << "YOU WON!" << endl;
  65. cout << "player score: " << playerScore << endl;
  66. cout << "computer score: " << computerScore << endl;
  67. }
  68.  
  69. else if (player == 2 && computer == 3)
  70. {
  71. playerScore++;
  72. cout << "YOU WON!" << endl;
  73. cout << "player score: " << playerScore << endl;
  74. cout << "computer score: " << computerScore << endl;
  75. }
  76. else if (player == 2 && computer == 1)
  77. {
  78. computerScore++;
  79. cout << "YOU LOSE!" << endl;
  80. cout << "player score: " << playerScore << endl;
  81. cout << "computer score: " << computerScore << endl;
  82. }
  83. else if (player == 3 && computer == 2)
  84. {
  85. computerScore++;
  86. cout << "YOU LOSE!" << endl;
  87. cout << "player score: " << playerScore << endl;
  88. cout << "computer score: " << computerScore << endl;
  89. }
  90. else if (player == 3 && computer == 1)
  91. {
  92. playerScore++;
  93. cout << "YOU WON!" << endl;
  94. cout << "player score: " << playerScore << endl;
  95. cout << "computer score: " << computerScore << endl;
  96. }
  97. else {
  98. rounds--;
  99. cout << "Tie" << endl;
  100. cout << "player score: " << playerScore << endl;
  101. cout << "computer score: " << computerScore << endl;
  102. }
  103. }
  104. }
  105.  
  106. //......Again........
  107. if (computerScore == 4) {
  108. cout << "!!! GAME OVER !!!" << endl;
  109. cout << "I WIN!" << endl;
  110. cout << "YOU LOSE! Ha Ha!" << endl;
  111.  
  112. }
  113. cout << "Want to try again?(Y/N)" << endl;
  114. cin >> again;
  115.  
  116. //........Play again???........
  117. } while (toupper(again) == 'Y');
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement