From 8f26a6f8a43a9716e5104c2d520c15f787193aaa Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Tue, 6 Feb 2024 12:39:24 +0100 Subject: [PATCH] refactoring: neue konstante Variable MAX_CARDS definiert --- src/main/c/Stefan/blackjack.c | 10 ++++++---- src/main/c/Stefan/blackjack.h | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/c/Stefan/blackjack.c b/src/main/c/Stefan/blackjack.c index deadcdf..e7db0af 100644 --- a/src/main/c/Stefan/blackjack.c +++ b/src/main/c/Stefan/blackjack.c @@ -89,13 +89,15 @@ int playBJ(int bet, int balance){ int winnings = 0; int userCardsTotal = 0, dealerCardsTotal = 0; - int *dealerCardsArray = (int*) malloc(10 * sizeof(int)); + // Array mit max 10 Karten anlegen + int *dealerCardsArray = (int*) malloc(MAX_CARDS * sizeof(int)); if(dealerCardsArray){ dealerCardsArray[0] = getRandCard(0); printf("computer rand card: %d\n", dealerCardsArray[0]); - int *userCardsArray = (int*) malloc(10 * sizeof(int)); + // Array mit max 10 Karten anlegen + int *userCardsArray = (int*) malloc(MAX_CARDS * sizeof(int)); if(userCardsArray){ @@ -111,7 +113,7 @@ int playBJ(int bet, int balance){ - for(int i = 2; i < 10; i++){ + for(int i = 2; i < MAX_CARDS; i++){ userCardsTotal = calculateCardsTotal(userCardsArray, i); @@ -134,7 +136,7 @@ int playBJ(int bet, int balance){ } - for(int i = 1; i < 10; i++){ + for(int i = 1; i < MAX_CARDS; i++){ dealerCardsTotal = calculateCardsTotal(dealerCardsArray, i); diff --git a/src/main/c/Stefan/blackjack.h b/src/main/c/Stefan/blackjack.h index f20062f..c55c744 100644 --- a/src/main/c/Stefan/blackjack.h +++ b/src/main/c/Stefan/blackjack.h @@ -4,6 +4,7 @@ #include #define ANZ_MOEGLICHE_KARTEN 13 +#define MAX_CARDS 10 int blackjack(); void welcomeMessageBJ();