Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<iostream>
- #include<windows.h>
- #include<conio.h>
- #include <locale>
- #include<string.h>
- #include<algorithm>
- #include <stdlib.h>
- using namespace std;
- void makeLine(int length){
- for(int i=0; i < length; i++){
- cout<<"=";
- }
- cout<<endl;
- }
- void waitSecond(unsigned milliseconds){
- Sleep(milliseconds);
- }
- void openHeader(){
- makeLine(25);
- cout<<" WELCOME TO Batu Gunting Kertas GAME!"<<endl;
- cout<<" Buatan Joshua"<<endl;
- makeLine(25);
- }
- void showRound(int round){
- cout<<" RONDE " << round << " DIMULAI!"<<endl;
- makeLine(25);
- }
- string compareBGK(string player,string bot){
- transform(player.begin(),player.end(),player.begin(),::towlower);
- transform(bot.begin(),bot.end(),bot.begin(),::towlower);
- string status;
- if(player == "gunting"){
- if (bot == "gunting"){
- status = "Seri";
- }
- else if (bot == "kertas"){
- status = "Menang";
- }
- else if (bot == "batu"){
- status = "Kalah";
- }
- }else if(player =="kertas"){
- if (bot == "gunting"){
- status = "Kalah";
- }
- else if (bot == "kertas"){
- status = "Seri";
- }
- else if (bot == "batu"){
- status = "Menang";
- }
- }else if(player =="batu"){
- if (bot == "gunting"){
- status = "Menang";
- }
- else if (bot == "kertas"){
- status = "Kalah";
- }
- else if (bot == "batu"){
- status = "Seri";
- }
- }
- cout<<"Bot Memilih "<<bot<<endl;
- return status;
- }
- string botPilihBGK()
- {
- cout<<"Bot Memilih ";
- int pilihanBot = rand() % 3+1;
- string statusPilihan;
- switch(pilihanBot){
- case 1:
- statusPilihan = "Gunting";
- break;
- case 2:
- statusPilihan = "Kertas";
- break;
- case 3:
- statusPilihan = "Batu";
- break;
- default:
- statusPilihan = "Gunting";
- break;
- }
- waitSecond(2000);
- cout<<"..."<<endl;
- waitSecond(2000);
- return statusPilihan;
- }
- string pilihBGK(string pilihan[],int length){
- cout<<"Beberapa opsi yg dapat anda pilih"<<endl;
- for(int i = 0 ; i<length;i++){
- cout<<"-"<<pilihan[i]<<endl;
- }
- string pilihanPlayer;
- cin>>pilihanPlayer;
- makeLine(25);
- cout<<"Anda Memilih "<<pilihanPlayer<<endl;
- return pilihanPlayer;
- }
- template <size_t array_length>
- int getArrayLength(string (&array)[array_length]){
- return array_length;
- }
- int main(){
- //int mulai;
- string mulai;
- bool isPlayed = false;
- string pilihanBot;
- string pilihanPlayer;
- string bgk[3] = {"Gunting","Batu","Kertas"};
- int round = 0;
- int maxRound = 3;
- int playerPoint = 0 , botPoint = 0;
- cout<<endl;
- cout<<"Apakah anda ingin memulai Permainan Y/N";
- cout<<endl;
- cin>>mulai;
- if(mulai == "y" || mulai == "Y"){
- openHeader();
- isPlayed = true;
- while(isPlayed && round < maxRound){
- round++;
- showRound(round);
- waitSecond(2000);
- string stat = compareBGK(pilihBGK(bgk,getArrayLength(bgk)),botPilihBGK());
- if (stat == "Menang"){
- playerPoint++;
- cout<<"Anda "<<stat<<"!"<<endl;
- }
- else if (stat == "Seri" ){
- //Nothing happend
- cout<<"Anda "<<stat<<"!"<<endl;
- }
- else{
- botPoint++;
- cout<<"Anda "<<stat<<"!"<<endl;
- }
- waitSecond(2000);
- makeLine(25);
- }
- cout<<"Player Point: "<<playerPoint<<endl;
- cout<<"Bot Point: "<<botPoint<<endl;
- makeLine(25);
- if (playerPoint > botPoint){
- cout<<"ANDA MENANG!"<<endl;
- }
- else if (playerPoint == botPoint){
- cout<<"ANDA SERI!"<<endl;
- }
- else {
- cout<<"ANDA KALAH!"<<endl;
- }
- }else{
- getch();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement