Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int rock = 1, scissor = 2, paper = 3, player, computer = 0, playerScore = 0, computerScore = 0, rounds = 1;
- char again = 'n';
- cout << "1 for rock, 2 for scissor, 3 for paper" << endl;
- do {
- playerScore = 0; computerScore = 0; rounds = 1;
- while (rounds <= 7 && playerScore < 4 && computerScore < 4) {
- cout << endl << "round " << rounds << ":" << endl;
- rounds++;
- cout << "Your move:";
- cin >> player;
- //Check invaild input
- while (player < 1 || player > 3) {
- cout << "Invalid move!, Please input 1 for rock, 2 for scissor, 3 for paper" << endl;
- cin >> player;
- }
- //........Cheating code..........
- if (playerScore < 3) {
- computer = rand() % 3;
- }
- else {
- computerScore++;
- if (player == 1) {
- computer = 3;
- }
- else if (player == 3) {
- computer = 2;
- }
- else if (player == 2) {
- computer = 1;
- }
- cout << "Computer's move: " << computer << endl;
- cout << "YOU LOSE!" << endl;
- cout << "player score " << playerScore << endl;
- cout << "computer score " << computerScore << endl;
- }
- //...........Regular run............
- if (playerScore < 3) {
- cout << "Computer's move:" << computer << endl;
- //Check who won
- //show Computer won
- if (player == 1 && computer == 3) {
- computerScore++;
- cout << "YOU LOSE!!" << endl;
- cout << "player score: " << playerScore << endl;
- cout << "computer score: " << computerScore << endl;
- }
- //show player Won
- else if (player == 1 && computer == 2)
- {
- playerScore++;
- cout << "YOU WON!" << endl;
- cout << "player score: " << playerScore << endl;
- cout << "computer score: " << computerScore << endl;
- }
- else if (player == 2 && computer == 3)
- {
- playerScore++;
- cout << "YOU WON!" << endl;
- cout << "player score: " << playerScore << endl;
- cout << "computer score: " << computerScore << endl;
- }
- else if (player == 2 && computer == 1)
- {
- computerScore++;
- cout << "YOU LOSE!" << endl;
- cout << "player score: " << playerScore << endl;
- cout << "computer score: " << computerScore << endl;
- }
- else if (player == 3 && computer == 2)
- {
- computerScore++;
- cout << "YOU LOSE!" << endl;
- cout << "player score: " << playerScore << endl;
- cout << "computer score: " << computerScore << endl;
- }
- else if (player == 3 && computer == 1)
- {
- playerScore++;
- cout << "YOU WON!" << endl;
- cout << "player score: " << playerScore << endl;
- cout << "computer score: " << computerScore << endl;
- }
- else {
- rounds--;
- cout << "Tie" << endl;
- cout << "player score: " << playerScore << endl;
- cout << "computer score: " << computerScore << endl;
- }
- }
- }
- //......Again........
- if (computerScore == 4) {
- cout << "!!! GAME OVER !!!" << endl;
- cout << "I WIN!" << endl;
- cout << "YOU LOSE! Ha Ha!" << endl;
- }
- cout << "Want to try again?(Y/N)" << endl;
- cin >> again;
- //........Play again???........
- } while (toupper(again) == 'Y');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement