Skip to content

Commit

Permalink
fix rps game
Browse files Browse the repository at this point in the history
  • Loading branch information
junian committed Feb 18, 2018
1 parent 4c3555f commit bf2d0de
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 61 deletions.
61 changes: 0 additions & 61 deletions Semut Orang Gajah/GMS Game.cpp

This file was deleted.

File renamed without changes.
60 changes: 60 additions & 0 deletions rock-paper-scissor/rps-game.cpp
@@ -0,0 +1,60 @@
/*###################################################
# #
# Rock-Paper-Scissor Game #
# Copyright (C) 2008 - 2018 #
# By: Junian Triajianto #
# #
###################################################*/

#include <stdio.h>
#include <stdlib.h>

char toUpper(char x);

int main(){
char r, p, s;
do{
char a[4]="RPS", k[4]="RPS";
int i;
system("cls");
printf("Rock-Paper-Scissor Game\n");
printf("=======================\n\n");
printf("R: Rock\nP: Paper\nS: Scissor");
for(i=1;i<=2;i++){
printf("\n\nYOU: %s\nCPU: %s\n", a, k);
printf("\nYou choose ");
do{
p = getchar();
p = toUpper(p);
}while((p != 'R' && p != 'P' && p != 'S') || p == s);
s = p;
printf("%c\nCPU choose ", p);
if(p == 'R'){
printf("S");
k[0] = ' ';
a[2] = ' ';
}else if(p == 'P'){
printf("R");
k[1] = ' ';
a[0] = ' ';
}else if(p == 'S'){
printf("P");
k[2] = ' ';
a[1] = ' ';
}
}
printf("\n\nYou: %s\nCPU: %s\n", a, k);
printf("\nYou LOSE!\n");
printf("\nTry again [Y/N]? ");
do{
r = getchar();
r = toUpper(r);
}while(r != 'Y' && r != 'N');
}while(r == 'Y');
return 0;
}

char toUpper(char x){
if (x >= 97 && x <= 122) x=x-32;
return x;
}

0 comments on commit bf2d0de

Please sign in to comment.