#include <stdio.h>
#include <conio.h>
#include <time.h>
void welcome();
int game(int *add_money);
int main()
{
int money=5000;
welcome();
while(1)
{
if(game(&money)==0)
{
break;
}
}
getch();
return 1;
}
void welcome()
{
printf("\n\t\tWELCOME TO CASINO\n\n");
printf("\t\t 20th May 2011\n\n");
}
void end(int money)
{
printf("The end of the game, you could live with RMB %d.",money);
return;
}
int bet(int money)
{
char ans;
while(1)
{
政治考纲 printf("Now you have Y%d\n",money);
printf("How much you want to bet:(a:10, s:20,d:30, f:40, g:50): ");
ans=getchar();
flushall();
switch(ans)
{
dyned ca 'a':
if(money-10<0)
continue;
return 1;
ca 's':money-=20;
delilah if(money-20<0)
continue;
return 2;
ca 'd':
if(money-30<10)
continue;
return 3;
ca 'f':
if(money-40<0)
continue;
return 4;
小学英语作文范文 ca 'g':
if(money-40<10)
continue;
return 5;
default:
printf("\nInvalid input!Input again!\n\n");
}
}
return -1;
}
void shuffle(int *card,int deck)
{
int i,j,index=0,round;
for(i=1;i<=deck;i++) /*initialization: value from 1 to 104,index from 0 to 103*/
{
for(j=1;j<=52;j++)
{
card[index]=j;
index++;
}
}
for(round=1;round<=200;round++) /*swap*/
{
i=rand()%(52*deck);
j=rand()%(52*deck);
index=card[i];
card[i]=card[j];
card[j]=index;
}
return;
}
void deal(int* player1,int* player2,int* card)
{
player1[0]=card[0];
player1[1]=card[2];
player2[0]=card[1];
巨型蝙蝠
player2[1]=card[3];
return;
}
void display(int card)
{
int shape=card/13+3;
int num=card%13+1;
printf("%c",shape);
if(num==1)
printf("A ");
el if(num==11)
printf("J ");
el if(num==12)
printf("Q ");
el if(num==13)
printf("K ");
el
printf("%-3d",num);
printf("");
return;
}
void displayCard(int* player1, int* player2,int choice)
{
int index=1;
if(choice==1)
printf("Dealer: XX ");
el
{
printf("Dealer: ");
happy go lucky
很久以前英文 display(player1[0]);
}
while(player1[index]!=0)
{
display(player1[index]);
index++;
}
国际接吻 index=0;
printf("\nPlayer: ");
while(player2[index]!=0)
{
display(player2[index]);
index++;
}
printf("\n");
return;
}
/*
1: player1 win/more. 2: player2 win/more. 3: Push. 4: player1 win Black Jack. 5:player2 win Black Jack;
6: player1 lo(bust).7: player2 lo(bust). 8: Black Jack: Push
*/
int checkWin(int* player1, int* player2)
{
int sum1=0,sum2=0,index=0,num;
int num1=player1[0]%13+1;
int num2=player1[1]%13+1;
int num3=player2[0]%13+1;
int num4=player2[1]%13+1;
if((num1==1&&num2>=10)||(num1>=10&&num2==1)) /*check for Black Jack*/
{
if((num3==1&&num4>=10)||(num3>=10&&num4==1))
return 8;
return 4;
}
if((num3==1&&num4>=10)||(num3>=10&&num4==1))
return 5;
while(player1[index]!=0)
{
num=player1[index]%13+1;
if(num>10)
num=10;
sum1+=num;
index++;
}
index=0;
while(player2[index]!=0)
{
num=player2[index]%13+1;
if(num>10)
num=10;
sum2+=num;
index++;
}
if(sum1>21)
if(sum2>21)一切顺利英文
return 3;
el
return 6;
if(sum2>21)
return 7;
if(sum1>sum2)
return 1;
el if(sum1<sum2)
return 2;
el
return 3;
return -1;
}
int sumN(int* player)
{
int sum=0,index=0;
while(player[index]!=0)
{
if(player[index]%13+1>10)
sum+=10;
el
sum+=player[index]%13+1;
bather index++;
}
return sum;
}
int game(int *add_money)
{
int betM,choice,index=4,win=-1,index1=2,index2=2,check=1;