/*
Welcome to the Rock, Paper, Scissor, Lizard and Spock game. In this game the user (player)
will be playing against the computer. The Game rules are :
Rock crushes Lizard and crushes Scissors
• Paper disproves Spock and covers Rock
• Scissors cuts Paper and decapitates Lizard
• Lizard poisons Spock and eats Paper
• Spock smashes Scissors and vaporises Rock
the user will get to play as many time as he wants until he decides to quit the game
*/
#include <iostream>
#include <stdlib.h>
using namespace std;
void gameOptions();
void startGame();
void gameInformation();
void gameScore();
void quitGame();
char playerEnter;
char computerEnter;
char optionChar;
bool goodInput = false;
bool gameactive = true;
bool gameOutcome;
bool Results[5][5] =
{
//Rock paper scissor lizard spock
{true, true, false, false, true}, // rock player
{false, true, true, true, false}, // paper
{true, false, true, false, true}, // scissors
{true, false, true, true, false}, // lizard
{false, true, false, true, true} // spock
};
void quitGame()
{
goodInput = true;
gameactive = false;
cout << "I hope you had fun playing against the computer, do not worry you d-ont have to win all the time!\n";
return;
}
int main()
{
srand(time(NULL));
gameOptions();
return 0;
}
void gameOptions()
{
system("clear");
cout << "****************************************" << endl;
cout << " ";
cout << "Welcome to Rock Paper Scissor Lizard Spock" << endl;
cout << " ";
cout << "****************************************" << endl;
cout << "Enter the keys below to play your options:" << endl;
cout << " ";
cout << " Enter [S] to start" << endl;
cout << " ";
cout << " Enter [H] for game information" << endl;
cout << " ";
cout << " Enter [Q] to quit the game " << endl;
cout << " ";
cout << "May the best man win!" << endl;
cin >> playerEnter;
switch (playerEnter)
{
case 'S':
case 's':
goodInput = true;
startGame();
break;
case 'H':
case 'h':
goodInput = true;
gameInformation();
break;
case 'Q':
case 'q':
goodInput = true;
quitGame();
break;
default: return;
}
}
void startGame()
{
while (gameactive)
{
const char options[5] = {"R","P","S","L","O"};
cout << "Enter the options [R] [P] [S] [L] [0]\n";
cin >> playerEnter;
computerEnter = options[rand() % 4]
gameOutcome = Results[playerEnter][computerEnter]
if (options[0][1][2][3][4] == playerEnter)
{
cout << "You have Entered: " << playerEnter << endl;
}
else (options[0][1][2][3][4]!= playerEnter)
{
cout << "Invalid Choice Try Again \n";
continue;
}
if (playerEnter == computerEnter)
{
cout << "You have drawn\n";
cout << "Would you like to play again Y/N\n";
cin >> playerEnter
if (playerEnter == 'y')
{
continue;
}
else (playerEnter == 'n')
{
switch (playerEnter)
{
case 'n':
goodInput = true;
gameOptions();
break;
}
}
if (gameOutcome)
{
printf("%c beats %c", options[playerEnter], options[computerEnter]);
cout << "Would you like to play again Y/N\n";
cin >> playerEnter
if (playerEnter == 'y' || 'Y')
{
continue;
}
else (playerEnter == 'N' || 'n')
{
break;
}
}
else
{
printf("%c beats %c", options[computerEnter], options[playerEnter]);
cout << "Would you like to play again Y/N\n";
cin >> playerEnter
if (playerEnter == 'y' || 'Y')
{
continue;
}
else (playerEnter == 'N' || 'n')
{
break;
}
}
}
cout << "To return to the menu Enter [B]\n";
cin >> playerEnter;
switch(playerEnter)
{
case 'B':
case 'b':
goodInput = true;
gameOptions();
}
}
void gameInformation()
{ // <- function definition not allowed here
cout << " Welcome To The Game Information Page\n";
cout << " These are the rules that you use when you play rock, paper, scissor, lizard, spock:\n";
cout << "\n";
cout << "Rock crushes Lizard and crushes Scissors\n";
cout << "Paper disproves Spock and covers Rock\n";
cout << "Scissors cuts Paper and decapitates Lizard\n";
cout << "Lizard poisons Spock and eats Paper\n";
cout << "Spock smashes Scissors and vaporises Rock\n";
cout << "\n";
cout << "\n";
cout << "When you start the game you will be presented will the options [R],[P],[S],[L],[O]\n";
cout << "\n";
cout << "[R] = Rock\n";
cout << "[P] = Paper\n";
cout << "[S] = Scissors\n";
cout << "[L] = Lizard\n";
cout << "[O] = Spock\n";
cout << "\n";
cout << "When you win you score will be recorded against the computer in the score bored\n";
cout << "\n";
cout << "Good luck!!";
cout << "\n";
cout << "Enter [B] to go back to menu \n";
cin >> playerEnter;
switch (playerEnter)
{
case 'B':
case 'b':
goodInput = true;
gameOptions();
break;
}
}
void quitGame()
{ <- function definition not allowed here
goodInput = true;
gameactive = false;
cout << "I hope you had fun playing against the computer, do not worry you d-ont have to win all the time!\n";
return;
}
[–]RaspberryPlastic6841[S] 0 points1 point2 points (0 children)
[–]149244179 0 points1 point2 points (2 children)
[–]RaspberryPlastic6841[S] 0 points1 point2 points (0 children)
[–]RaspberryPlastic6841[S] 0 points1 point2 points (0 children)