Browse Source

Karte ASCII wird jedes mal angezeigt, wenn eine neue Karte gezogen wird + Test

remotes/origin/stefan
fdai7472 11 months ago
parent
commit
c8ec59c392
  1. 6
      src/main/c/Stefan/blackjack.c
  2. 14
      src/test/c/Stefan/test_blackjack.c

6
src/main/c/Stefan/blackjack.c

@ -98,6 +98,7 @@ int playBJ(int bet, int balance){
if(dealerCardsArray){ if(dealerCardsArray){
dealerCardsArray[0] = getRandCard(0); dealerCardsArray[0] = getRandCard(0);
printf("computer rand card: %d\n", dealerCardsArray[0]); printf("computer rand card: %d\n", dealerCardsArray[0]);
generateCardAscii(dealerCardsArray[0]);
// Array mit max 10 Karten anlegen // Array mit max 10 Karten anlegen
int *userCardsArray = (int*) malloc(MAX_CARDS * sizeof(int)); int *userCardsArray = (int*) malloc(MAX_CARDS * sizeof(int));
@ -106,8 +107,11 @@ int playBJ(int bet, int balance){
userCardsArray[0] = getRandCard(1); userCardsArray[0] = getRandCard(1);
printf("user rand card: %d\n", userCardsArray[0]); printf("user rand card: %d\n", userCardsArray[0]);
generateCardAscii(userCardsArray[0]);
userCardsArray[1] = getRandCard(2); userCardsArray[1] = getRandCard(2);
printf("user rand card: %d\n", userCardsArray[1]); printf("user rand card: %d\n", userCardsArray[1]);
generateCardAscii(userCardsArray[1]);
if(checkForBlackjack(userCardsArray)){ if(checkForBlackjack(userCardsArray)){
winnings = calculateWinnings(true, bet); winnings = calculateWinnings(true, bet);
@ -133,6 +137,7 @@ int playBJ(int bet, int balance){
if(hit()){ if(hit()){
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]);
} else{ } else{
break; break;
} }
@ -146,6 +151,7 @@ int playBJ(int bet, int balance){
if(dealerCardsTotal < 17){ if(dealerCardsTotal < 17){
dealerCardsArray[i] = getRandCard(i); dealerCardsArray[i] = getRandCard(i);
printf("Dealer Card: %d\n", dealerCardsArray[i]); printf("Dealer Card: %d\n", dealerCardsArray[i]);
generateCardAscii(dealerCardsArray[i]);
dealerCardsTotal = calculateCardsTotal(dealerCardsArray, i + 1); dealerCardsTotal = calculateCardsTotal(dealerCardsArray, i + 1);
} }
printf("Dealer Cards Total: %d\n", dealerCardsTotal); printf("Dealer Cards Total: %d\n", dealerCardsTotal);

14
src/test/c/Stefan/test_blackjack.c

@ -199,3 +199,17 @@ void test_generate_char_for_card_2() {
TEST_ASSERT_EQUAL_CHAR(expected_result, actual_result); TEST_ASSERT_EQUAL_CHAR(expected_result, actual_result);
} }
void test_generate_char_for_card_ace() {
//arrange
int cardValue = 11;
char expected_result = 'A';
//act
char actual_result = generateCardAscii(cardValue);
//assert
TEST_ASSERT_EQUAL_CHAR(expected_result, actual_result);
}
Loading…
Cancel
Save