1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
int main(void)
{
int play=gamesWon+gamesLost;
srand((unsigned)time(NULL));
display_details();
do
{
char answer,junk;
printf("\n\n\n");
printf("Would you like to play craps [y|n]? ");
answer=getchar();
junk=getchar();
printf("\n\n\n");
if(answer=='y' || answer=='Y')
play_craps();
}while(answer=='y' || answer=='Y');
return;
}
void play_craps()
{
int play=gamesWon+gamesLost;
do
{
srand((unsigned)time(NULL));
printf("+-------------------------------------+\n\n");
printf("Number of chips: %d\n\n", chipBalance);
printf("\nPlace your bet: ");
scanf("%d", &bet);
printf("\n\n");
while(bet < 0 || bet > chipBalance)
{
printf("+---------------------------------------+");
printf("\nSorry, you can only bet what you have (0-%d)!\n", chipBalance);
printf("\nPlace your bet: ");
scanf("%d", &bet);
printf("\n\n");
}
die_1 = 1+ rand() %6;
die_2 = 1+ rand() %6;
roll = die_1 + die_2;
printf("\nYou rolled %d + %d = %d\n\n",die_1,die_2, roll);
if( roll==4 || roll==5 || roll==6 || roll ==8 || roll==9 || roll==10)
printf("Point to make is: %d\n\n", roll);
if(play>1)
printf("Point to make is: %d\n\n", roll);
if(roll==7 || roll==11)
{
chipBalance+=bet;
gamesWon++;
printf("\n* * * You Win! * * *\n\n");
printf("\n You now have %d chips!\n\n", chipBalance);
printf("+-------------------------------------+\n\n\n");
printf("\n Play Again [y|n]? ");
answer=getchar();
junk=getchar();
}
else if(roll==2 || roll==3 || roll==12)
{
chipBalance-=bet;
gamesLost++;
printf("\n* * * You Lose! * * *\n\n");
printf("\n You now have %d chips!\n\n", chipBalance);
printf("+-------------------------------------+\n\n\n");
if (chipBalance<=0)
{gameOver();return;}
else if (chipBalance > 0 )
printf("\n Play Again? ");
answer=getchar();
junk=getchar();
}
else
{
do
{
play=gamesWon+gamesLost;
die_3= 1+ rand() % 6;
die_4= 1+ rand() % 6;
roll_2=die_3 + die_4;
printf("\n|--> rolled: %d + %d = %d\n",die_3, die_4, roll_2);
if(roll_2==roll)
{
chipBalance+=bet;
gamesWon++;
printf("\n* * * You Win! * * *\n\n");
printf("\n You now have %d chips!\n\n", chipBalance);
printf("\n+-------------------------------------+\n\n");
printf("\n Play Again? ");
answer=getchar();
junk=getchar();
}
}while(roll_2 != 7);
chipBalance-=bet;
gamesLost++;
printf("\n* * * You Lose! * * *\n\n");
printf("\nYou now have %d chips!\n\n", chipBalance);
printf("+-------------------------------------+\n\n");
if (chipBalance<=0)
{gameOver();}
if (chipBalance > 0 )
printf("\nPlay Again? ");
answer=getchar();
junk=getchar();
}
}while (answer=='y' || answer=='Y');
gameStats();return;
}
|