Herramientas de usuario

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Próxima revisión
Revisión previa
piedra_papel_tijeras.c [2024/04/02 19:42] – creado peronpiedra_papel_tijeras.c [2026/04/21 16:08] (actual) – editor externo 127.0.0.1
Línea 1: Línea 1:
-<code c>+<file c piedra_papel_tijeras.c>
 #include <stdio.h> #include <stdio.h>
 #include <string.h> #include <string.h>
Línea 5: Línea 5:
 #include <time.h> #include <time.h>
  
-void printTitle(char a[]); +void printTitulo(char a[]); 
-void stringToCaps(char a[]);+void stringAMayusculas(char a[]);
  
 int main(){ int main(){
-    int userHandcomputerHand+    int manoUsuariomanoComputadora
-    char userHandString[10], computerHandString[10]; +    char manoUsuarioString[10], manoComputadoraString[10]; 
-    +
     int result;     int result;
  
-    int keepAsking+    int siguePreguntando
-    char keepPlaying = 'Y';+    char sigueJugando = 'S';
  
     /*Start randomizer*/     /*Start randomizer*/
     srand(time(NULL));     srand(time(NULL));
  
-    while(keepPlaying == 'Y' || keepPlaying == 'y'){+    while(sigueJugando == 'S' || sigueJugando == 's'){
         /*Genera mano computada*/         /*Genera mano computada*/
-        computerHand = rand() % 3;+        manoComputadora = rand() % 3;
  
-        switch(computerHand){+        switch(manoComputadora){
             case 0:             case 0:
-                strcpy(computerHandString, "PIEDRA");+                strcpy(manoComputadoraString, "PIEDRA");
                 break;                 break;
             case 1:             case 1:
-                strcpy(computerHandString, "PAPEL");+                strcpy(manoComputadoraString, "PAPEL");
                 break;                 break;
             case 2:             case 2:
-                strcpy(computerHandString, "TIJERA");+                strcpy(manoComputadoraString, "TIJERA");
                 break;                 break;
             default:             default:
Línea 38: Línea 38:
         }         }
  
-        /*Game*/ +        /*Juego*/ 
-        printTitle("PIEDRA, PAPEL, O TIJERA, por ~peron");       +        printTitulo("PIEDRA, PAPEL, O TIJERA, por ~peron");       
 + 
         do{         do{
             printf("\Piedra, papel o tijera?: ");             printf("\Piedra, papel o tijera?: ");
- +  
-            scanf("%s", userHandString); +            scanf("%s", manoUsuarioString); 
-            stringToCaps(userHandString); +            stringAMayusculas(manoUsuarioString); 
- +  
-            keepAsking = 0; +            siguePreguntando = 0; 
- +  
-            if(strcmp(userHandString, "PIEDRA") == 0) +            if(strcmp(manoUsuarioString, "PIEDRA") == 0) 
-                userHand = 0; +                manoUsuario = 0; 
-            else if(strcmp(userHandString, "PAPEL") == 0) +            else if(strcmp(manoUsuarioString, "PAPEL") == 0) 
-                userHand = 1; +                manoUsuario = 1; 
-            else if(strcmp(userHandString, "TIJERA") == 0) +            else if(strcmp(manoUsuarioString, "TIJERA") == 0) 
-                userHand = 2;+                manoUsuario = 2;
             else             else
-                keepAsking = 1; +                siguePreguntando = 1; 
-        }while(keepAsking == 1);+        } 
 +while(siguePreguntando == 1);
  
-        printf("\n\nSu mano: %s", userHandString); +        printf("\n\nSu mano: %s", manoUsuarioString); 
-        printf("\nMano del mainframe: %s\n\n", computerHandString);+        printf("\nMano del mainframe: %s\n\n", manoComputadoraString);
  
-        result = userHand computerHand;+        result = manoUsuario manoComputadora;
         if(result < 0)         if(result < 0)
             result += 3;             result += 3;
Línea 68: Línea 69:
         switch(result){         switch(result){
             case 0:             case 0:
-                printf("Empatamos, gg\n\n");+                printf("Empatamos, nuestra mente coincide!\n\n");
                 break;                 break;
             case 1:             case 1:
Línea 79: Línea 80:
                 break;                 break;
         }         }
-               +
         do{         do{
-            printf("Quiere seguir jugando? [Y/N]: ");+            printf("Quiere seguir jugando? [S/N]: ");
             fflush(stdin);             fflush(stdin);
-            scanf("%c",&keepPlaying); +            scanf("%c",&sigueJugando); 
-        }while(keepPlaying != 'y' && keepPlaying != 'Y'&& keepPlaying != 'n' && keepPlaying != 'N');+        }while(sigueJugando != 's' && sigueJugando != 'S'&& sigueJugando != 'n' && sigueJugando != 'N');
         system("@cls||clear");         system("@cls||clear");
     }     }
  
-    printTitle("Gracias por jugar en texto-plano!! UwU"); +    printTitulo("Gracias por jugar en texto-plano!! UwU"); 
-    clock_t start_time = clock();  +    clock_t start_time = clock(); 
-    while (clock() < start_time + 1600);+    while (clock() < start_time + 16);
  
     return 0;     return 0;
 } }
  
-void printTitle(char a[]){+void printTitulo(char a[]){
     int j = 0;     int j = 0;
     printf("%c%c",176,177);     printf("%c%c",176,177);
Línea 114: Línea 115:
 } }
  
-void stringToCaps(char a[]){+void stringAMayusculas(char a[]){
     for(int i = 0; i < strlen(a); i++)     for(int i = 0; i < strlen(a); i++)
         if(a[i] > 96 && a[i] < 123)         if(a[i] > 96 && a[i] < 123)
             a[i] -= 32;             a[i] -= 32;
 } }
-</code>+</file>

Este sitio web utiliza cookies para guardar datos esenciales de su actividad, como su autenticación. Al entrar acepta el uso de cookies.

Más información