diff --git a/src/main/c/Stefan/blackjack.c b/src/main/c/Stefan/blackjack.c index a4878e7..2268373 100644 --- a/src/main/c/Stefan/blackjack.c +++ b/src/main/c/Stefan/blackjack.c @@ -1,8 +1,7 @@ #include "blackjack.h" #include #include -#include - +#include int blackjack(){ @@ -62,6 +61,8 @@ int getRandCard(){ if(r > 10){ return 10; + } else if(r == 1){ + return 11; } return r; @@ -87,6 +88,8 @@ int playBJ(int bet, int balance){ userCardArray[1] = getRandCard(); printf("user rand card: %d\n", userCardArray[1]); + checkForBlackjack(userCardArray); + free(userCardArray); } @@ -95,4 +98,12 @@ int playBJ(int bet, int balance){ } return balance; +} + +bool checkForBlackjack(int userCardArray[]){ + if(userCardArray[0] + userCardArray[1] == 21){ + printf("BLACKJACK!\n"); + return true; + } + return false; } \ No newline at end of file diff --git a/src/main/c/Stefan/blackjack.h b/src/main/c/Stefan/blackjack.h index af00859..1388b18 100644 --- a/src/main/c/Stefan/blackjack.h +++ b/src/main/c/Stefan/blackjack.h @@ -1,6 +1,7 @@ #ifndef BLACKJACK_H #define BLACKJACK_H +#include int blackjack(); int getBalanceBJ(); @@ -8,5 +9,6 @@ int getBetBJ(int balance); int userInputBJ(); int getRandCard(); int playBJ(int bet, int balance); +bool checkForBlackjack(int userCards[]); #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 092557c..6217651 100644 --- a/src/test/c/Stefan/test_blackjack.c +++ b/src/test/c/Stefan/test_blackjack.c @@ -6,22 +6,28 @@ void setUp() {} void tearDown() {} -void test_1() { +void test_blackjack() { //arrange + int userCards[] = {10, 11}; //act + bool result = checkForBlackjack(userCards); //assert + TEST_ASSERT_TRUE(result); } -void test_2() { +void test_no_blackjack() { //arrange + int userCards[] = {10, 10}; //act + bool result = checkForBlackjack(userCards); //assert - + TEST_ASSERT_FALSE(result); + } \ No newline at end of file