Rock Paper Scissors Lizard Spock
Project Overview
This is a C++ implementation of the classic game Rock Paper Scissors Lizard Spock. As I am still in the beginning of my journey I have not yet worked out how to get my webpage to run my C++ code. So even though I initially created this code on C++, I have rewritten (with the help of AI) the code to run using JavaScript so it can be played here. If you want to see the complete C++ code then click here.
The game allows a user to play against the computer, which makes random choices.
The concept of this game came from The Big Bang Theory, if you want to learn the rules please watch the video in the header.
Result
1) Rock ✊
2) Paper ✋
3) Scissors ✌️
4) Lizard 🦎
5) Spock 🖖
Enter number 1-5 below to play against the computer.
Method
The first thing I did to make this program is to create a variable to store the users choice and also one that will select a random number which be the computers choice.
int computer = rand() % 5 + 1; //random number between 1-5
int user = 0;
Next is I put in some prompt to appear in the terminal, which would collect the users choice.
//user prompts
std::cout << "=================================\n";
std::cout << "Rock Paper Scissors Lizard Spock!\n";
std::cout << "=================================\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!: ";
std::cin >> user;
Finally, I created conditionals based on what the user selected to decide the victor of the round.
//conditionals about victor
//User = Computer Tie
if (user==computer) {
std::cout << "It's a tie!\n";
}
//user picks rock
if (user==1) {
if (computer==3) {
std::cout << "Rock crushes scissors. You win!\n";
} else if (computer==4) {
std::cout << "Rock crushes lizard. You win!\n";
} else {
std::cout << "You lose!\n";
}
}
//user picks paper
if (user==2) {
if (computer==1) {
std::cout << "Paper covers rock. You win!\n";
} else if (computer==5) {
std::cout << "Paper disproves Spock. You win!\n";
} else {
std::cout << "You lose!\n";
}
}
//user picks scissors
if (user==3) {
if (computer==2) {
std::cout << "Scissors cuts paper. You win!\n";
} else if (computer==4) {
std::cout << "Scissors decapitates lizard. You win!\n";
} else {
std::cout << "You lose!\n";
}
}
//user picks lizard
if (user==4) {
if (computer==5) {
std::cout << "Lizard poisons Spock. You win!\n";
} else if (computer==2) {
std::cout << "Lizard eat paper. You win!\n";
} else {
std::cout << "You lose!\n";
}
}
//user picks Spock
if (user==5) {
if (computer==3) {
std::cout << "Spock smashes scissors. You win!\n";
} else if (computer==1) {
std::cout << "Spock vaporises rock. You win!\n";
} else {
std::cout << "You lose!\n";
}
}