Guest User

Untitled

a guest
Jan 23rd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. #include <windows.h>
  2. #include <iostream>
  3. #include <ctime>
  4.  
  5. class AI {
  6. public:
  7. AI() {}
  8. ~AI() {}
  9.  
  10. int choice() { return (((rand() & (RAND_MAX - RAND_MIN))) + RAND_MIN)); }
  11.  
  12. void checkMoves(int usrChoice) {
  13. switch (usrChoice) {
  14. case 1:
  15. if (choice() == 1)
  16. cout << "Computer chooses rock.\r\nDraw." << endl;
  17. else if (choice() == 2)
  18. cout << "Computer choose paper.\r\nYou lose." << endl;
  19. else if (choice() == 3)
  20. cout << "Computer chooses scissors.\r\nYou win." << endl;
  21. break;
  22.  
  23. case 2:
  24. if (choice() == 1)
  25. cout << "Computer chooses rock.\r\nYou win." << endl;
  26. else if (choice() == 2)
  27. cout << "Computer choose paper.\r\nDraw." << endl;
  28. else if (choice() == 3)
  29. cout << "Computer chooses scissors.\r\nYou lose." << endl;
  30. break;
  31.  
  32. case 3:
  33. if (choice() == 1)
  34. cout << "Computer chooses rock.\r\nYou lose." << endl;
  35. else if (choice() == 2)
  36. cout << "Computer choose paper.\r\nYou win." << endl;
  37. else if (choice() == 3)
  38. cout << "Computer chooses scissors.\r\nDraw." << endl;
  39. break;
  40.  
  41. default:
  42. cout << "Error: " << choice() << endl;
  43. break;
  44. }
  45.  
  46. Sleep(500);
  47. system("cls");
  48. }
  49. };
  50.  
  51. void game(AI ai);
  52.  
  53. int main() {
  54. SetConsoleTitle("Rock Paper Scissors");
  55. AI ai;
  56. game(ai);
  57. }
  58.  
  59. void game(AI ai) {
  60. int usrChoice(0);
  61.  
  62. while (usrChoice != 0) {
  63. srand(time(0));
  64.  
  65. cout << "Available moves:\r\n1.) Rock\r\n2.) Paper\r\n3.) Scissors\r\n0.) Exit\r\nYour choice: "
  66. cin >> usrChoice;
  67.  
  68. ai.checkMoves(usrChoice);
  69. }
  70. }
Add Comment
Please, Sign In to add comment