Skip to content

Commit

Permalink
C file
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertoBaena authored Aug 8, 2020
1 parent c3f9693 commit 2c9727e
Showing 1 changed file with 119 additions and 0 deletions.
119 changes: 119 additions & 0 deletions rock paper scissors.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <time.h>

void printTitle(char a[]);
void stringToCaps(char a[]);

int main(){
int userHand, computerHand;
char userHandString[10], computerHandString[10];

int result;

int keepAsking;
char keepPlaying = 'Y';

/*Start randomizer*/
srand(time(NULL));

while(keepPlaying == 'Y' || keepPlaying == 'y'){
/*Generate computer's hand*/
computerHand = rand() % 3;

switch(computerHand){
case 0:
strcpy(computerHandString, "ROCK");
break;
case 1:
strcpy(computerHandString, "PAPER");
break;
case 2:
strcpy(computerHandString, "SCISSORS");
break;
default:
break;
}

/*Game*/
printTitle("ROCK, PAPER, SCISSORS BY ZABE");

do{
printf("\nRock, paper or scissors?: ");

scanf("%s", userHandString);
stringToCaps(userHandString);

keepAsking = 0;

if(strcmp(userHandString, "ROCK") == 0)
userHand = 0;
else if(strcmp(userHandString, "PAPER") == 0)
userHand = 1;
else if(strcmp(userHandString, "SCISSORS") == 0)
userHand = 2;
else
keepAsking = 1;
}while(keepAsking == 1);

printf("\n\nYour hand: %s", userHandString);
printf("\nComputer's hand: %s\n\n", computerHandString);

result = userHand - computerHand;
if(result < 0)
result += 3;

switch(result){
case 0:
printf("It's a draw, gg\n\n");
break;
case 1:
printf("YOU WON YAY!\n\n");
break;
case 2:
printf("Oh, you lost. GG EZ NOOB\n\n");
break;
default:
break;
}

do{
printf("Do you want to keep playing? [Y/N]: ");
fflush(stdin);
scanf("%c",&keepPlaying);
}while(keepPlaying != 'y' && keepPlaying != 'Y'&& keepPlaying != 'n' && keepPlaying != 'N');
system("@cls||clear");
}

printTitle("Thanks for playing! UwU");
clock_t start_time = clock();
while (clock() < start_time + 1600);

return 0;
}

void printTitle(char a[]){
int j = 0;
printf("%c%c",176,177);
for(int i = 0; i <= strlen(a)+7; i++)
printf("%c",178);
printf("%c%c\n",177,176);
printf("%c%c%c%c%c ",176,177,178,177,176);
while(a[j]!='\0'){
printf("%c",a[j]);
j++;
}
printf(" %c%c%c%c%c\n",176,177,178,177,176);
printf("%c%c",176,177);
for(int i = 0; i <= strlen(a)+7; i++)
printf("%c",178);
printf("%c%c\n",177,176);

}

void stringToCaps(char a[]){
for(int i = 0; i < strlen(a); i++)
if(a[i] > 96 && a[i] < 123)
a[i] -= 32;
}

0 comments on commit 2c9727e

Please # to comment.