Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void RockPaperScissors()
- { //game is running.
- int gameisRunning;
- gameisRunning = true;
- char ch;
- // setting variables for the scores, and turns.
- int player_win_tally= 0;
- int draw = 0;
- int comp_win_tally = 0;
- int playTurn = 5;
- int Turnfinish = 5;
- // start of the game loop, the loop will be running until ch == n
- for (int i = 0; i < playTurn; i++) {
- if (gameisRunning == true) {
- std::string CPUChoices;
- //opens RPS.txt, this will implement the Computer moves.
- std::ifstream inFile;
- inFile.open("RPS.txt");
- char choice;
- std::cout << "Welcome to Rock, Paper, Scissors!" << std::endl;
- //Asking the player to make a choice.
- while (std::getline(inFile, CPUChoices) || i != 4) {
- std::cout << "Press R for Rock, P for Paper, S for Scissors:" << std::endl;
- playTurn++;
- std::cin >> choice;
- std::cout << "The computer has chosen: " << CPUChoices << std::endl;
- //starting the sequence where 9 possible outcomes can happen.
- if (choice == 'R' && CPUChoices == "R") {
- std::cout << "Rock meets rock, it is a draw." << std::endl;
- draw++;
- } else if (choice == 'R' && CPUChoices == "P") {
- std::cout << "Rock has been covered by paper, computer wins." << std::endl;;
- comp_win_tally++;
- } else if (choice == 'R' && CPUChoices == "S") {
- std::cout << "Rock beats scissors, player wins." << std::endl;;
- player_win_tally++;
- } else if (choice == 'P' && CPUChoices == "R") {
- std::cout << "Paper covers rock, player wins." << std::endl;
- player_win_tally++;
- } else if (choice == 'P' && CPUChoices == "P") {
- std::cout << "Paper meets paper, it is a draw." << std::endl;
- draw++;
- } else if (choice == 'P' && CPUChoices == "S") {
- std::cout << "Paper has been cut by Scissors, computer wins." << std::endl;;
- comp_win_tally++;
- } else if (choice == 'S' && CPUChoices == "R") {
- std::cout << "Scissors have been crushed by the rock, computer wins." << std::endl;
- comp_win_tally++;
- } else if (choice == 'S' && CPUChoices == "P") {
- std::cout << "Scissors cuts paper, player wins." << std::endl;
- player_win_tally++;
- } else if (choice == 'S' && CPUChoices == "S") {
- std::cout << "Scissors meets scissors, it is a draw." << std::endl;
- draw++;
- } else {
- std::cout << "Player has not selected R, P, and S." << std::endl;
- }
- if (i == 4) {
- std::cout << "Player:" << player_win_tally << std::endl;
- ;std::cout << "Draws:" << draw << std::endl;
- std::cout << "CPU:" << comp_win_tally << std::endl;
- return;
- }
- }
- inFile.close(); // close file after, playing a game of RPS.
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement