Advertisement
Guest User

Campanas

a guest
Oct 17th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. #define Rock 1
  6. #define Paper 2
  7. #define Scissors 3
  8. #define Lizard 4
  9. #define Spock 5
  10.  
  11. using namespace std;
  12.  
  13. void PresentacioJoc() //Ejercicio 1
  14. {
  15. 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;
  16. }
  17.  
  18. bool Senar(int sencer) //Ejercicio 2
  19. {
  20. if (sencer % 2 == 0)
  21. return false;
  22. else
  23. return true;
  24. }
  25.  
  26. int LlegirSenar() //Ejercicio 3
  27. {
  28. bool correcto = true;
  29. int num;
  30.  
  31. cout << "Introduir un nombre senar: ";
  32. cin >> num;
  33.  
  34. correcto = Senar(num);
  35.  
  36. while (!correcto) {
  37. cout << "ERROR: El nombre introduit es parell" << endl;
  38. cout << "Introduir un nombre senar: ";
  39. cin >> num;
  40. correcto = Senar(num);
  41. }
  42.  
  43. return num;
  44. }
  45.  
  46. int Aleatori(int min, int max) //Ejercicio 4
  47. {
  48. int numero;
  49. numero = min + (rand() % (max + 1));
  50.  
  51. return numero;
  52. }
  53.  
  54. void MenuRPSLS() //Ejercicio 5
  55. {
  56. cout << "Escull entre: " << endl << "1 - Rock" << endl << "2 - Paper" << endl << "3 - Scissors" << endl << "4 - Lizard" << endl << "5 - Spock" << endl;
  57. }
  58.  
  59. int LlegirNombre(int min, int max) //Ejercicio 6
  60. {
  61. int valor;
  62. cout << "Entra valor entre " << min << " i " << max << ": ";
  63. cin >> valor;
  64.  
  65. while ((valor > max) || (valor < min))
  66. {
  67. cout << "Error: valor fora de l'interval" << endl;
  68. cout << "Entra valor entre " << min << " i " << max << ": ";
  69. cin >> valor;
  70. }
  71. return valor;
  72. }
  73.  
  74. int JocRPSLS(int p1, int p2) //Ejercicio 7
  75. {
  76. if (p1 == p2)
  77. return 0;
  78. switch (p1)
  79. {
  80. case Rock:
  81. if (p2 == Paper)
  82. return 2;
  83. if (p2 == Scissors)
  84. return 1;
  85. if (p2 == Lizard)
  86. return 1;
  87. if (p2 == Spock)
  88. return 2;
  89. break;
  90. case Paper:
  91. if (p2 == Rock)
  92. return 1;
  93. if (p2 == Scissors)
  94. return 2;
  95. if (p2 == Lizard)
  96. return 2;
  97. if (p2 == Spock)
  98. return 1;
  99. break;
  100. case Scissors:
  101. if (p2 == Rock)
  102. return 2;
  103. if (p2 == Paper)
  104. return 1;
  105. if (p2 == Lizard)
  106. return 1;
  107. if (p2 == Spock)
  108. return 2;
  109. break;
  110. case Lizard:
  111. if (p2 == Rock)
  112. return 2;
  113. if (p2 == Paper)
  114. return 1;
  115. if (p2 == Scissors)
  116. return 2;
  117. if (p2 == Spock)
  118. return 1;
  119. break;
  120. case Spock:
  121. if (p2 == Rock)
  122. return 1;
  123. if (p2 == Paper)
  124. return 2;
  125. if (p2 == Lizard)
  126. return 2;
  127. if (p2 == Scissors)
  128. return 1;
  129. break;
  130. }
  131. }
  132.  
  133. void MissatgeRPSLS(int p1, int p2) //Ejercicio 8
  134. {
  135. if (p1 == p2)
  136. cout << "Empat!!!" << endl;
  137. switch (p1)
  138. {
  139. case Rock:
  140. if (p2 == Scissors)
  141. cout << "Rock crushes Scissors" << endl;
  142. if (p2 == Lizard)
  143. cout << "Rock crushes Lizard" << endl;
  144. break;
  145. case Paper:
  146. if (p2 == Rock)
  147. cout << "Paper covers Rock" << endl;
  148. if (p2 = Spock)
  149. cout << "Paper disproves Spock" << endl;
  150. break;
  151. case Scissors:
  152. if (p2 == Paper)
  153. cout << "Scissors cuts Paper" << endl;
  154. if (p2 == Lizard)
  155. cout << "Scissors decapitates Lizard" << endl;
  156. break;
  157. case Lizard:
  158. if (p2 == Paper)
  159. cout << "Lizard eats Paper" << endl;
  160. if (p2 == Spock)
  161. cout << "Lizard poisons Spock" << endl;
  162. break;
  163. case Spock:
  164. if (p2 == Rock)
  165. cout << "Spock vaporizes Rock" << endl;
  166. if (p2 == Scissors)
  167. cout << "Spock smashes Scissors" << endl;
  168. break;
  169. }
  170. }
  171.  
  172. int main() //Ejercicio 9
  173. {
  174. int Cooper, min = 1, max = 5;
  175. int enfrontaments, eleccion, resultado;
  176. int contador_propi = 0, contador_S = 0;
  177.  
  178. srand((unsigned)time(NULL));
  179. PresentacioJoc();
  180. enfrontaments = LlegirSenar();
  181.  
  182. do
  183. {
  184. Cooper = Aleatori(min, max);
  185. MenuRPSLS();
  186. eleccion = LlegirNombre(min, max);
  187. resultado = JocRPSLS(eleccion, Cooper);
  188. MissatgeRPSLS(eleccion, Cooper);
  189.  
  190. if (resultado == 1)
  191. {
  192. cout << "Guanyes Tu!!!" << endl;
  193. contador_propi++;
  194. enfrontaments--;
  195. }
  196. if (resultado == 2)
  197. {
  198. cout << "Guanya Sheldon Cooper!!!" << endl;
  199. contador_S++;
  200. enfrontaments--;
  201. }
  202. cout << "MARCADOR -- Sheldon " << contador_S << " Tu " << contador_propi << endl;
  203. } while (((contador_propi <= ((enfrontaments / 2) + 1)) && (contador_S <= ((enfrontaments / 2) + 1))));
  204.  
  205. if (contador_propi > contador_S)
  206. cout << "Tu ets el guanyador" << endl;
  207. else if (contador_propi < contador_S)
  208. cout << "El guanyador es Sheldon" << endl;
  209.  
  210. return 0;
  211. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement