|
@ -7,7 +7,7 @@ void slotMachine(){ |
|
|
|
|
|
|
|
|
welcomeMessage(); |
|
|
welcomeMessage(); |
|
|
|
|
|
|
|
|
Symbol symbols[NUM_OF_SYMBOLS]; |
|
|
|
|
|
|
|
|
char symbols[NUM_OF_SYMBOLS]; |
|
|
|
|
|
|
|
|
int balance = getBalance(); |
|
|
int balance = getBalance(); |
|
|
|
|
|
|
|
@ -15,6 +15,8 @@ void slotMachine(){ |
|
|
|
|
|
|
|
|
int bet = getBet(balance); |
|
|
int bet = getBet(balance); |
|
|
balance = subtractBetFromBalance(bet, balance); |
|
|
balance = subtractBetFromBalance(bet, balance); |
|
|
|
|
|
printf("Guthaben: %d\n", balance); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
randomizeSymbols(symbols); |
|
|
randomizeSymbols(symbols); |
|
|
spin(symbols, bet, balance); |
|
|
spin(symbols, bet, balance); |
|
@ -47,17 +49,16 @@ int getBet(int balance){ |
|
|
} else { |
|
|
} else { |
|
|
printf("Ungueltige Eingabe!\n"); |
|
|
printf("Ungueltige Eingabe!\n"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int subtractBetFromBalance(int bet, int balance){ |
|
|
int subtractBetFromBalance(int bet, int balance){ |
|
|
return balance - bet; |
|
|
return balance - bet; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void randomizeSymbols(Symbol symbols[]){ |
|
|
|
|
|
|
|
|
|
|
|
char possibleLetter[] = "ABCD"; |
|
|
|
|
|
int possibleValue[] = { 3,5,10,20 }; |
|
|
|
|
|
|
|
|
void randomizeSymbols(char symbols[]){ |
|
|
|
|
|
|
|
|
srand(time(NULL)); |
|
|
srand(time(NULL)); |
|
|
|
|
|
|
|
@ -67,36 +68,32 @@ void randomizeSymbols(Symbol symbols[]){ |
|
|
|
|
|
|
|
|
// 35% chance für A |
|
|
// 35% chance für A |
|
|
if (r < 35) { |
|
|
if (r < 35) { |
|
|
symbols[i].letter = possibleLetter[0]; |
|
|
|
|
|
symbols[i].value = possibleValue[0]; |
|
|
|
|
|
|
|
|
symbols[i] = 'A'; |
|
|
} |
|
|
} |
|
|
// 30% chance für B |
|
|
// 30% chance für B |
|
|
else if (r < 65) { |
|
|
else if (r < 65) { |
|
|
symbols[i].letter = possibleLetter[1]; |
|
|
|
|
|
symbols[i].value = possibleValue[1]; |
|
|
|
|
|
|
|
|
symbols[i] = 'B'; |
|
|
} |
|
|
} |
|
|
// 20% chance für C |
|
|
// 20% chance für C |
|
|
else if (r < 85) { |
|
|
else if (r < 85) { |
|
|
symbols[i].letter = possibleLetter[2]; |
|
|
|
|
|
symbols[i].value = possibleValue[2]; |
|
|
|
|
|
|
|
|
symbols[i] = 'C'; |
|
|
} |
|
|
} |
|
|
// 15% chance für D |
|
|
// 15% chance für D |
|
|
else { |
|
|
else { |
|
|
symbols[i].letter = possibleLetter[3]; |
|
|
|
|
|
symbols[i].value = possibleValue[3]; |
|
|
|
|
|
|
|
|
symbols[i] = 'D'; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int spin(Symbol symbols[], int bet, int balance){ |
|
|
|
|
|
|
|
|
int spin(char symbols[], int bet, int balance){ |
|
|
|
|
|
|
|
|
int winnings = getWinnings(symbols, bet); |
|
|
int winnings = getWinnings(symbols, bet); |
|
|
|
|
|
|
|
|
return balance; |
|
|
return balance; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int getWinnings(Symbol symbols[], int bet){ |
|
|
|
|
|
|
|
|
int getWinnings(char symbols[], int bet){ |
|
|
|
|
|
|
|
|
int winnings = 0; |
|
|
int winnings = 0; |
|
|
|
|
|
|
|
@ -106,8 +103,16 @@ int getWinnings(Symbol symbols[], int bet){ |
|
|
|
|
|
|
|
|
// 3 gleiche Symbole in einer Reihe gewinnen, Gewinn berechnen |
|
|
// 3 gleiche Symbole in einer Reihe gewinnen, Gewinn berechnen |
|
|
for (int i = 0; i < ROWS; i++){ |
|
|
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; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (symbols[i * ROWS] == symbols[i * ROWS + 1] && symbols[i * ROWS] == symbols[i * ROWS + 2]) { |
|
|
|
|
|
|
|
|
|
|
|
switch(symbols[i]){ |
|
|
|
|
|
case 'A': winnings = bet * 3; break; |
|
|
|
|
|
case 'B': winnings = bet * 5; break; |
|
|
|
|
|
case 'C': winnings = bet * 10; break; |
|
|
|
|
|
case 'D': winnings = bet * 20; break; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|