Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <iostream>
- #include <ctime>
- class AI {
- public:
- AI() {}
- ~AI() {}
- int choice() { return (((rand() & (RAND_MAX - RAND_MIN))) + RAND_MIN)); }
- void checkMoves(int usrChoice) {
- switch (usrChoice) {
- case 1:
- if (choice() == 1)
- cout << "Computer chooses rock.\r\nDraw." << endl;
- else if (choice() == 2)
- cout << "Computer choose paper.\r\nYou lose." << endl;
- else if (choice() == 3)
- cout << "Computer chooses scissors.\r\nYou win." << endl;
- break;
- case 2:
- if (choice() == 1)
- cout << "Computer chooses rock.\r\nYou win." << endl;
- else if (choice() == 2)
- cout << "Computer choose paper.\r\nDraw." << endl;
- else if (choice() == 3)
- cout << "Computer chooses scissors.\r\nYou lose." << endl;
- break;
- case 3:
- if (choice() == 1)
- cout << "Computer chooses rock.\r\nYou lose." << endl;
- else if (choice() == 2)
- cout << "Computer choose paper.\r\nYou win." << endl;
- else if (choice() == 3)
- cout << "Computer chooses scissors.\r\nDraw." << endl;
- break;
- default:
- cout << "Error: " << choice() << endl;
- break;
- }
- Sleep(500);
- system("cls");
- }
- };
- void game(AI ai);
- int main() {
- SetConsoleTitle("Rock Paper Scissors");
- AI ai;
- game(ai);
- }
- void game(AI ai) {
- int usrChoice(0);
- while (usrChoice != 0) {
- srand(time(0));
- cout << "Available moves:\r\n1.) Rock\r\n2.) Paper\r\n3.) Scissors\r\n0.) Exit\r\nYour choice: "
- cin >> usrChoice;
- ai.checkMoves(usrChoice);
- }
- }
Add Comment
Please, Sign In to add comment