diff --git a/src/main/c/Stefan/place_your_code_here.txt b/src/main/c/Stefan/place_your_code_here.txt deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/c/Stefan/slot_machine.c b/src/main/c/Stefan/slot_machine.c new file mode 100644 index 0000000..f659eab --- /dev/null +++ b/src/main/c/Stefan/slot_machine.c @@ -0,0 +1,164 @@ +#include "slot_machine.h" +#include +#include +#include +#include + +void slotMachine(){ + + welcomeMessage(); + + char symbols[NUM_OF_SYMBOLS]; + + int balance = getBalance(); + + while(balance > 0){ + + int bet = getBet(balance); + balance = subtractBetFromBalance(bet, balance); + + randomizeSymbols(symbols); + balance = spin(symbols, bet, balance); + } + +} + +int getBalance(){ + int balance; + printf("Guthaben einwerfen: "); + balance = userInput(); + printf("Dein Guthaben: %d\n", balance); + return balance; +} + +int userInput(){ + int input; + scanf("%d", &input); + return input; +} + +int getBet(int balance){ + + while(1){ + printf("Wetteinsatz: "); + int bet = userInput(); + + if(bet <= balance && bet > 0){ + return bet; + } else { + printf("Ungueltige Eingabe!\n"); + } + + } + +} + +int subtractBetFromBalance(int bet, int balance){ + return balance - bet; +} + +void randomizeSymbols(char symbols[]){ + + srand(time(NULL)); + + for (int i = 0; i < NUM_OF_SYMBOLS; i++) { + + int r = rand() % 100; + + // 35% chance für A + if (r < 35) { + symbols[i] = 'A'; + } + // 30% chance für B + else if (r < 65) { + symbols[i] = 'B'; + } + // 20% chance für C + else if (r < 85) { + symbols[i] = 'C'; + } + // 15% chance für D + else { + symbols[i] = 'D'; + } + } + +} + +int spin(char symbols[], int bet, int balance){ + + int winnings = getWinnings(symbols, bet); + + showResult(symbols, winnings); + + balance += winnings; + printf("Aktuelles Guthaben: %d\n-------------------------\n", balance); + return balance; +} + +int getWinnings(char symbols[], int bet){ + + int winnings = 0; + + // 0 | 1 | 2 + // 3 | 4 | 5 + // 6 | 7 | 8 + + // 3 gleiche Symbole in einer Reihe gewinnen, Gewinn berechnen + for (int i = 0; i < ROWS; i++){ + + if (symbols[i * ROWS] == symbols[i * ROWS + 1] && symbols[i * ROWS] == symbols[i * ROWS + 2]) { + + switch(symbols[i * ROWS]){ + case 'A': winnings += bet * 3; break; + case 'B': winnings += bet * 5; break; + case 'C': winnings += bet * 10; break; + case 'D': winnings += bet * 20; break; + } + } + } + if (winnings > 0) { + printf("\nDu hast %d gewonnen!\n", winnings - bet); + } + else { + printf("\nLeider verloren.\n"); + } + + return winnings; +} + +void showResult(char symbols[], int winnings){ + + char winnerMessage[] = {""}; + + if(winnings > 0){ + strcpy(winnerMessage, " WINNER "); + } else { + strcpy(winnerMessage, " LOSER "); + } + + printf("\n" + " .-------.\n" + " {-%s-} \n" + " .=============.\n" + " | | __\n" + " | [%c] [%c] [%c] |( )\n" + " | [%c] [%c] [%c] | ||\n" + " | [%c] [%c] [%c] | ||\n" + " | |_||\n" + " | xxx ::::::: |--'\n" + " | ooo ::::::: |\n" + " | $$$ ::::::: |\n" + " | __ |\n" + " |_____/__\\____|\n\n", winnerMessage, symbols[0], symbols[1], symbols[2], symbols[3], symbols[4], symbols[5], symbols[6], symbols[7], symbols[8]); +} + +void welcomeMessage(){ + printf("Herzlich Willkommen zur \n\n" + " _ _ _ _ \n" + " | | | | | | (_) \n" + " ___| | ___ | |_ _ __ ___ __ _ ___| |__ _ _ __ ___ \n" + "/ __| |/ _ \\| __| | '_ ` _ \\ / _` |/ __| '_ \\| | '_ \\ / _ \\\n" + "\\__ \\ | (_) | |_ | | | | | (_| | (__| | | | | | | | __/\n" + "|___/_|\\___/ \\__| |_| |_| |_|\\__,_|\\___|_| |_|_|_| |_|\\___|\n\n"); +} \ No newline at end of file diff --git a/src/main/c/Stefan/slot_machine.h b/src/main/c/Stefan/slot_machine.h new file mode 100644 index 0000000..c08b4bb --- /dev/null +++ b/src/main/c/Stefan/slot_machine.h @@ -0,0 +1,19 @@ +#ifndef SLOT_MACHINE_H +#define SLOT_MACHINE_H + + +#define NUM_OF_SYMBOLS 9 +#define ROWS 3 + +void slotMachine(); +void welcomeMessage(); +int getBalance(); +int userInput(); +int getBet(int balance); +int subtractBetFromBalance(int bet, int balance); +void randomizeSymbols(char symbols[]); +int spin(char symbols[], int bet, int balance); +int getWinnings(char symbols[], int bet); +void showResult(char symbols[], int winnings); + +#endif // SLOT_MACHINE_H \ No newline at end of file diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index d49319b..08886d6 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -1,7 +1,261 @@ #include "hangman.h" #include +#include +#include +#include +#include +#include + + + + +char wordlist[LISTSIZE][MAX_WORD_LENGTH] = { + "Kartoffel", "Zigarette", "Haus", "Fenster", "Kartenleseettiketiergeraet", + "Kleiderschrank", "Schnee","Wasserhahn","Fernbedienung", + "Computertastatur", "Verlies","Zucchini","lizenzieren", + "Portemonnaie","brillant","Rückgrat","Toilettenpapier", + "Dachpappe","Hund","Zwiebelsuppe","Zebra", + "Kruzifix","Anschnallgurt","Bügeleisen","Fliesenleger", + "Adventskranz","Weihnachtsbaum","Autoreifen","Waschbecken", + "Busfahrkarte" +}; + +char hangmanStages[STAGENUM][ASCII_ART_SIZE]={ + "+---+\n" + "| |\n" + "|\n" + "|\n" + "|\n" + "|\n" + "=========\n", + "+---+\n" + "| |\n" + "| O\n" + "|\n" + "|\n" + "|\n" + "=========\n", + "+---+\n" + "| |\n" + "| O\n" + "| |\n" + "|\n" + "|\n" + "=========\n", + "+---+\n" + "| |\n" + "| O\n" + "| /|\n" + "|\n" + "|\n" + "=========\n", + "+---+\n" + "| |\n" + "| O\n" + "| /|\\\n" + "|\n" + "|\n" + "=========\n", + "+---+\n" + "| |\n" + "| O\n" + "| /|\\\n" + "| /\n" + "|\n" + "=========\n", + "+---+\n" + "| |\n" + "| O\n" + "| /|\\\n" + "| / \\\n" + "|\n" + "=========\n", +}; + void hangman() { - printf("Hello World!"); + srand(time(NULL)); + char userSelection; + getWelcomeMessageHangman(); + + do + { + char guessWord[MAX_WORD_LENGTH]; + int length; + int countWrongGuess=0; + strcpy(guessWord,getWordFromList(rand() % LISTSIZE)); + length = strlen(guessWord); + + char displayWord[MAX_WORD_LENGTH]; + drawHangman(countWrongGuess); + for (int i = 0; i <= length; i++) + { + if(i=0 && x0) + { + printf("Dein gewaehlter Buchstabe %c war ein Treffer!\n", selectedLetter); + return true; + } + else + { + return false; + } + +} + +void changeLetter(char selectedLetter, char guessWord[], int length, char ptrDisplayWord[]) +{ + for(int i = 0; i= POSSIBLE_TRYS) + { + printf("Du hast verloren!\n\nDas gesuchte Wort war \"%s\"\n\n", guessWord); + return true; + } + else + { + return false; + } +} + +char endGame() +{ + char userSelect; + endGameQuestionHangman(); + scanf(" %c", &userSelect); + + return userSelect; +} + + +void endGameQuestionHangman() +{ + printf("Moechtest du nochmal spielen?\n\nBeliebige Taste: Nochmal spielen\n 0 : Beenden\n"); +} \ No newline at end of file diff --git a/src/main/c/Tim/hangman.h b/src/main/c/Tim/hangman.h index cd17d02..f68abf8 100644 --- a/src/main/c/Tim/hangman.h +++ b/src/main/c/Tim/hangman.h @@ -1,6 +1,22 @@ +#include #ifndef HANGMAN_H #define HANGMAN_H +#define LISTSIZE 30 +#define MAX_WORD_LENGTH 30 +#define STAGENUM 7 +#define ASCII_ART_SIZE 1000 +#define POSSIBLE_TRYS 6 + void hangman(); +void getWelcomeMessageHangman(); +char* getWordFromList(int); +bool wordGuessed(char[],char[]); +bool letterGuessed(char, char[], int); +void changeLetter(char, char[], int, char[]); +void drawHangman(int); +bool noTrysLeft(int,char[]); +char endGame(); +void endGameQuestionHangman(); #endif diff --git a/src/main/c/main.c b/src/main/c/main.c index 4dc37a9..49f4cdd 100644 --- a/src/main/c/main.c +++ b/src/main/c/main.c @@ -14,6 +14,7 @@ #include "SchereSteinPapier.h" #include "hangman.h" #include "tictactoe.h" +#include "slot_machine.h" void openInterface(); @@ -35,7 +36,8 @@ void openInterface() "Du hast folgende Spiele zur Auswahl:\n\n" "1: Schere-Stein-Papier\n" "2: Hangman\n" - "3: TicTacToe\n"); + "3: TicTacToe\n" + "4: Slot Machine\n"); printf("\nBitte waehle die Zahl des entsprechenden Spiels aus, um damit zu starten.\nAm Ende eines Spiels kannst du mit der Taste 0 wieder zurueck zum Hauptmenue kommen.\nIm Hauptmenue beendest du mit der Auswahl 0 das Programm \n\n"); scanf_s("%d", &selection); @@ -54,10 +56,10 @@ void openInterface() case(3): startTicTacToe(); break; - /*case(4): - //Spiel() + case(4): + slotMachine(); break; - case(5): + /*case(5): //Spiel() break;*/ default: diff --git a/src/test/c/Stefan/place_your_tests_here.txt b/src/test/c/Stefan/place_your_tests_here.txt deleted file mode 100644 index e69de29..0000000 diff --git a/src/test/c/Stefan/test_slot_machine.c b/src/test/c/Stefan/test_slot_machine.c new file mode 100644 index 0000000..f2a17c9 --- /dev/null +++ b/src/test/c/Stefan/test_slot_machine.c @@ -0,0 +1,224 @@ +#include "slot_machine.h" +#include "unity.h" + +void setUp() {} + +void tearDown() {} + +void test_subtract_bet_10_from_balance_10() { + + //arrange + int expectedResult = 0; + + //act + int actualResult = subtractBetFromBalance(10, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} + +void test_subtract_bet_0_from_balance_10() { + + //arrange + int expectedResult = 10; + + //act + int actualResult = subtractBetFromBalance(0, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} + +void test_subtract_bet_5_from_balance_10() { + + //arrange + int expectedResult = 5; + + //act + int actualResult = subtractBetFromBalance(5, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} + +void test_no_rows_won_bet_equals_10() { + + //arrange + char testSymbols[] = {"AABAACAAD"}; + + int expectedResult = 0; + + //act + int actualResult = getWinnings(testSymbols, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} + +void test_3_A_won_bet_equals_10() { + + //arrange + char testSymbols[] = {"AAAAACAAD"}; + + int expectedResult = 30; + + //act + int actualResult = getWinnings(testSymbols, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} + +void test_3_B_won_bet_equals_10() { + + //arrange + char testSymbols[] = {"BBBAACAAD"}; + + int expectedResult = 50; + + //act + int actualResult = getWinnings(testSymbols, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} + +void test_3_C_won_bet_equals_10() { + + //arrange + char testSymbols[] = {"BABAACCCC"}; + + int expectedResult = 100; + + //act + int actualResult = getWinnings(testSymbols, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} + +void test_3_D_won_bet_equals_10() { + + //arrange + char testSymbols[] = {"BABDDDCAC"}; + + int expectedResult = 200; + + //act + int actualResult = getWinnings(testSymbols, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} + +void test_6_A_won_bet_equals_10() { + + //arrange + char testSymbols[] = {"AAAAAACAC"}; + + int expectedResult = 60; + + //act + int actualResult = getWinnings(testSymbols, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} + +void test_6_B_won_bet_equals_10() { + + //arrange + char testSymbols[] = {"BBBBBBCAC"}; + + int expectedResult = 100; + + //act + int actualResult = getWinnings(testSymbols, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} + +void test_6_C_won_bet_equals_10() { + + //arrange + char testSymbols[] = {"CCCCCCCAC"}; + + int expectedResult = 200; + + //act + int actualResult = getWinnings(testSymbols, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} + +void test_6_D_won_bet_equals_10() { + + //arrange + char testSymbols[] = {"DDDDDDCAC"}; + + int expectedResult = 400; + + //act + int actualResult = getWinnings(testSymbols, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} + +void test_3_A_3_B_won_bet_equals_10() { + + //arrange + char testSymbols[] = {"AAABBBCAC"}; + + int expectedResult = 80; + + //act + int actualResult = getWinnings(testSymbols, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} + +void test_3_C_3_D_won_bet_equals_10() { + + //arrange + char testSymbols[] = {"BAACCCDDD"}; + + int expectedResult = 300; + + //act + int actualResult = getWinnings(testSymbols, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} + +void test_9_A_won_bet_equals_10() { + + //arrange + char testSymbols[] = {"AAAAAAAAA"}; + + int expectedResult = 90; + + //act + int actualResult = getWinnings(testSymbols, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} + +void test_3_B_3_C_3_D_won_bet_equals_10() { + + //arrange + char testSymbols[] = {"BBBCCCDDD"}; + + int expectedResult = 350; + + //act + int actualResult = getWinnings(testSymbols, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} \ No newline at end of file diff --git a/src/test/c/Tim/test_hangman.c b/src/test/c/Tim/test_hangman.c index 2afdf17..47f8e40 100644 --- a/src/test/c/Tim/test_hangman.c +++ b/src/test/c/Tim/test_hangman.c @@ -1,5 +1,7 @@ #include "hangman.h" #include "unity.h" +#include +#include @@ -13,12 +15,165 @@ void tearDown(void) } -void test_ceedling_functionality() +void test_getWordFromList_Kartoffel_0() { //arrange - int expectedResult = 0; + int pos = 0; + char expectedResult[] = "Kartoffel"; //act - int actualResult = 0; + char actualResult[30]; + strcpy(actualResult,getWordFromList(pos)); //assert - TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); -} \ No newline at end of file + TEST_ASSERT_EQUAL_STRING(expectedResult, actualResult); +} + +void test_getWordFromList_Kleiderschrank_5() +{ + //arrange + int pos = 5; + char expectedResult[] = "Kleiderschrank"; + //act + char actualResult[30]; + strcpy(actualResult,getWordFromList(pos)); + //assert + TEST_ASSERT_EQUAL_STRING(expectedResult, actualResult); +} + + +void test_getWordFromList_Index_lower_Listsize() +{ + //arrange + int pos = -5; + char expectedResult[] = "Index nicht vorhanden"; + //act + char actualResult[30]; + strcpy(actualResult,getWordFromList(pos)); + //assert + TEST_ASSERT_EQUAL_STRING(expectedResult, actualResult); +} +void test_getWordFromList_Index_higher_Listsize() +{ + //arrange + int pos = LISTSIZE+1; + char expectedResult[] = "Index nicht vorhanden"; + //act + char actualResult[30]; + strcpy(actualResult,getWordFromList(pos)); + //assert + TEST_ASSERT_EQUAL_STRING(expectedResult, actualResult); +} + + +void test_wonGame_wordGuessed() +{ + //arrange + char word1[] ="Kartoffel"; + char word2[] = "Kartoffel"; + //assert + TEST_ASSERT_TRUE(wordGuessed(word1, word2)); +} + +void test_not_wordGuessed() +{ + //arrange + char word1[] ="Kartoffel"; + char word2[] ="Thunfisch"; + //assert + TEST_ASSERT_FALSE(wordGuessed(word1, word2)); +} + +void test_wordGuessed_differentCaps() +{ + //arrange + char word1[] ="Kartoffel"; + char word2[] ="karTOFFel"; + //assert + TEST_ASSERT_FALSE(wordGuessed(word1, word2)); +} + + +void test_letterGuessed_differentCaps_small_big() +{ + //arrange + char x ='F'; + char y[] ="Kartoffel"; + int length = 9; + //assert + TEST_ASSERT_TRUE(letterGuessed(x,y,length)); +} + +void test_letterGuessed_differentCaps_big_small() +{ + //arrange + char x ='k'; + char y[] ="Kartoffel"; + int length = 9; + //assert + TEST_ASSERT_TRUE(letterGuessed(x,y,length)); +} +void test_letterGuessed_sameCaps_small() +{ + //arrange + char x ='f'; + char y[] ="Kartoffel"; + int length = 9; + //assert + TEST_ASSERT_TRUE(letterGuessed(x,y,length)); +} +void test_letterGuessed_differentLetter_small() +{ + //arrange + char x ='p'; + char y[] ="Kartoffel"; + int length = 9; + //assert + TEST_ASSERT_FALSE(letterGuessed(x,y,length)); +} +void test_letterGuessed_differentLetter_big() +{ + //arrange + char x ='P'; + char y[] ="Kartoffel"; + int length = 9; + //assert + TEST_ASSERT_FALSE(letterGuessed(x,y,length)); +} + + +void test_letterGuessed_sameCaps_big() +{ + //arrange + char x ='K'; + char y[] ="Kartoffel"; + int length = 9; + //assert + TEST_ASSERT_TRUE(letterGuessed(x,y,length)); +} + +void test_noTrysLeft_x_equals_POSSIBLE_TRYS() +{ + //arrange + char x = POSSIBLE_TRYS; + char y[] ="Kartoffel"; + //assert + TEST_ASSERT_TRUE(noTrysLeft(x, y)); +} + +void test_noTrysLeft_x_lower_POSSIBLE_TRYS() +{ + //arrange + char x = POSSIBLE_TRYS-2; + char y[] ="Kartoffel"; + //assert + TEST_ASSERT_FALSE(noTrysLeft(x, y)); +} + +void test_noTrysLeft_x_higher_POSSIBLE_TRYS() +{ + //arrange + char x = POSSIBLE_TRYS+2; + char y[] ="Kartoffel"; + //assert + TEST_ASSERT_TRUE(noTrysLeft(x, y)); +} +