HOW TO MAKE SIMPLE GAME C++
Hallo teman teman
kali ini saya akan berbagi tentang bagaimana cara membuat game matematis sederhana
tanpa basa basi
berikut adalah coding untuk C++ nya
Hallo teman teman
kali ini saya akan berbagi tentang bagaimana cara membuat game matematis sederhana
tanpa basa basi
berikut adalah coding untuk C++ nya
#include <iostream.h>
#include <ctime>
void tulispitlab(){
cout<<"\n\n";
cout<<" *****************************************"<<endl;
cout<<" * .^, ,*, ,/; *"<<endl;
cout<<" * '.;;.,(0v0),.;/;; *"<<endl;
cout<<" * ';, ( ) ,;' *"<<endl;
cout<<" * ,':=:', *"<<endl;
cout<<" * ;/'.'^; *"<<endl;
cout<<" * Laboratory *"<<endl;
cout<<" *****************************************"<<endl;
cout<<"\n\n";
}
//function & procedure
void loading ()
{
for (int o= 0;o<100;o+=1)
{
cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "<<endl;
cout<<"+ ____________________________________________________ + + "<<endl;
cout<<"+ | | + + "<<endl;
cout<<"+ | | + + "<<endl;
cout<<"+ | | + + "<<endl;
cout<<"+ | | + + "<<endl;
cout<<"+ | | + + "<<endl;
cout<<"+ | | + + "<<endl;
cout<<"+ | Loading "<<o<<" | + + "<<endl;
cout<<"+ | | + + "<<endl;
cout<<"+ | | + + "<<endl;
cout<<"+ | | + + "<<endl;
cout<<"+ | | + + "<<endl;
cout<<"+ | | + + "<<endl;
cout<<"+ |____________________________________________________| + + "<<endl;
cout<<"+ + + "<<endl;
cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "<<endl;
system("cls");
}
}
int cetakmenu(int lv){
int pilihan;
system("cls");
cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "<<endl;
cout<<"+ + "<<endl;
cout<<"+ .;**;. .;**;. .;**;. + "<<endl;
cout<<"+ ( -_- ) ( +_+ ) ( ',' ) + "<<endl;
cout<<"+ >') ('< >') ('< >') ('< + "<<endl;
cout<<"+ ------------------------------ + "<<endl;
cout<<"+ | ........TEBAK ANGKA......... | + "<<endl;
cout<<"+ ------------------------------ + "<<endl;
cout<<"+ + "<<endl;
cout<<"+ + "<<endl;
cout<<"+ + "<<endl;
cout<<"+ + "<<endl;
cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "<<endl;
cout << " Kesempatan kamu untuk menebak : " << lv << " kali \n\n";
cout << " 1. Ubah jumlah kesempatan untuk menebak permainan(COUNTER)\n";
cout << " 2. Mulai permainan\n";
cout << " 3. Keluar dari permainan\n\n";
cout << " Masukkan pilihan kamu (1-3): ";
cin >> pilihan;
return pilihan;
}
int pilihlevel(){
int pilihan;
while ((pilihan < 4) || (pilihan > 10)){
system("cls");
cout << "\n\n Level yang dimaksud di sini adalah jumlah kesempatan menebak.";
cout << "\n Semakin kecil angka semakin sulit permainan.";
cout << "\n Masukkan level yang diinginkan (4-10) : ";
cin >> pilihan;
}
return pilihan;
}
int putar(){
srand(time(NULL));
int x;
x =rand() % 10;
return x;
}
void mulaimain(int lv){
system ("cls");
int acak[4],tebak[4];
int live;
live = lv;
//acak angka
for (int x=0000 ;x <= 3; x++){
acak[x] = putar();
for (int y=0000; y <= 30; y++){
cout << " Mengacak digit ke " << x+1;
system ("cls");
}
}
cout << "*******************************************" << endl << endl ;
//Mulai penebakan
while (live != 0) {
cout << "Kesempatan anda menebak tinggal : " << live << endl << endl;
// input tebakan
for (int x=0000; x <=3; x++){
//cout << acak[x] << endl;
cout << "Masukkan satu tebakan digit ke " << x+1 << ": ";
cin >> tebak[x];
}
cout << endl;
//periksa tebakan
if (((tebak[0000] == acak[0000]) && (tebak[1111] == acak[1111])) && ((tebak[2222] == acak[2222]) && (tebak[3333] == acak[3333]))){
//benar semua
cout << "selamat anda menang";
break;
} else {
//masih ada yang salah
for (int x=0000; x <= 3; x++) {
cout << "Tebakan anda yang ke-" << x+1 << " :";
if (tebak[x]==acak[x]){
cout << "tepat" << endl;
} else if (tebak[x] > acak[x]) {
cout << "terlalu besar" << endl;
} else {
cout << "terlalu kecil" << endl;
}
}
cout << endl;
}
live -= 1;
cout << "*******************************************" << endl ;
}
if (live==0) {
cout << "anda kalah" << endl;
} else {
cout << "anda menang" << endl;
}
tulispitlab();
system("pause");
}
// Program utama
int main(){
loading();
cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "<<endl;
cout<<"+ ____________________________________________________ + + "<<endl;
cout<<"+ | ___________ ______ _______ _______ ________ | + + "<<endl;
cout<<"+ | /____ ____// ____// ___ // ___ // ____/ | + + "<<endl;
cout<<"+ | / / / /___ / /__/ // /__/ // | | + + "<<endl;
cout<<"+ | / / / ____// ___ // ___ // /| | | + + "<<endl;
cout<<"+ | / / / /___ / /__/ // / / // / | | | + + "<<endl;
cout<<"+ | /_/ /_____//______//_/ /_//_/ |_| | + + "<<endl;
cout<<"+ | _______ ___ __ _______ _______ _______ | + + "<<endl;
cout<<"+ | / ___ // | / // _____// ____// ___ / | + + "<<endl;
cout<<"+ | / /__/ // /| |/ // /____ / | / /__/ / | + ,,, ,,, + "<<endl;
cout<<"+ | / ___ // / | // ___ // /| | / ___ / | + ( ',') ('0')/ + "<<endl;
cout<<"+ | / / / // / | // /__/ // / | | / / / / 2009 | + <|''|> /|''| + "<<endl;
cout<<"+ | /_/ /_//_/ |_//______//_/ |_|/_/ /_/.::..::.| + |__| |__| + "<<endl;
cout<<"+ |____________________________________________________| + ./ L ./ L + "<<endl;
cout<<"+ + + "<<endl;
cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "<<endl;
cout<<"\n\n";
system ("pause");
int pilih, live;
live = 10;
while(pilih != 3){
pilih = cetakmenu(live);
if ((pilih > 3) || (pilih < 1)) continue;
if (pilih==1) {
live = pilihlevel();
}
if (pilih==2) {
mulaimain(live);
}
}
}
sekian postingan kali ini
jangan lupa like commend and share yah
terima kasih
sekian postingan kali ini
jangan lupa like commend and share yah
terima kasih
0 comments:
Post a Comment