Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <time.h>
- #define Rock 1
- #define Paper 2
- #define Scissors 3
- #define Lizard 4
- #define Spock 5
- using namespace std;
- void PresentacioJoc() //Ejercicio 1
- {
- cout << "Pedra, paper, tisores, llangardaix, Spock es un joc d'atzar aplicacio del popular Pedra, paper, tisores" << endl << "Creat per Sam Kass amb Karen Bryla http://www.samkass.com/theories/RPSSL.html" << endl << "Popularitzat per Sheldon Cooper a la serie Big Bang Theory." << endl << "Es fa servir per solucionar una disputa entre Sheldon i Raj en el capitol The Lizard - Spock Expansion" << endl << endl << "El joc es al millor de N partides on N es un nombre senar" << endl << endl;
- }
- bool Senar(int sencer) //Ejercicio 2
- {
- if (sencer % 2 == 0)
- return false;
- else
- return true;
- }
- int LlegirSenar() //Ejercicio 3
- {
- bool correcto = true;
- int num;
- cout << "Introduir un nombre senar: ";
- cin >> num;
- correcto = Senar(num);
- while (!correcto) {
- cout << "ERROR: El nombre introduit es parell" << endl;
- cout << "Introduir un nombre senar: ";
- cin >> num;
- correcto = Senar(num);
- }
- return num;
- }
- int Aleatori(int min, int max) //Ejercicio 4
- {
- int numero;
- numero = min + (rand() % (max + 1));
- return numero;
- }
- void MenuRPSLS() //Ejercicio 5
- {
- cout << "Escull entre: " << endl << "1 - Rock" << endl << "2 - Paper" << endl << "3 - Scissors" << endl << "4 - Lizard" << endl << "5 - Spock" << endl;
- }
- int LlegirNombre(int min, int max) //Ejercicio 6
- {
- int valor;
- cout << "Entra valor entre " << min << " i " << max << ": ";
- cin >> valor;
- while ((valor > max) || (valor < min))
- {
- cout << "Error: valor fora de l'interval" << endl;
- cout << "Entra valor entre " << min << " i " << max << ": ";
- cin >> valor;
- }
- return valor;
- }
- int JocRPSLS(int p1, int p2) //Ejercicio 7
- {
- if (p1 == p2)
- return 0;
- switch (p1)
- {
- case Rock:
- if (p2 == Paper)
- return 2;
- if (p2 == Scissors)
- return 1;
- if (p2 == Lizard)
- return 1;
- if (p2 == Spock)
- return 2;
- break;
- case Paper:
- if (p2 == Rock)
- return 1;
- if (p2 == Scissors)
- return 2;
- if (p2 == Lizard)
- return 2;
- if (p2 == Spock)
- return 1;
- break;
- case Scissors:
- if (p2 == Rock)
- return 2;
- if (p2 == Paper)
- return 1;
- if (p2 == Lizard)
- return 1;
- if (p2 == Spock)
- return 2;
- break;
- case Lizard:
- if (p2 == Rock)
- return 2;
- if (p2 == Paper)
- return 1;
- if (p2 == Scissors)
- return 2;
- if (p2 == Spock)
- return 1;
- break;
- case Spock:
- if (p2 == Rock)
- return 1;
- if (p2 == Paper)
- return 2;
- if (p2 == Lizard)
- return 2;
- if (p2 == Scissors)
- return 1;
- break;
- }
- }
- void MissatgeRPSLS(int p1, int p2) //Ejercicio 8
- {
- if (p1 == p2)
- cout << "Empat!!!" << endl;
- switch (p1)
- {
- case Rock:
- if (p2 == Scissors)
- cout << "Rock crushes Scissors" << endl;
- if (p2 == Lizard)
- cout << "Rock crushes Lizard" << endl;
- break;
- case Paper:
- if (p2 == Rock)
- cout << "Paper covers Rock" << endl;
- if (p2 = Spock)
- cout << "Paper disproves Spock" << endl;
- break;
- case Scissors:
- if (p2 == Paper)
- cout << "Scissors cuts Paper" << endl;
- if (p2 == Lizard)
- cout << "Scissors decapitates Lizard" << endl;
- break;
- case Lizard:
- if (p2 == Paper)
- cout << "Lizard eats Paper" << endl;
- if (p2 == Spock)
- cout << "Lizard poisons Spock" << endl;
- break;
- case Spock:
- if (p2 == Rock)
- cout << "Spock vaporizes Rock" << endl;
- if (p2 == Scissors)
- cout << "Spock smashes Scissors" << endl;
- break;
- }
- }
- int main() //Ejercicio 9
- {
- int Cooper, min = 1, max = 5;
- int enfrontaments, eleccion, resultado;
- int contador_propi = 0, contador_S = 0;
- srand((unsigned)time(NULL));
- PresentacioJoc();
- enfrontaments = LlegirSenar();
- do
- {
- Cooper = Aleatori(min, max);
- MenuRPSLS();
- eleccion = LlegirNombre(min, max);
- resultado = JocRPSLS(eleccion, Cooper);
- MissatgeRPSLS(eleccion, Cooper);
- if (resultado == 1)
- {
- cout << "Guanyes Tu!!!" << endl;
- contador_propi++;
- enfrontaments--;
- }
- if (resultado == 2)
- {
- cout << "Guanya Sheldon Cooper!!!" << endl;
- contador_S++;
- enfrontaments--;
- }
- cout << "MARCADOR -- Sheldon " << contador_S << " Tu " << contador_propi << endl;
- } while (((contador_propi <= ((enfrontaments / 2) + 1)) && (contador_S <= ((enfrontaments / 2) + 1))));
- if (contador_propi > contador_S)
- cout << "Tu ets el guanyador" << endl;
- else if (contador_propi < contador_S)
- cout << "El guanyador es Sheldon" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement