You are on page 1of 8

/* PROGRAM BLACK JACK *\

#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include<dos.h>
int i,j,k;
struct data1
{
int nilai[2];
int tipe;
int tipe2;
}kartu[52],temp;
struct data2
{
int no_kartu[5];
int jml_kartu;
int jumlah[2];
long money;
long bet;
char nama[50];
}player1,bandar;
void judul()
{
textcolor(11);
gotoxy(15,5); cprintf("*** * ** *** * * **** ** *** * *");
gotoxy(15,6); cprintf("* * * * * * * * * * * * * * ");
gotoxy(15,7); cprintf("***%c * * * * ** * * * * ** ",255);
gotoxy(15,
; cprintf("* * * **** * * * * * **** * * * ");
gotoxy(15,9); cprintf("*** **** * * *** * * **** * * *** * *");
}
void border()
{
int r,s,t;
textcolor(11);
for(r=1;r<81;r++)
{gotoxy(r,1);cprintf("*"); gotoxy(r,24);cprintf("*");}
for(r=2;r<24;r++)
{gotoxy(1,r);cprintf("*"); gotoxy(80,r);cprintf("*");}
}
void menu_utama()
{
textcolor(WHITE);
gotoxy(35,11); cprintf("Menu :");
gotoxy(35,12); cprintf("1.Deal");
gotoxy(35,13); cprintf("2.Bet");
gotoxy(35,14); cprintf("3.New Game");
gotoxy(35,15); cprintf("4.Exit");
}
void menu_game()
{
textcolor(WHITE);
gotoxy(70,11); cprintf("1.Hit");
gotoxy(70,12); cprintf("2.Double");
gotoxy(70,13); cprintf("3.Stand");
}
void kocok_kartu()
{
int a,b;
randomize();
for(a=0;a<52;a++)
{
b=random(52-a);
temp = kartu[b];
kartu[b] = kartu[51-a];
kartu[51-a] = temp;
}
}
void buat_kartu()
{

int a,b,c;
for(a=0;a<13;a++)
{
if (a==0)
{
kartu[a].nilai[0] = 1;
kartu[a].nilai[1] = 11;
kartu[a].tipe = 3;
kartu[a+13].nilai[0] = 1;
kartu[a+13].nilai[1] = 11;
kartu[a+13].tipe = 4;
kartu[a+26].nilai[0] = 1;
kartu[a+26].nilai[1] = 11;
kartu[a+26].tipe = 5;
kartu[a+39].nilai[0] = 1;
kartu[a+39].nilai[1] = 11;
kartu[a+39].tipe = 6;
}
else if (a >=1 && a<=9)
{
kartu[a].nilai[0] = a + 1;
kartu[a].nilai[1] = a + 1;
kartu[a].tipe = 3;
kartu[a+13].nilai[0] = a + 1;
kartu[a+13].nilai[1] = a + 1;
kartu[a+13].tipe = 4;
kartu[a+26].nilai[0] = a + 1;
kartu[a+26].nilai[1] = a + 1;
kartu[a+26].tipe = 5;
kartu[a+39].nilai[0] = a + 1;
kartu[a+39].nilai[1] = a + 1;
kartu[a+39].tipe = 6;
}
else
{
kartu[a].nilai[0] = 10;
kartu[a].nilai[1] = 10;
kartu[a].tipe = 3;
kartu[a+13].nilai[0] = 10;
kartu[a+13].nilai[1] = 10;
kartu[a+13].tipe = 4;
kartu[a+26].nilai[0] = 10;
kartu[a+26].nilai[1] = 10;
kartu[a+26].tipe = 5;
kartu[a+39].nilai[0] = 10;
kartu[a+39].nilai[1] = 10;
kartu[a+39].tipe = 6;
}
kartu[a].tipe2=a+1;
kartu[a+13].tipe2=a+1;
kartu[a+26].tipe2=a+1;
kartu[a+39].tipe2=a+1;
}
}
void gambar_kartu(int x,int y, int tipe, int tipe2)
{
switch(tipe2)
{
case 1 :
{
if(tipe==3||tipe==4) textcolor(12);
else textcolor(BLACK);
gotoxy(x,y); cprintf("%c%c%c%c%c%c%c",201,205,205,205,205,205,187);
gotoxy(x,y+1); cprintf("%c %c %c",186,tipe,186);
gotoxy(x,y+2); cprintf("%c %c %c %c",186,tipe,tipe,186);
gotoxy(x,y+3); cprintf("%c %c %c %c",186,tipe,tipe,186);
gotoxy(x,y+4); cprintf("%c %c%c%c %c",186,tipe,tipe,tipe,186);
gotoxy(x,y+5); cprintf("%c %c %c %c",186,tipe,tipe,186);
gotoxy(x,y+6); cprintf("%c%c%c%c%c%c%c",200,205,205,205,205,205,188);
break;
}
case 2 :
{
if(tipe==3||tipe==4) textcolor(12);
else textcolor(BLACK);
gotoxy(x,y); cprintf("%c%c%c%c%c%c%c",201,205,205,205,205,205,187);
gotoxy(x,y+1); cprintf("%c %c",186,186);
gotoxy(x,y+2); cprintf("%c %c",186,186);

gotoxy(x,y+3); cprintf("%c %c %c %c",186,tipe,tipe,186);


gotoxy(x,y+4); cprintf("%c %c",186,186);
gotoxy(x,y+5); cprintf("%c %c",186,186);
gotoxy(x,y+6); cprintf("%c%c%c%c%c%c%c",200,205,205,205,205,205,188);
break;
}
case 3 :
{
if(tipe==3||tipe==4) textcolor(12);
else textcolor(BLACK);
gotoxy(x,y); cprintf("%c%c%c%c%c%c%c",201,205,205,205,205,205,187);
gotoxy(x,y+1); cprintf("%c %c %c",186,tipe,186);
gotoxy(x,y+2); cprintf("%c %c",186,186);
gotoxy(x,y+3); cprintf("%c %c %c",186,tipe,186);
gotoxy(x,y+4); cprintf("%c %c",186,186);
gotoxy(x,y+5); cprintf("%c %c %c",186,tipe,186);
gotoxy(x,y+6); cprintf("%c%c%c%c%c%c%c",200,205,205,205,205,205,188);
break;
}
case 4 :
{
if(tipe==3||tipe==4) textcolor(12);
else textcolor(BLACK);
gotoxy(x,y); cprintf("%c%c%c%c%c%c%c",201,205,205,205,205,205,187);
gotoxy(x,y+1); cprintf("%c %c",186,186);
gotoxy(x,y+2); cprintf("%c %c %c %c",186,tipe,tipe,186);
gotoxy(x,y+3); cprintf("%c %c",186,186);
gotoxy(x,y+4); cprintf("%c %c %c %c",186,tipe,tipe,186);
gotoxy(x,y+5); cprintf("%c %c",186,186);
gotoxy(x,y+6); cprintf("%c%c%c%c%c%c%c",200,205,205,205,205,205,188);
break;
}
case 5 :
{
if(tipe==3||tipe==4) textcolor(12);
else textcolor(BLACK);
gotoxy(x,y); cprintf("%c%c%c%c%c%c%c",201,205,205,205,205,205,187);
gotoxy(x,y+1); cprintf("%c %c",186,186);
gotoxy(x,y+2); cprintf("%c %c %c %c",186,tipe,tipe,186);
gotoxy(x,y+3); cprintf("%c %c %c",186,tipe,186);
gotoxy(x,y+4); cprintf("%c %c %c %c",186,tipe,tipe,186);
gotoxy(x,y+5); cprintf("%c %c",186,186);
gotoxy(x,y+6); cprintf("%c%c%c%c%c%c%c",200,205,205,205,205,205,188);
break;
}
case 6 :
{
if(tipe==3||tipe==4) textcolor(12);
else textcolor(BLACK);
gotoxy(x,y); cprintf("%c%c%c%c%c%c%c",201,205,205,205,205,205,187);
gotoxy(x,y+1); cprintf("%c %c %c %c",186,tipe,tipe,186);
gotoxy(x,y+2); cprintf("%c %c",186,186);
gotoxy(x,y+3); cprintf("%c %c %c %c",186,tipe,tipe,186);
gotoxy(x,y+4); cprintf("%c %c",186,186);
gotoxy(x,y+5); cprintf("%c %c %c %c",186,tipe,tipe,186);
gotoxy(x,y+6); cprintf("%c%c%c%c%c%c%c",200,205,205,205,205,205,188);
break;
}
case 7 :
{
if(tipe==3||tipe==4) textcolor(12);
else textcolor(BLACK);
gotoxy(x,y); cprintf("%c%c%c%c%c%c%c",201,205,205,205,205,205,187);
gotoxy(x,y+1); cprintf("%c %c %c %c",186,tipe,tipe,186);
gotoxy(x,y+2); cprintf("%c %c %c",186,tipe,186);
gotoxy(x,y+3); cprintf("%c %c %c %c",186,tipe,tipe,186);
gotoxy(x,y+4); cprintf("%c %c",186,186);
gotoxy(x,y+5); cprintf("%c %c %c %c",186,tipe,tipe,186);
gotoxy(x,y+6); cprintf("%c%c%c%c%c%c%c",200,205,205,205,205,205,188);
break;
}
case 8 :
{
if(tipe==3||tipe==4) textcolor(12);
else textcolor(BLACK);
gotoxy(x,y); cprintf("%c%c%c%c%c%c%c",201,205,205,205,205,205,187);
gotoxy(x,y+1); cprintf("%c %c %c %c",186,tipe,tipe,186);
gotoxy(x,y+2); cprintf("%c %c %c",186,tipe,186);
gotoxy(x,y+3); cprintf("%c %c %c %c",186,tipe,tipe,186);
gotoxy(x,y+4); cprintf("%c %c %c",186,tipe,186);

gotoxy(x,y+5); cprintf("%c %c %c %c",186,tipe,tipe,186);


gotoxy(x,y+6); cprintf("%c%c%c%c%c%c%c",200,205,205,205,205,205,188);
break;
}
case 9 :
{
if(tipe==3||tipe==4) textcolor(12);
else textcolor(BLACK);
gotoxy(x,y); cprintf("%c%c%c%c%c%c%c",201,205,205,205,205,205,187);
gotoxy(x,y+1); cprintf("%c %c %c %c",186,tipe,tipe,186);
gotoxy(x,y+2); cprintf("%c %c %c %c",186,tipe,tipe,186);
gotoxy(x,y+3); cprintf("%c %c %c",186,tipe,186);
gotoxy(x,y+4); cprintf("%c %c %c %c",186,tipe,tipe,186);
gotoxy(x,y+5); cprintf("%c %c %c %c",186,tipe,tipe,186);
gotoxy(x,y+6); cprintf("%c%c%c%c%c%c%c",200,205,205,205,205,205,188);
break;
}
case 10 :
{
if(tipe==3||tipe==4) textcolor(12);
else textcolor(BLACK);
gotoxy(x,y); cprintf("%c%c%c%c%c%c%c",201,205,205,205,205,205,187);
gotoxy(x,y+1); cprintf("%c %c %c %c",186,tipe,tipe,186);
gotoxy(x,y+2); cprintf("%c %c %c %c",186,tipe,tipe,186);
gotoxy(x,y+3); cprintf("%c %c %c %c",186,tipe,tipe,186);
gotoxy(x,y+4); cprintf("%c %c %c %c",186,tipe,tipe,186);
gotoxy(x,y+5); cprintf("%c %c %c %c",186,tipe,tipe,186);
gotoxy(x,y+6); cprintf("%c%c%c%c%c%c%c",200,205,205,205,205,205,188);
break;
}
case 11 :
{
if(tipe==3||tipe==4) textcolor(12);
else textcolor(BLACK);
gotoxy(x,y); cprintf("%c%c%c%c%c%c%c",201,205,205,205,205,205,187);
gotoxy(x,y+1); cprintf("%c %c%c%c %c",186,tipe,tipe,tipe,186);
gotoxy(x,y+2); cprintf("%c %c %c",186,tipe,186);
gotoxy(x,y+3); cprintf("%c %c %c",186,tipe,186);
gotoxy(x,y+4); cprintf("%c %c %c %c",186,tipe,tipe,186);
gotoxy(x,y+5); cprintf("%c %c%c%c %c",186,tipe,tipe,tipe,186);
gotoxy(x,y+6); cprintf("%c%c%c%c%c%c%c",200,205,205,205,205,205,188);
break;
}
case 12 :
{
if(tipe==3||tipe==4) textcolor(12);
else textcolor(BLACK);
gotoxy(x,y); cprintf("%c%c%c%c%c%c%c",201,205,205,205,205,205,187);
gotoxy(x,y+1); cprintf("%c %c%c %c",186,tipe,tipe,186);
gotoxy(x,y+2); cprintf("%c%c %c %c",186,tipe,tipe,186);
gotoxy(x,y+3); cprintf("%c%c %c %c",186,tipe,tipe,186);
gotoxy(x,y+4); cprintf("%c%c %c %c",186,tipe,tipe,186);
gotoxy(x,y+5); cprintf("%c %c%c %c%c",186,tipe,tipe,tipe,186);
gotoxy(x,y+6); cprintf("%c%c%c%c%c%c%c",200,205,205,205,205,205,188);
break;
}
case 13 :
{
if(tipe==3||tipe==4) textcolor(12);
else textcolor(BLACK);
gotoxy(x,y); cprintf("%c%c%c%c%c%c%c",201,205,205,205,205,205,187);
gotoxy(x,y+1); cprintf("%c%c %c %c",186,tipe,tipe,186);
gotoxy(x,y+2); cprintf("%c%c %c %c",186,tipe,tipe,186);
gotoxy(x,y+3); cprintf("%c%c%c %c",186,tipe,tipe,186);
gotoxy(x,y+4); cprintf("%c%c %c %c",186,tipe,tipe,186);
gotoxy(x,y+5); cprintf("%c%c %c %c",186,tipe,tipe,186);
gotoxy(x,y+6); cprintf("%c%c%c%c%c%c%c",200,205,205,205,205,205,188);
break;
}
default :
{
textcolor(12);
gotoxy(x,y); cprintf("%c%c%c%c%c%c%c",201,205,205,205,205,205,187);
gotoxy(x,y+1); cprintf("%c%c%c%c%c%c%c",186,178,178,178,178,178,186);
gotoxy(x,y+2); cprintf("%c%c%c%c%c%c%c",186,178,178,178,178,178,186);
gotoxy(x,y+3); cprintf("%c%c%c%c%c%c%c",186,178,178,178,178,178,186);
gotoxy(x,y+4); cprintf("%c%c%c%c%c%c%c",186,178,178,178,178,178,186);
gotoxy(x,y+5); cprintf("%c%c%c%c%c%c%c",186,178,178,178,178,178,186);
gotoxy(x,y+6); cprintf("%c%c%c%c%c%c%c",200,205,205,205,205,205,188);
}

}
}
void tambah_kartu_player()
{
int b;
player1.jml_kartu++;j++;
player1.no_kartu[player1.jml_kartu]=kartu[i].tipe2;
for(b=0;b<2;b++)
{
player1.jumlah[b]=player1.jumlah[b]+kartu[i].nilai[b];
}
gambar_kartu((j-1)*10 + 5,15,kartu[i].tipe,kartu[i].tipe2);
sleep(1);
i++;
}
void tambah_kartu_bandar()
{
int b;
bandar.jml_kartu++; k++;
bandar.no_kartu[bandar.jml_kartu]=kartu[i].tipe2;
for(b=0;b<2;b++)
{
bandar.jumlah[b]=bandar.jumlah[b]+kartu[i].nilai[b];
}
gambar_kartu((k-1)*10 + 5,5,kartu[i].tipe,kartu[i].tipe2);
sleep(1);
i++;
}
void status()
{
if(player1.jumlah[0]==player1.jumlah[1])
{
gotoxy(3,13);
textcolor(WHITE);
cprintf("%s's card %d Bet : %ld Money : %ld",player1.nama,player1.jumlah[0],player1.bet,player1.money);
}
else
{
gotoxy(3,13);
textcolor(WHITE);
cprintf("%s's card %d or %d Bet : %ld Money : %ld",player1.nama,player1.jumlah[0],player1.jumlah[1],player1.bet,player1.money);
}
}
void kalahpl()
{
textcolor(WHITE);
gotoxy(3,22);cprintf(" ");
gotoxy(3,22);cprintf("YoU LoSe!!! YouR CaRd %d !!!",player1.jumlah[0]);
}
void bet()
{
do
{
gotoxy(10,20); cprintf("Insert your bet ($50 - $%ld) : ",player1.money);
gotoxy(10,20); cprintf("Insert your bet ($50 - $%ld) : ",player1.money);
scanf("%ld",&player1.bet);
}
while(player1.bet<50||player1.bet>player1.money);
}
main()
{
int a,b,c,d,e=0,m=0;
char tekan,tombol;
clrscr();
do
{
textcolor(WHITE);
clrscr();judul();border();
player1.money=5000; player1.bet=50;
textcolor(WHITE);
gotoxy(23,19); cprintf("Insert your name : ");
scanf("%s",player1.nama);
bet();
do
{

clrscr();
buat_kartu();
judul();
border();
menu_utama();
if (player1.money<player1.bet) player1.bet=player1.money;
m=0;
if (player1.money < player1.bet*2) m=1;
if (player1.money<50) {gotoxy(10,21); cprintf("GAME OVER!!! PreSs aNy Key To pLaY aGaiN oR '4' To eXiT!!!"); tekan=getch(); break;}
textcolor(WHITE);
gotoxy(3,3); cprintf("%s's Money = %ld",player1.nama,player1.money);
gotoxy(57,3); cprintf("%s's Bet = %ld",player1.nama,player1.bet);
tekan=getch();
switch(tekan)
{
case '1' :
{
clrscr();
border();
kocok_kartu();
i=0;
j=0;
k=0;
for(b=0;b<2;b++)
{
bandar.jumlah[b]=0;
player1.jumlah[b]=0;
}
bandar.jml_kartu=0;
player1.jml_kartu=0;
bandar.jml_kartu++; k++;
bandar.no_kartu[bandar.jml_kartu]=kartu[i].tipe2;
for(b=0;b<2;b++)
{
bandar.jumlah[b]=bandar.jumlah[b]+kartu[i].nilai[b];
}
gambar_kartu((k-1)*10 +5,5,0,0);
sleep(1);i++;
tambah_kartu_player();
tambah_kartu_bandar();
tambah_kartu_player();
menu_game();
c = 0; d=0; e=0;
do
{
status();
if (bandar.jumlah[1]==21)
{
gambar_kartu(5,5,kartu[0].tipe,kartu[0].tipe2);
player1.money=player1.money - player1.bet;
gotoxy(3,22);
textcolor(WHITE);
cprintf("YoU LoSe!!! DeaLer BlaCkJacK!!! ");
d=1;
break;
}
else if(player1.jumlah[1]==21||player1.jumlah[1]==22)
{
if (j<3)
{
player1.money=player1.money + (player1.bet*2);
gotoxy(3,22);
textcolor(WHITE);
if(player1.jumlah[1]==21)
cprintf("BLACK JACK!!! YoU WiN");
else
cprintf("YoU GoT DoubLe Ace !!!YoU WiN");
d=1;
break;
}
}
tombol=getch();
if (tombol == '1' )
{
tambah_kartu_player();
c=1;
if (player1.jumlah[0]>21||player1.jumlah[1]>21)
{

if(player1.jumlah[0]>21)
{
player1.money=player1.money-player1.bet;
kalahpl();
d=1;
break;
}
if (j==5||player1.jumlah[0]==21) break;
else continue;
}
if (j==5) break;
}
else if (tombol == '2')
{
if (c==1) continue;
else if (m==1)
{
textcolor(WHITE); gotoxy(3,22);
cprintf("YoU dOn'T HaVe Enough Money to DoUbLe uR BeT!!!");
continue;
}
else
{
player1.bet *=2; e=1;
tambah_kartu_player();
if(player1.jumlah[0]>21)
{
d=1; player1.money=player1.money-player1.bet;
kalahpl();
}
break;
}
}
}
while(tombol!='3');
if(d==0)
{
status();
gambar_kartu(5,5,kartu[0].tipe,kartu[0].tipe2);
while (bandar.jumlah[0]<player1.jumlah[0]&&bandar.jumlah[0]<player1.jumlah[1]||bandar.jumlah[1]<player1.jumlah[0]&&bandar.jumlah[1]<player1.jumlah[1])
{
if(bandar.jumlah[1]>player1.jumlah[0] && bandar.jumlah[1]>player1.jumlah[1] && bandar.jumlah[1]<=21 && i<=5) break;
tambah_kartu_bandar();
sleep(1);
}
if (j==5)
{
if(i==5)
{
if(bandar.jumlah[0]<21)
{
player1.money=player1.money-player1.bet;
textcolor(WHITE);
gotoxy(3,22);cprintf(" ");
gotoxy(3,22);cprintf("You Lose!!! Dealer card %d !!! ",bandar.jumlah[0]);
}
}
else
{
player1.money=player1.money + player1.bet*2;
textcolor(WHITE);
gotoxy(3,22);cprintf(" ");
gotoxy(3,22);cprintf("You Win!!! Dealer card %d !!! ",bandar.jumlah[0]);
}
}
else if (bandar.jumlah[0]>=player1.jumlah[0]||bandar.jumlah[1]>=player1.jumlah[1])
{
if(bandar.jumlah[1]>21&&bandar.jumlah[0]>21)
{
player1.money=player1.money+player1.bet;
textcolor(WHITE);
gotoxy(3,22);cprintf(" ");
gotoxy(3,22);cprintf("You Win!!! Dealer card %d !!! ",bandar.jumlah[0]);
}
else

{
player1.money=player1.money-player1.bet;
textcolor(WHITE);
gotoxy(3,22);cprintf(" ");
gotoxy(3,22);
if(bandar.jumlah[1]<21)
cprintf("You Lose!!! Dealer card %d !!! ",bandar.jumlah[1]);
else cprintf("You Lose!!! Dealer card %d !!! ",bandar.jumlah[0]);
}
}
}
status();
if(e==1) player1.bet/=2; e=0;
getch();
break;
}
case '2' :
{
bet();
continue;
}
}
}
while(tekan!='3'&&tekan!='4');
}
while(tekan!='4');
}

You might also like