Skip to content

Instantly share code, notes, and snippets.

@krysseltillada
Created May 1, 2015 16:43
Show Gist options
  • Save krysseltillada/e9eecd3d7ce2280c97d1 to your computer and use it in GitHub Desktop.
Save krysseltillada/e9eecd3d7ce2280c97d1 to your computer and use it in GitHub Desktop.
rock, paper ,scissors game
#include <iostream>
#include <string>
#include <vector>
int main()
{
vector<int> comp = {1 , 3, 2, 1, 2, 3, 1, 1, 2, 3};
vector<string> attacks = { "rocks", "paper", "scissors" };
string decided_atk = "none", user_decided_atk = "none", results = "none";
int user_input = 0, rounds = 0, counter = 0, user_points = 0, ai_points = 0;
bool loop = true;
while (loop){
cout << "rock and scissors game: " << endl
<< "1. 3 rounds: " << endl
<< "2. 6 rounds: " << endl
<< "3. 10 rounds: " << endl;
cin >> rounds;
if (rounds == 1){
rounds = 3;
break;
}
else if (rounds = 2){
rounds = 6;
break;
}
else if (rounds = 3){
rounds = 10;
break;
}
else{
cout << "invalid input: " << endl;
continue;
}
}
while (loop)
{
for (int i = 0; i < rounds; i++){
cout << "\nenter 1 for rock: " << endl
<< "enter 2 for paper: " << endl
<< "enter 3 for scissors: " << endl;
cin >> user_input;
if (user_input > 3 || user_input < 0){
cout << "choose 1 - 3 " << endl;
break;
}
else{
for (int x = 0; x < int(attacks.size()); x++){
if (comp[i] == x){
decided_atk = attacks[x];
}
if (user_input == x){
user_decided_atk = attacks[x];
}
}
cout << "you used: " << user_decided_atk << endl
<< "the computer used: " << decided_atk << endl;
results = user_decided_atk + decided_atk;
if (results == "rockscissors" || results == "paperrock" || results == "scissorspaper"){
cout << "you win " << endl;
user_points++;
}
else if (results == "rockrock" || results == "paperpaper" || results == "scissorsscissors"){
cout << "tie " << endl;
user_points++;
ai_points++;
}
else{ cout << "you lose " << endl; ai_points++; }
counter++;
}
}
if (counter == rounds){
break;
}
}
cout << "\nresults: " << endl
<< "user: " << user_points << endl
<< "computer: " << ai_points << endl;
if (user_points > ai_points){
cout << "you win " << endl;
}
else if (user_points == ai_points){
cout << "tie " << endl;
}
else{
cout << "you lose " << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment