Assalamu'alaikum.. malam teman, gimana aktivitasnya hari ini? Jangan lupa untuk istirahat ya di sela - sela kesibukan.. :)
Oiya teman, kali ini saya akan memposting sebuah source code sebuah permainan.. Ini merupakan permainan yang tergolong klasik.. Tic Tac Toe.. Iya, kali ini saya akan share kepada teman - teman source codenya.. Langsung aja ya..
#include <iostream>
#include <stdlib.h>
#include <time.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main();
void l(){for(int i=1;i<=5;i++) cout<<char(205);}//lurus
void kna(){cout<<char(201);}//kanan atas
void ta(){cout<<char(203);}//tengah atas
void kra(){cout<<char(187)<<endl;}//kiri atas
void la(){cout<<char(186);}//lurus atas
void kos(){for(int i=1;i<=5;i++) cout<<char(0);} //kosong
void knt(){cout<<char(204); }//kanan tengah
void tt(){cout<<char(206);}//tengah tengah
void krt(){cout<<char(185)<<endl;}//kiri tengah
void knb(){cout<<char(200);}
void tb(){cout<<char(202);}
void krb(){cout<<char(188);}
void xp(){cout<<"# #";} void op(){cout<<"* * *";}
void xt(){cout<<" # ";}; void ot(){cout<<"* *";}
void lyr(int a,int b,int c){
la();switch(a){case 0:kos();break;case 1:xp();break;case 2:op();break;default:kos();break;} la(); switch(b){case 0:kos();break;case 1:xp();break;case 2:op();break;default:kos();break;} la(); switch(c){case 0:kos();break;case 1:xp();break;case 2:op();break;default:kos();break;} la(); cout<<endl;
la();switch(a){case 0:kos();break;case 1:xt();break;case 2:ot();break;default:kos();break;} la(); switch(b){case 0:kos();break;case 1:xt();break;case 2:ot();break;default:kos();break;} la(); switch(c){case 0:kos();break;case 1:xt();break;case 2:ot();break;default:kos();break;} la(); cout<<endl;
la();switch(a){case 0:kos();break;case 1:xp();break;case 2:op();break;default:kos();break;} la(); switch(b){case 0:kos();break;case 1:xp();break;case 2:op();break;default:kos();break;} la(); switch(c){case 0:kos();break;case 1:xp();break;case 2:op();break;default:kos();break;} la(); cout<<endl;
}
int cek(int a[]){
int b=0;
for(int i=0;i<=8;i++) {
if(a[i]!=0) b++;
}
if(b==9){
return 3;
}//kembalian seri
//if(pyr==1) pyr=2; else pyr=1;
for(int i=0;i<=6;i+=3){
if(a[i]!=0)
if(a[i]==a[i+1]&&a[i]==a[i+2]){
return a[i];
}
}
for(int i=0;i<=6;i++){
if(a[i]!=0)
if(a[i]==a[i+3]&&a[i+3]==a[i+6]){
return a[i];
}
}
if(a[0]!=0) {
if(a[0]==a[4]&&a[4]==a[8]){
return a[0];
}
}
if(a[2]!=0){
if(a[2]==a[4]&&a[4]==a[6]){
return a[2];
}
}
return 0;
}
void tengah(){knt();l();tt();l();tt();l();krt();}
void atas(){kna();l();ta();l();ta();l();kra();};
void bawah(){knb();l();tb();l();tb();l();krb();cout<<endl;}
void ai(int a[]){
}
main() {
int a[9];
int pyr=1;
int plh;
int slh=0;
for(int i=0;i<=8;i++){a[i]=0;}
balik:
if(slh==1){ cout<<"ojo nindihi coo"<<endl;slh=0;} else if(slh==2){ cout<<"kotak e ming 1 ketok 9, fokus-fokus"<<endl;slh=0;}
atas();
lyr(a[0],a[1],a[2]);
tengah();
lyr(a[3],a[4],a[5]);
tengah();
lyr(a[6],a[7],a[8]);
bawah();
//for(int i=0;i<=8;i++) cout<<a[i]; melihat posisi dalam angka
if(cek(a)!=0){
if (cek(a)!=3){
cout<<"pemain";
if(cek(a)==1) cout<<" x "; else if(cek(a)==2) cout<<" O ";
cout<<"menang"<<endl;
}
else if (cek(a)==3) cout<<"seri cieeee ;)"<<endl;
system("pause");
system("cls");
main();
}
//for(int i=0;i<=8;i++){cout<<a[i];}
cout<<"player ";if(pyr==1)cout<<"x";else if(pyr==2) cout<<"o";cout<<" pilih kotak ";cin>>plh;
if(plh<1||plh>9) {
slh=2;
system("cls");
goto balik;
}//di luar kotak
if(a[plh-1]<=2 && a[plh-1]>=1) {
slh=1;
system("cls");
goto balik;
}//sudah di pilih
else if(plh<=9&&plh>=1) a[plh-1]=pyr;
if(pyr==1) pyr=2; else if(pyr==2) pyr=1;
system("cls");
goto balik;
}
Oiya teman, kali ini saya akan memposting sebuah source code sebuah permainan.. Ini merupakan permainan yang tergolong klasik.. Tic Tac Toe.. Iya, kali ini saya akan share kepada teman - teman source codenya.. Langsung aja ya..
#include <iostream>
#include <stdlib.h>
#include <time.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main();
void l(){for(int i=1;i<=5;i++) cout<<char(205);}//lurus
void kna(){cout<<char(201);}//kanan atas
void ta(){cout<<char(203);}//tengah atas
void kra(){cout<<char(187)<<endl;}//kiri atas
void la(){cout<<char(186);}//lurus atas
void kos(){for(int i=1;i<=5;i++) cout<<char(0);} //kosong
void knt(){cout<<char(204); }//kanan tengah
void tt(){cout<<char(206);}//tengah tengah
void krt(){cout<<char(185)<<endl;}//kiri tengah
void knb(){cout<<char(200);}
void tb(){cout<<char(202);}
void krb(){cout<<char(188);}
void xp(){cout<<"# #";} void op(){cout<<"* * *";}
void xt(){cout<<" # ";}; void ot(){cout<<"* *";}
void lyr(int a,int b,int c){
la();switch(a){case 0:kos();break;case 1:xp();break;case 2:op();break;default:kos();break;} la(); switch(b){case 0:kos();break;case 1:xp();break;case 2:op();break;default:kos();break;} la(); switch(c){case 0:kos();break;case 1:xp();break;case 2:op();break;default:kos();break;} la(); cout<<endl;
la();switch(a){case 0:kos();break;case 1:xt();break;case 2:ot();break;default:kos();break;} la(); switch(b){case 0:kos();break;case 1:xt();break;case 2:ot();break;default:kos();break;} la(); switch(c){case 0:kos();break;case 1:xt();break;case 2:ot();break;default:kos();break;} la(); cout<<endl;
la();switch(a){case 0:kos();break;case 1:xp();break;case 2:op();break;default:kos();break;} la(); switch(b){case 0:kos();break;case 1:xp();break;case 2:op();break;default:kos();break;} la(); switch(c){case 0:kos();break;case 1:xp();break;case 2:op();break;default:kos();break;} la(); cout<<endl;
}
int cek(int a[]){
int b=0;
for(int i=0;i<=8;i++) {
if(a[i]!=0) b++;
}
if(b==9){
return 3;
}//kembalian seri
//if(pyr==1) pyr=2; else pyr=1;
for(int i=0;i<=6;i+=3){
if(a[i]!=0)
if(a[i]==a[i+1]&&a[i]==a[i+2]){
return a[i];
}
}
for(int i=0;i<=6;i++){
if(a[i]!=0)
if(a[i]==a[i+3]&&a[i+3]==a[i+6]){
return a[i];
}
}
if(a[0]!=0) {
if(a[0]==a[4]&&a[4]==a[8]){
return a[0];
}
}
if(a[2]!=0){
if(a[2]==a[4]&&a[4]==a[6]){
return a[2];
}
}
return 0;
}
void tengah(){knt();l();tt();l();tt();l();krt();}
void atas(){kna();l();ta();l();ta();l();kra();};
void bawah(){knb();l();tb();l();tb();l();krb();cout<<endl;}
void ai(int a[]){
}
main() {
int a[9];
int pyr=1;
int plh;
int slh=0;
for(int i=0;i<=8;i++){a[i]=0;}
balik:
if(slh==1){ cout<<"ojo nindihi coo"<<endl;slh=0;} else if(slh==2){ cout<<"kotak e ming 1 ketok 9, fokus-fokus"<<endl;slh=0;}
atas();
lyr(a[0],a[1],a[2]);
tengah();
lyr(a[3],a[4],a[5]);
tengah();
lyr(a[6],a[7],a[8]);
bawah();
//for(int i=0;i<=8;i++) cout<<a[i]; melihat posisi dalam angka
if(cek(a)!=0){
if (cek(a)!=3){
cout<<"pemain";
if(cek(a)==1) cout<<" x "; else if(cek(a)==2) cout<<" O ";
cout<<"menang"<<endl;
}
else if (cek(a)==3) cout<<"seri cieeee ;)"<<endl;
system("pause");
system("cls");
main();
}
//for(int i=0;i<=8;i++){cout<<a[i];}
cout<<"player ";if(pyr==1)cout<<"x";else if(pyr==2) cout<<"o";cout<<" pilih kotak ";cin>>plh;
if(plh<1||plh>9) {
slh=2;
system("cls");
goto balik;
}//di luar kotak
if(a[plh-1]<=2 && a[plh-1]>=1) {
slh=1;
system("cls");
goto balik;
}//sudah di pilih
else if(plh<=9&&plh>=1) a[plh-1]=pyr;
if(pyr==1) pyr=2; else if(pyr==2) pyr=1;
system("cls");
goto balik;
}
Mula - mula permainan |
Kondisi permainan saat seri |
Kondisi Permainan saat Player X memenangkan permainan |