|
|
@ -89,7 +89,6 @@ int getRandCard(int offset){ |
|
|
|
|
|
|
|
|
|
|
|
int playBJ(int bet, int balance){ |
|
|
|
|
|
|
|
int winnings = 0; |
|
|
|
int userCardsTotal = 0, dealerCardsTotal = 0; |
|
|
|
|
|
|
@ -154,6 +153,7 @@ int playBJ(int bet, int balance){ |
|
|
|
|
|
|
|
dealerCardsTotal = calculateCardsTotal(dealerCardsArray, i); |
|
|
|
|
|
|
|
// Wenn Dealer total < 17, muss er noch eine Karte ziehen |
|
|
|
if(dealerCardsTotal < 17){ |
|
|
|
dealerCardsArray[i] = getRandCard(i); |
|
|
|
printf("Dealer Card: %d\n", dealerCardsArray[i]); |
|
|
@ -162,35 +162,36 @@ int playBJ(int bet, int balance){ |
|
|
|
} |
|
|
|
printf("Dealer Cards Total: %d\n", dealerCardsTotal); |
|
|
|
|
|
|
|
// Wenn Dealer total > 17 und <= 21, dann keine Karte mehr ziehen |
|
|
|
if(dealerCardsTotal >= 17 && dealerCardsTotal <= 21){ |
|
|
|
// Überprüfen, wer gewonnen hat und entsprechend Gewinn berechnen |
|
|
|
if(calculateIfYouWon(userCardsTotal, dealerCardsTotal)){ |
|
|
|
winnings = calculateWinnings(false, bet); |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
// Wenn dealer total > 21, dann hat der Spieler gewonnen + Gewinn berechnen |
|
|
|
if(dealerCardsTotal > 21){ |
|
|
|
printf("DEALER BUST\n\n"); |
|
|
|
winnings = calculateWinnings(false, bet); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Speicher wieder freigeben/zurücksetzen |
|
|
|
free(userCardsArray); |
|
|
|
} |
|
|
|
|
|
|
|
// Speicher wieder freigeben/zurücksetzen |
|
|
|
free(dealerCardsArray); |
|
|
|
} |
|
|
|
|
|
|
|
return balance + winnings; |
|
|
|
} |
|
|
|
|
|
|
|
// Wenn die ersten beiden Karten in Summe den Wert 21 haben, heißt das Blackjack |
|
|
|
bool checkForBlackjack(int userCardArray[]){ |
|
|
|
if(userCardArray[0] + userCardArray[1] == 21){ |
|
|
|
printf("BLACKJACK!\n\n"); |
|
|
@ -200,10 +201,8 @@ bool checkForBlackjack(int userCardArray[]){ |
|
|
|
} |
|
|
|
|
|
|
|
bool hit(){ |
|
|
|
|
|
|
|
int answer; |
|
|
|
printf("Hit (1) or stand (2): "); |
|
|
|
scanf("%d", &answer); |
|
|
|
int answer = userInputBJ(); |
|
|
|
|
|
|
|
if(answer != 1){ |
|
|
|
printf("You stand.\n\n"); |
|
|
|