Browse Source

Symbole in einer Reihe vergleichen und Gewinn berechnen

remotes/origin/dev
fdai7472 11 months ago
parent
commit
ac710a4578
  1. 26
      src/main/c/Stefan/slot_machine.c
  2. 3
      src/main/c/Stefan/slot_machine.h

26
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"

3
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
Loading…
Cancel
Save