From 26dcf2bf942d60f945b6fdc1ef2e3321427c1006 Mon Sep 17 00:00:00 2001 From: Ronja Awe Date: Mon, 23 Jan 2023 15:01:37 +0100 Subject: [PATCH] Funktion blackjack erstellt --- src/c/raetselronja.c | 34 ++++++++++++++++++++++++++++++++++ src/c/raetselronja.h | 2 +- src/c/randomnumber.c | 8 ++++++++ src/c/randomnumber.h | 6 ++++++ test/c/test_raetselronja.c | 22 ++++++++++++++++++++++ 5 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 src/c/randomnumber.c create mode 100644 src/c/randomnumber.h diff --git a/src/c/raetselronja.c b/src/c/raetselronja.c index 0172e19..cdfbe0c 100644 --- a/src/c/raetselronja.c +++ b/src/c/raetselronja.c @@ -1,9 +1,11 @@ #include #include #include +#include #include "raetselronja.h" #include "userinput.h" +#include "randomnumber.h" @@ -86,6 +88,38 @@ if (gegner < spieler){ } +int blackjack(int spieler, int geber, int janein){ + + int lower = 1, upper = 11, count = 1, num = 0, num2 = 0; + + srand(time(NULL)); + + printf("Wollen Sie das Spiel starten?\nJA(1), NEIN(2)\n"); + janein = userInput(); + + while (spieler < 21 && geber < 21) { + + if (janein == 1) { + for (int i = 1; i <= count; i++) { + int num = (randnum() % (upper - lower + 1)) + lower; + printf("Sie haben eine %d bekommen\n", num); + spieler += num; + printf("Nun haben Sie: %d\n", spieler); + } + for (int i = 1; i <= count; i++) { + int num = (randnum() % (upper - lower + 1)) + lower; + printf("Der Geber hat eine %d bekommen\n", num); + geber += num; + printf("Nun hat der Geber: %d\n", geber); + } + printf("Wollen Sie eine weitere Karte?\nJA(1), NEIN(2)\n"); + janein = userInput(); + } + } + return 1; + +} + diff --git a/src/c/raetselronja.h b/src/c/raetselronja.h index 5de01c4..e81ff79 100644 --- a/src/c/raetselronja.h +++ b/src/c/raetselronja.h @@ -4,7 +4,7 @@ int zahlenraetsel(int input[], int loesung, int n); int raetselaufruf(); int armdruecken(int gegner, int spieler); - +int blackjack(int spieler, int geber, int janein); #endif \ No newline at end of file diff --git a/src/c/randomnumber.c b/src/c/randomnumber.c new file mode 100644 index 0000000..926cfea --- /dev/null +++ b/src/c/randomnumber.c @@ -0,0 +1,8 @@ +#include "randomnumber.h" + +int randnum(){ + +int value; +return value; + +} \ No newline at end of file diff --git a/src/c/randomnumber.h b/src/c/randomnumber.h new file mode 100644 index 0000000..e9de3e6 --- /dev/null +++ b/src/c/randomnumber.h @@ -0,0 +1,6 @@ +#ifndef RANDOMNUMBER_H +#define RANDOMNUMBER_H + +int randnum(); + +#endif \ No newline at end of file diff --git a/test/c/test_raetselronja.c b/test/c/test_raetselronja.c index 7eb707d..971b59b 100644 --- a/test/c/test_raetselronja.c +++ b/test/c/test_raetselronja.c @@ -4,6 +4,8 @@ #include "raetselronja.h" #include "userinput.h" #include "mock_userinput.h" +#include "randomnumber.h" +#include "mock_randomnumber.h" //Vor- bzw. Nachbereitung void setUp(void) @@ -82,6 +84,26 @@ TEST_ASSERT_EQUAL_INT(0, result); } +void test_runRaetselTestBJ(void){ + + int spieler = 0; + int geber = 0; + int janein = 0; + + userInput_ExpectAndReturn(1); + randnum_ExpectAndReturn(10); + randnum_ExpectAndReturn(8); + userInput_ExpectAndReturn(1); + randnum_ExpectAndReturn(10); + randnum_ExpectAndReturn(10); + userInput_ExpectAndReturn(1); + + + + int result = blackjack(spieler, geber, janein); + TEST_ASSERT_EQUAL_INT(1, result); +} +