1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int getUserChoice();
int getComputerChoice();
void determineWinner(int, int);
void displayChoice(int);
int main()
{
cout << "Can you beat me at Rock, Paper, Scissors, Spock, Lizard?" << endl;
cout << "Rules of the game are!" << endl;
cout << "Scissors cuts Paper, Paper covers Rock, Rock crushes Lizard, Lizard poisons Spock, Spock smashes" << endl;
cout <<" Scissors, Scissors decapitates Lizard, Lizard eats Paper, Paper disproves Spock, Spock vaporizes Rock, Rock crushes" << endl;
cout <<" Scissors " << endl;
}
int getUsersChoice()
{
int userschoice, Rock = 1, Paper = 2, Scissors = 3, Lizard = 4, Spock = 5;
cout << "Please enter your choice: 1-Rock, 2-Paper, 3-Scissors, 4-Lizard, 5-Spock";
cin >> userschoice;
if ( userschoice == 1 )
{
cout << "You Chose: Rock" << endl;
}
else if ( userschoice == 2 )
{
cout << "You Chose: Paper" << endl;
}
else if ( userschoice == 3 )
{
cout << "You Chose: Scissors" << endl;
}
else if ( userschoice == 4 )
{
cout << "You Chose: Lizard" << endl;
}
else if ( userschoice == 5 )
{
cout << "You Chose: Spock" << endl;
}
int getComputerChoice();
{
char compchar, compchoice;
srand(time(0));
compchoice = rand() % 5 + 1;
if ( compchoice == 1 )
{
compchar = '1';
cout << " Computer Chooses: Rock " << endl;
}
else if ( compchoice == 2 )
{
compchar = '2';
cout << " Computer Chooses: Paper " << endl;
}
else if ( compchoice == 3 )
{
compchar = '3';
cout << " Computer Chooses: Scissors " << endl;
}
else if ( compchoice == 4 )
{
compchar = '4';
cout << " Computer Chooses: Lizard " << endl;
}
else if ( compchoice == 5 )
{
compchar = '5';
cout << " Computer Chooses: Spock " << endl;
return compchar;
}
}
void determineWinner (int userschoice, int compchoice);
{
int ususerschoiceer, compchoice;
if ( ( userschoice == 1 && compchoice == '1' ) ||
( userschoice == 2 && compchoice == '2' ) ||
( userschoice == 3 && compchoice == '3' ) ||
( userschoice == 4 && compchoice == '4' ) ||
( userschoice == 5 && compchoice == '5' ) )
{
cout << " It's a TIE! " << endl;
}
else if (( userschoice == 3 && compchoice == '2' ) ||
( userschoice == 2 && compchoice == '1' ) ||
( userschoice == 1 && compchoice == '4' ) ||
( userschoice == 4 && compchoice == '5' ) ||
( userschoice == 5 && compchoice == '3' ) ||
( userschoice == 3 && compchoice == '4' ) ||
( userschoice == 4 && compchoice == '2' ) ||
( userschoice == 2 && compchoice == '5' ) ||
( userschoice == 5 && compchoice == '1' ) ||
( userschoice == 1 && compchoice == '3' ))
{
cout << "You Won. I'll get you next time." << endl;
}
else if (( userschoice == 2 && compchoice == '3' ) ||
( userschoice == 1 && compchoice == '2' ) ||
( userschoice == 4 && compchoice == '1' ) ||
( userschoice == 5 && compchoice == '4' ) ||
( userschoice == 3 && compchoice == '5' ) ||
( userschoice == 4 && compchoice == '3' ) ||
( userschoice == 2 && compchoice == '4' ) ||
( userschoice == 5 && compchoice == '2' ) ||
( userschoice == 1 && compchoice == '5' ) ||
( userschoice == 3 && compchoice == '1' ))
{
cout << "I won, Better luck next time!!" << endl;
}
return 0;
}
void displayChoice (int winner);
{
int winner;
}
|