Browse Source

Spiel verlassen, wenn du 0 eingibst + noch ein Test

remotes/origin/stefan
fdai7472 11 months ago
parent
commit
4dca4bb034
  1. 17
      src/main/c/Stefan/blackjack.c
  2. 2
      src/main/c/Stefan/blackjack.h
  3. 14
      src/test/c/Stefan/test_blackjack.c

17
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");
}

2
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);

14
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

Loading…
Cancel
Save