diff --git a/src/main/c/Stefan/blackjack.c b/src/main/c/Stefan/blackjack.c index b648de5..52cdba1 100644 --- a/src/main/c/Stefan/blackjack.c +++ b/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; } \ No newline at end of file diff --git a/src/main/c/Stefan/blackjack.h b/src/main/c/Stefan/blackjack.h index c55c744..2e610b2 100644 --- a/src/main/c/Stefan/blackjack.h +++ b/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 \ No newline at end of file diff --git a/src/test/c/Stefan/test_blackjack.c b/src/test/c/Stefan/test_blackjack.c index cd067cf..675acac 100644 --- a/src/test/c/Stefan/test_blackjack.c +++ b/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); -} \ No newline at end of file +} + +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); + +}