Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using a loop asking the user if wants to play again Rock Paper Scissors Lizard Spock. #53

Open
car-mor opened this issue Oct 30, 2021 · 1 comment

Comments

@car-mor
Copy link

car-mor commented Oct 30, 2021

#include<iostream>
#include<cstdlib>
#include<time.h>

//logic of the program
/*Scissors cuts Paper.
Paper covers Rock.
Rock crushes Lizard.
Lizard poisons Spock.
Spock smashes Scissors.
Rock destroys Scissors.
Scissors decapitate Lizard.
Lizard eats Paper.
Paper disproves Spock.
Spock vaporizes Rock.
(and as it always has) Rock crushes Scissors.*/

int main() {
  int ch;
  do{
    std::cout<<"\n"<<"Would you like to continue to play?"<<"\n";
    std::cout<<"Type the number corresponding to your choice"<<"\n";
    std::cout<<"1. Yes"<<"\n";
    std::cout<<"2. No"<<"\n";
    std::cin>>ch;
    switch (ch) {

      case 1:{
        int computer = rand()%5 + 1;
        int user = 0;
        srand(time(NULL));
        std::cout << "====================================\n";
        std::cout << "rock paper scissors lizard spock!\n";
        std::cout << "====================================\n\n";

        std::cout << "1) ✊-Rock\n";
        std::cout << "2) ✋-Paper\n";
        std::cout << "3) ✌️-Scissors\n";
        std::cout << "4) 🦎-Lizard\n";
        std::cout << "5) 🖖-Spock\n";
        std::cout << "shoot!   \n";

        std::cin>>user;
        std::cout<<"Computer choice: "<<computer<<"\n";

        //logic rock with everything
        if (computer==1&&user==2) {
          std::cout<<"User has won!!"<<"\n";
          std::cout<<"Paper covers rock"<<"\n";
        }else if(computer==2&&user==1){
          std::cout<<"Computer has won!!"<<"\n";
          std::cout<<"Paper covers rock"<<"\n";
        }else if(computer==1&&user==3){
          std::cout<<"Computer has won!!"<<"\n";
          std::cout<<"Rock destroys scissors"<<"\n";
        }else if(computer==3&&user==1){
          std::cout<<"User has won!!"<<"\n";
          std::cout<<"Rock destroys scissors"<<"\n";
        }else if(computer==1&&user==4){
          std::cout<<"Computer has won!!"<<"\n";
          std::cout<<"Rock crushes lizard"<<"\n";
        }else if(computer==4&&user==1){
          std::cout<<"User has won!!"<<"\n";
          std::cout<<"Rock crushes lizard"<<"\n";
        }else if(computer==1&&user==5){
          std::cout<<"User has won!!"<<"\n";
          std::cout<<"Spock vaporizes rock"<<"\n";
        }else if(computer==5&&user==1){
          std::cout<<"Computer has won!!"<<"\n";
          std::cout<<"Spock vaporizes rock"<<"\n";
        }

        //logic paper with everything
        if (computer==2&&user==3) {
          std::cout<<"User has won!!"<<"\n";
          std::cout<<"Scissors cuts paper"<<"\n";
        }else if(computer==3&&user==2){
          std::cout<<"Computer has won!!"<<"\n";
          std::cout<<"Scissors cuts paper"<<"\n";
        }else if(computer==2&&user==4){
          std::cout<<"User has won!!"<<"\n";
          std::cout<<"Lizard eats paper"<<"\n";
        }else if(computer==4&&user==2){
          std::cout<<"Computer has won!!"<<"\n";
          std::cout<<"Lizard eats paper"<<"\n";
        }else if(computer==2&&user==5){
          std::cout<<"Computer has won!!"<<"\n";
          std::cout<<"Paper disproves Spock"<<"\n";
        }else if(computer==5&&user==2){
          std::cout<<"User has won!!"<<"\n";
          std::cout<<"Paper disproves Spock"<<"\n";
        }

        //logic scissors with everything
        if (computer==3&&user==4) {
          std::cout<<"Computer has won!!"<<"\n";
          std::cout<<"Scissors decapitate lizard"<<"\n";
        }else if(computer==4&&user==3){
          std::cout<<"User has won!!"<<"\n";
          std::cout<<"Scissors decapitate lizard"<<"\n";
        }else if(computer==3&&user==5){
          std::cout<<"User has won!!"<<"\n";
          std::cout<<"Spock smashes scissors"<<"\n";
        }else if(computer==5&&user==3){
          std::cout<<"Computer has won!!"<<"\n";
          std::cout<<"Spock smashes scissors"<<"\n";
        }

        //logic lizard with everything
        if (computer==4&&user==5) {
          std::cout<<"Computer has won!!"<<"\n";
          std::cout<<"Lizard poisons Spock"<<"\n";
        }else if(computer==5&&user==4){
          std::cout<<"User has won!!"<<"\n";
          std::cout<<"Lizard poisons Spock"<<"\n";
        }


        //ties
        if (computer==1&&user==1) {
          std::cout<<"Oops it's a tie!!"<<"\n";
        }else if(computer==2&&user==2){
          std::cout<<"Oops it's a tie!!"<<"\n";
        }else if(computer==3&&user==3){
          std::cout<<"Oops it's a tie!!"<<"\n";
        }else if(computer==4&&user==4){
          std::cout<<"Oops it's a tie!!"<<"\n";
        }else if(computer==5&&user==5){
          std::cout<<"Oops it's a tie!!"<<"\n";
        }


        break;
      }
      default:
      if (ch!=2) {
        std::cout<<"Choose an option from above"<<"\n";
      }

    }
  }while(ch!=2);
  return 0;
}
@abdulriiyaz
Copy link

Yes, this is promising, how about adding sleeper/delay sequences or methods for the countdown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants