diff --git a/src/main/c/Stefan/blackjack.c b/src/main/c/Stefan/blackjack.c index 9c40be9..4af7f15 100644 --- a/src/main/c/Stefan/blackjack.c +++ b/src/main/c/Stefan/blackjack.c @@ -8,14 +8,20 @@ int blackjack(){ printf("Welcome to Blackjack \n\n"); + bool exit = false; + bool *exitPtr = &exit; int balance = getBalanceBJ(); while(balance > 0){ printf("Aktuelles Guthaben: %d\n", balance); - int bet = getBetBJ(balance); + int bet = getBetBJ(balance, exitPtr); + if(exit) { + return -1; + } + balance -= bet; - playBJ(bet, balance); + balance = playBJ(bet, balance); } return 0; @@ -24,18 +30,21 @@ int blackjack(){ int getBalanceBJ(){ printf("Guthaben einwerfen: "); int balance = userInputBJ(); - printf("Dein Guthaben: %d\n", balance); return balance; } -int getBetBJ(int balance){ +int getBetBJ(int balance, bool *exitPtr){ while(1){ + printf("\nGib (0) ein, um Blackjack zu verlassen.\n"); printf("Wetteinsatz: "); int bet = userInputBJ(); if(bet <= balance && bet > 0){ return bet; + } else if(bet == 0) { + *exitPtr = true; + break; } else { printf("Ungueltige Eingabe!\n"); } diff --git a/src/main/c/Stefan/blackjack.h b/src/main/c/Stefan/blackjack.h index adc9a15..5b2bc79 100644 --- a/src/main/c/Stefan/blackjack.h +++ b/src/main/c/Stefan/blackjack.h @@ -5,7 +5,7 @@ int blackjack(); int getBalanceBJ(); -int getBetBJ(int balance); +int getBetBJ(int balance, bool *exitPtr); int userInputBJ(); int getRandCard(); int playBJ(int bet, int balance); diff --git a/src/test/c/Stefan/test_blackjack.c b/src/test/c/Stefan/test_blackjack.c index 25d5957..a31db25 100644 --- a/src/test/c/Stefan/test_blackjack.c +++ b/src/test/c/Stefan/test_blackjack.c @@ -102,6 +102,20 @@ void test_cards_ace_10_total_equals_21() { } +void test_cards_ace_ace_9_total_equals_21() { + + //arrange + int userCards[] = { 11, 11, 9}; + int expected_result = 21; + + //act + int actual_result = calculateCardsTotal(userCards, 3); + + //assert + TEST_ASSERT_EQUAL_INT(expected_result, actual_result); + +} + void test_blackjack_bet_equals_10() { //arrange