/*
*하다보니, 중간에 너무 꼬여버렸네요. ...컴터 인공지능,,,포기...
*이기면 베팅한 만큼 벌고, 지면 베팅한 값 잃고, 베팅 안하면 -1 입니다.
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(){
int sel;
int m=100; // Starting money
int bm=-1; // betting money
int dm=1; // default money
int drawBm=0;
int drawFlag=0;;
int d1,d2,d3,d4,c1,c2,c3,c4;
int win=0,lose=0,draw=0;
char bet='a';
srand(time(NULL));rand();rand();rand();
srand(rand());
while(1){
do{
printf("\n== Dice Game == #your money is :$%d, #no bet :$-%d\n",m,dm);
printf("1. Game Start\n");
printf("2. Game Score\n");
printf("3. End Game\n");
printf("> ");
scanf("%d",&sel);
}while(sel!=1&&sel!=2&&sel!=3);
while(1){
switch(sel){
case 1:
printf("\n<< Game Start >>\n\n");
d1=(rand()%6)+1;d2=(rand()%6)+1;d3=(rand()%6)+1;
d4=d1+d2+d3;
printf("Your Dice sum is : %2d\n",d4);
bet='a';
while(bet!='y'&&bet!='n'&&bet!='Y'&&bet!='N'&&bet!='q'&&bet!='Q')
{
if (drawFlag==1)
{
printf("\rBetting money is now: %d\t\t\t\n",drawBm);
}
printf("\rDo you want to bet ?(y/n) (q.quit): ");
scanf("%c",&bet); fflush(stdin);
}
if (bet=='y'||bet=='Y')
{
do
{
printf("\nYou have $ %d \n",m);
printf("How much money want to bet ? : ");
scanf("%d",&bm);
if (bm<0||bm>m)
{
printf("You have to choose between 1~%d (your money)\n",m);
}
} while(bm<0||bm>m);
c1=rand()%6+1;c2=rand()%6+1;c3=rand()%6+1;
c4=c1+c2+c3;
if (d4>c4){
printf("You Win, your dice:%d , com dice:%d\n",d4,c4);
m=(drawFlag==0)?(m+bm):(m+drawBm);
printf("Your Money is %d\n",m);
drawFlag=0;
win++;
drawBm=0;
continue;
}else if(d4<c4) {
printf("You lose, your dice:%d , com dice:%d\n",d4,c4);
m=(drawFlag==0)?(m-bm):(m-drawBm);
printf("Your Money is %d\n",m);
drawFlag=0;
lose++;
drawBm=0;
if (m<=0)
{
printf("you lose all of your money. \n");
system("pause");
exit(0);
}
continue;
}else {
printf("DRAW Game, your dice:%d , com dice:%d\n",d4,c4);
drawBm+=bm;
draw++;
drawFlag=1;
continue;
}
}
if (bet=='n'||bet=='N')
{
m=(drawFlag=0)?m-dm:m-drawBm;
printf("You lose, your money is : %d \n",m);
break;
}
break;
case 2:
printf("<< Your History >>\n");
printf(" W I N : %3d\n", win);
printf(" L O S E : %3d\n", lose);
printf(" D R A W : %3d\n", draw);
system("pause");
break;
case 3:
printf("\n Have a good day \n");
exit(0);
break;
} // switch - sel
if (bet=='q'||bet=='Q'||sel==2) {
system("cls");
break;
}
}
}// whlie(1)
return 0;
} //main
'Programming > C#' 카테고리의 다른 글
C - 지렁이 & 지뢰 찾기 게임 만들기 (0) | 2009.03.29 |
---|---|
C - 구구단 파일 입출력 (0) | 2009.03.27 |
Maximum value of each Radix ... ? (0) | 2009.03.25 |
c - Students' score management program. (0) | 2009.03.21 |
c - Baseball Game. (0) | 2009.03.20 |
댓글