Skip to content

Instantly share code, notes, and snippets.

@felixa1243
Created February 3, 2022 19:45
Show Gist options
  • Save felixa1243/3237be34bd859fbc191eed57bfca43c4 to your computer and use it in GitHub Desktop.
Save felixa1243/3237be34bd859fbc191eed57bfca43c4 to your computer and use it in GitHub Desktop.
#include<iostream>
#include <conio.h>
#include<cstdlib>
using namespace std;
int pointInitializer(int a=1){
system("color b");
cout<<"System initializing!...\n";
sleep(1);
cout<<"Enter how many lifes do you want: ";
cin>>a;
cin.ignore();
clrscr();
cout<<"Set life to "<<a<<" Succed!\n Enjoy\n";
return a;
}
int main(){
bool playing=true;
int player;
string RnG[]={"Kertas","Batu","Gunting"};
int point=pointInitializer();
while(playing|point>1){
system("color a");
srand(time(0));
int RandIndex=rand()%3;
string cpu=RnG[RandIndex];
cout<<"Kertas Batu Gunting\n";
cout<<"[0].Exit\n[1].Kertas\n[2].Batu\n[3].Gunting\n>";
cin>>player;
if(player==0){
cout<<"Safe quit...";
sleep(1);
playing=false;
}
else if(point<1){
system("color c");
cout<<"GAME OVER!";
playing=false;
}//kertas
else if(player==1&&RandIndex==0){
cout<<"Pilihanmu adalah: "<<RnG[player-1]<<endl;
cout<<"Cpu: "<<cpu<<endl;
cout<<"Draw!\n";
cout<<"Poin sekarang adalah: "<<point<<endl;
}
else if(player==1&&RandIndex==1){
cout<<"Pilihanmu adalah: "<<RnG[player-1]<<endl;
cout<<"Cpu: "<<cpu<<endl;
cout<<"KAMU MENANG!\n";
point+=8;
cout<<"Poin sekarang adalah: "<<point<<endl;
}
else if(player==1&&RandIndex==2){
cout<<"Pilihanmu adalah: "<<RnG[player-1]<<endl;
cout<<"Cpu: "<<cpu<<endl;
cout<<"KAMU KALAH\n";
point-=8;
cout<<"Poin sekarang adalah: "<<point<<endl;
}
//end of kertas
//batu
else if(player==2&&RandIndex==0){
cout<<"Pilihanmu adalah: "<<RnG[player-1]<<endl;
cout<<"Cpu: "<<cpu<<endl;
cout<<"KAMU KALAH\n";
point-=8;
cout<<"Poin sekarang adalah: "<<point<<endl;
}
else if(player==2&&RandIndex==1){
cout<<"Pilihanmu adalah: "<<RnG[player-1]<<endl;
cout<<"Cpu: "<<cpu<<endl;
cout<<"DRAW!\n";
cout<<"Poin sekarang adalah: "<<point<<endl;
}
else if(player==2&&RandIndex==2){
cout<<"Pilihanmu adalah: "<<RnG[player-1]<<endl;
cout<<"Cpu: "<<cpu<<endl;
cout<<"KAMU MENANG!\n";
point+=8;
cout<<"Poin sekarang adalah: "<<point<<endl;
}
//end of batu
//gunting
else if(player==3&&RandIndex==0){
cout<<"Pilihanmu adalah: "<<RnG[player-1]<<endl;
cout<<"Cpu: "<<cpu<<endl;
cout<<"KAMU MENANG!\n";
point+=8;
cout<<"Poin sekarang adalah: "<<point<<endl;
}
else if(player==3&&RandIndex==1){
cout<<"Pilihanmu adalah: "<<RnG[player-1]<<endl;
cout<<"Cpu: "<<cpu<<endl;
cout<<"KAMU KALAH!\n";
point-=8;
cout<<"Poin sekarang adalah: "<<point<<endl;
}
else if(player==3&&RandIndex==2){
cout<<"Pilihanmu adalah: "<<RnG[player-1]<<endl;
cout<<"Cpu: "<<cpu<<endl;
cout<<"DRAW!\n";
cout<<"Poin sekarang adalah: "<<point<<endl;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment