Skip to content

Instantly share code, notes, and snippets.

@XMB

XMB/RPS Secret

Created November 18, 2016 11:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save XMB/af424b7c37c8bec651b0a17fa032d4e8 to your computer and use it in GitHub Desktop.
Save XMB/af424b7c37c8bec651b0a17fa032d4e8 to your computer and use it in GitHub Desktop.
Rock paper scissors game
#include <iostream>
#include <string>
using namespace std;
// Main program function
int main()
{
// Players choice of item
char p1Choice;
char p2Choice;
char playerStartChoice;
while (true)
{
cout << "~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~" << endl;
// Basic greeting to program
cout << "Welcome to Rock, Paper, Scissors" << endl;
cout << "~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~" << endl;
// Message requesting player 1 to input their choice
cout << "Player 1, Enter R, P or S" << endl;
// Player 1 inputs choice
cin >> p1Choice;
cout << string(100, '\n');
// Message requesting player 2 to input their choice
cout << "Player 2, Enter R, P or S" << endl;
// Player 2 inputs choice
cin >> p2Choice;
// Both players enter the same choice, results in a draw
if (p1Choice == p2Choice)
cout << "Draw, Try again" << endl << endl;
else
{
// Player 2's Paper beats Player 1's Rock
if (p1Choice == 'R' && p2Choice == 'P')
cout << "Player 2 wins!" << endl << endl;
// Player 1's Paper beats Player 2's Rock
else if (p2Choice == 'R' && p1Choice == 'P')
cout << "Player 1 wins!" << endl << endl;
// Player 1's Rock beats Player 2's Scissors
else if (p1Choice == 'R' && p2Choice == 'S')
cout << "Player 1 wins!" << endl << endl;
// Player 2's Rock beats Player 1's Scissors
else if (p2Choice == 'R' && p1Choice == 'S')
cout << "Player 2 wins!" << endl << endl;
// Player 1's Scissors beats Player 2's Paper
else if (p1Choice == 'S' && p2Choice == 'P')
cout << "Player 1 wins!" << endl << endl;
// Player 2's Scissors beats Player 1's Paper
else if (p2Choice == 'S' && p1Choice == 'P')
cout << "Player 2 wins!" << endl << endl;
// Gives the players the option the end the script
cout << "Do you want to play again?" << endl;
cin >> playerStartChoice;
// Conditions for break; (ending the code)
// != (not equals)
if (playerStartChoice != 'Y')
{
cout << "Thank you for playing!" << endl;
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment