diff --git a/src/main/c/Stefan/slot_machine.c b/src/main/c/Stefan/slot_machine.c index f57a38e..1bb050e 100644 --- a/src/main/c/Stefan/slot_machine.c +++ b/src/main/c/Stefan/slot_machine.c @@ -17,6 +17,7 @@ void slotMachine(){ balance = subtractBetFromBalance(bet, balance); randomizeSymbols(symbols); + spin(symbols, bet, balance); } } @@ -88,6 +89,31 @@ void randomizeSymbols(Symbol symbols[]){ } +int spin(Symbol symbols[], int bet, int balance){ + + int winnings = getWinnings(symbols, bet); + + return balance; +} + +int getWinnings(Symbol 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].letter == symbols[i * ROWS + 1].letter && symbols[i * ROWS].letter == symbols[i * ROWS + 2].letter) { + winnings += bet * symbols[i * ROWS].value; + } + } + + return winnings; +} + void welcomeMessage(){ printf("Herzlich Willkommen zur \n\n" " _ _ _ _ \n" diff --git a/src/main/c/Stefan/slot_machine.h b/src/main/c/Stefan/slot_machine.h index bebd77b..1ed2f00 100644 --- a/src/main/c/Stefan/slot_machine.h +++ b/src/main/c/Stefan/slot_machine.h @@ -7,6 +7,7 @@ typedef struct { } Symbol; #define NUM_OF_SYMBOLS 9 +#define ROWS 9 void slotMachine(); void welcomeMessage(); @@ -15,5 +16,7 @@ int userInput(); int getBet(int balance); int subtractBetFromBalance(int bet, int balance); void randomizeSymbols(Symbol symbols[]); +int spin(Symbol symbols[], int bet, int balance); +int getWinnings(Symbol symbols[], int bet); #endif // SLOT_MACHINE_H \ No newline at end of file