Browse Source

Implementierung Karte zu ASCII art konvertieren + Test

remotes/origin/stefan
fdai7472 11 months ago
parent
commit
a3e2b5a9e2
  1. 30
      src/main/c/Stefan/blackjack.c
  2. 1
      src/main/c/Stefan/blackjack.h
  3. 16
      src/test/c/Stefan/test_blackjack.c

30
src/main/c/Stefan/blackjack.c

@ -245,4 +245,34 @@ void welcomeMessageBJ(){
"|_.__/|_|\\__,_|\\___|_|\\_\\ |\\__,_|\\___|_|\\_\\\n"
" _/ | \n"
" |__/ \n\n");
}
char generateCardAscii(int cardValue){
char cardValueAsChar, possibleZero = ' ';
if(cardValue == 11){
cardValueAsChar = 'A';
} else if(cardValue == 10){
srand(time(NULL));
int randomValue = rand()%4;
switch(randomValue){
case(0): cardValueAsChar = 'J'; break;
case(1): cardValueAsChar = 'Q'; break;
case(2): cardValueAsChar = 'K'; break;
case(4): cardValueAsChar = '1';
possibleZero = '0'; break;
default: cardValueAsChar = 'E'; break; // ERROR
}
} else {
cardValueAsChar = cardValue + '0';
}
printf(" ___\n"
" |%c%c |\n"
" | |\n"
" |___| \n\n", cardValueAsChar, possibleZero);
return cardValueAsChar;
}

1
src/main/c/Stefan/blackjack.h

@ -18,5 +18,6 @@ int calculateCardsTotal(int cardsArray[], int len);
int calculateWinnings(bool blackjack, int bet);
bool hit();
bool calculateIfYouWon(int userCardsTotal, int computerCardsTotal);
char generateCardAscii(int cardValue);
#endif // BLACKJACK_H

16
src/test/c/Stefan/test_blackjack.c

@ -184,4 +184,18 @@ void test_calculate_if_you_won_20_vs_21() {
//assert
TEST_ASSERT_FALSE(result);
}
}
void test_generate_char_for_card_2() {
//arrange
int cardValue = 2;
char expected_result = '2';
//act
char actual_result = generateCardAscii(cardValue);
//assert
TEST_ASSERT_EQUAL_CHAR(expected_result, actual_result);
}
Loading…
Cancel
Save