|
@ -97,6 +97,7 @@ int playBJ(int bet, int balance){ |
|
|
int *dealerCardsArray = (int*) malloc(MAX_CARDS * sizeof(int)); |
|
|
int *dealerCardsArray = (int*) malloc(MAX_CARDS * sizeof(int)); |
|
|
|
|
|
|
|
|
if(dealerCardsArray){ |
|
|
if(dealerCardsArray){ |
|
|
|
|
|
// Erste Karte vom Dealer ziehen und anzeigen |
|
|
dealerCardsArray[0] = getRandCard(0); |
|
|
dealerCardsArray[0] = getRandCard(0); |
|
|
printf("\nDealer's first card: \n"); |
|
|
printf("\nDealer's first card: \n"); |
|
|
generateCardAscii(dealerCardsArray[0]); |
|
|
generateCardAscii(dealerCardsArray[0]); |
|
@ -105,45 +106,50 @@ int playBJ(int bet, int balance){ |
|
|
int *userCardsArray = (int*) malloc(MAX_CARDS * sizeof(int)); |
|
|
int *userCardsArray = (int*) malloc(MAX_CARDS * sizeof(int)); |
|
|
|
|
|
|
|
|
if(userCardsArray){ |
|
|
if(userCardsArray){ |
|
|
|
|
|
|
|
|
userCardsArray[0] = getRandCard(1); |
|
|
|
|
|
|
|
|
// Ersten 2 Karten vom Spieler ziehen und anzeigen |
|
|
printf("\nYour first two cards: \n"); |
|
|
printf("\nYour first two cards: \n"); |
|
|
|
|
|
userCardsArray[0] = getRandCard(1); |
|
|
generateCardAscii(userCardsArray[0]); |
|
|
generateCardAscii(userCardsArray[0]); |
|
|
userCardsArray[1] = getRandCard(2); |
|
|
userCardsArray[1] = getRandCard(2); |
|
|
generateCardAscii(userCardsArray[1]); |
|
|
generateCardAscii(userCardsArray[1]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Ersten zwei Karten auf Blackjack überprüfen |
|
|
if(checkForBlackjack(userCardsArray)){ |
|
|
if(checkForBlackjack(userCardsArray)){ |
|
|
|
|
|
// Wenn Blackjack, dann Gewinn berechnen und Guthaben aktualisieren |
|
|
winnings = calculateWinnings(true, bet); |
|
|
winnings = calculateWinnings(true, bet); |
|
|
return balance + winnings; |
|
|
return balance + winnings; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Spieler kann maximal 10 Karten ziehen |
|
|
for(int i = 2; i < MAX_CARDS; i++){ |
|
|
for(int i = 2; i < MAX_CARDS; i++){ |
|
|
|
|
|
|
|
|
|
|
|
// Gesamtwert vom Spieler berechnen und anzeigen |
|
|
userCardsTotal = calculateCardsTotal(userCardsArray, i); |
|
|
userCardsTotal = calculateCardsTotal(userCardsArray, i); |
|
|
|
|
|
|
|
|
printf("Your Cards Total: %d\n\n", userCardsTotal); |
|
|
printf("Your Cards Total: %d\n\n", userCardsTotal); |
|
|
|
|
|
|
|
|
|
|
|
// Gesamtwert > 21 -> Verloren |
|
|
if(userCardsTotal > 21){ |
|
|
if(userCardsTotal > 21){ |
|
|
printf("YOU BUST\n\n"); |
|
|
printf("YOU BUST\n\n"); |
|
|
|
|
|
|
|
|
|
|
|
// Spieler und Dealer Karten zurücksetzen |
|
|
free(userCardsArray); |
|
|
free(userCardsArray); |
|
|
free(dealerCardsArray); |
|
|
free(dealerCardsArray); |
|
|
return balance; |
|
|
return balance; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Spieler fragen, ob hit oder stand |
|
|
if(hit()){ |
|
|
if(hit()){ |
|
|
|
|
|
// Wenn hit, neue Karte ziehen und anzeigen |
|
|
userCardsArray[i] = getRandCard(i); |
|
|
userCardsArray[i] = getRandCard(i); |
|
|
printf("Your new card: %d\n", userCardsArray[i]); |
|
|
printf("Your new card: %d\n", userCardsArray[i]); |
|
|
generateCardAscii(userCardsArray[i]); |
|
|
generateCardAscii(userCardsArray[i]); |
|
|
} else{ |
|
|
} else{ |
|
|
|
|
|
// Wenn stand, Schleife abbrechen, nicht mehr ziehen |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Dealer kann maximal 10 Karten ziehen |
|
|
for(int i = 1; i < MAX_CARDS; i++){ |
|
|
for(int i = 1; i < MAX_CARDS; i++){ |
|
|
|
|
|
|
|
|
dealerCardsTotal = calculateCardsTotal(dealerCardsArray, i); |
|
|
dealerCardsTotal = calculateCardsTotal(dealerCardsArray, i); |
|
|