Advertisement
Primitiv0

Rock Paper Scissors

Sep 10th, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.83 KB | None | 0 0
  1. /******************************************************************************
  2. Piedra, Papel & Tijera
  3. *******************************************************************************/
  4.  
  5. #include <iostream>
  6. #include <string>
  7. #include <ctime>
  8. #include <cstdlib>
  9. using namespace std;
  10.  
  11. void muestra_menu()
  12. {
  13.     cout<<"0 - Piedra"<<endl;
  14.     cout<<"1 - Papel"<<endl;
  15.     cout<<"2 - Tijera"<<endl;
  16.     cout<<"3 - Salir"<<endl;
  17.    
  18.     cout<<"Selecciona una opción: "<<endl;
  19. }
  20.  
  21. int user_in()
  22. {  
  23.     int hu;
  24.     cin>> hu;
  25.  
  26.   switch(hu)
  27.   {
  28.       case 0: cout<< "Elegiste Piedra"<<endl;
  29.             break;
  30.       case 1: cout<< "Elegiste Papel"<<endl;
  31.             break;
  32.       case 2: cout<< "Elegiste Tijera"<<endl;
  33.             break;
  34. /*      case 3: cout<< "Finalizaste el juego. Hasta luego!"<<endl;
  35.             break;*/
  36.       default:///////
  37.       break;
  38.   }
  39.     return hu;
  40. }
  41.  
  42. int pc_gen()
  43. {
  44.     srand(time(0));
  45.     int pc;
  46.     pc = (rand() % 2) + 1;
  47.    
  48.       switch(pc)
  49.   {
  50.       case 0: cout<< "La PC eligió Piedra"<<endl;
  51.             break;
  52.       case 1: cout<< "La PC eligió Papel"<<endl;
  53.             break;
  54.       case 2: cout<< "La PC eligió Tijera"<<endl;
  55.               break;
  56.       default:///////
  57.       break;
  58.   }
  59.         return pc;
  60. }
  61.  
  62. char ganador(int pc, int hu)
  63. {
  64.     if (hu==3)
  65.     {
  66.         cout<< "Finalizaste el juego. Hasta luego!"<<endl;
  67.         return 0;
  68.     }
  69.     else if ((hu==0 && pc==2 ) || (hu==1 && pc==0) || (hu==2 && pc==1))
  70.     {
  71.         cout<<"Ganaste!";
  72.     }
  73.     else if ((hu==0 && pc==0 ) || (hu==1 && pc==1) || (hu==2 && pc==2))
  74.     {
  75.         cout<<"Has empatado!";
  76.     }
  77.     else if ((hu==2 && pc==0 ) || (hu==0 && pc==1) || (hu==1 && pc==2))
  78.     {
  79.         cout<<"Perdiste :(";
  80.     }
  81.         return 0;
  82. }
  83.  
  84. int main()
  85. {
  86.     muestra_menu();
  87.     ganador(user_in(),pc_gen());
  88.     return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement