Browse Source

Ergebnis wird mit coolem ascii art angezeigt

remotes/origin/dev
fdai7472 11 months ago
parent
commit
a35238d83f
  1. 32
      src/main/c/Stefan/slot_machine.c
  2. 2
      src/main/c/Stefan/slot_machine.h

32
src/main/c/Stefan/slot_machine.c

@ -2,6 +2,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
#include <string.h>
void slotMachine(){ void slotMachine(){
@ -86,9 +87,10 @@ void randomizeSymbols(char symbols[]){
int spin(char symbols[], int bet, int balance){ int spin(char symbols[], int bet, int balance){
showResult(symbols);
int winnings = getWinnings(symbols, bet); int winnings = getWinnings(symbols, bet);
showResult(symbols, winnings);
balance += winnings; balance += winnings;
printf("Aktuelles Guthaben: %d\n-------------------------\n", balance); printf("Aktuelles Guthaben: %d\n-------------------------\n", balance);
return balance; return balance;
@ -125,12 +127,30 @@ int getWinnings(char symbols[], int bet){
return winnings; return winnings;
} }
void showResult(char symbols[]){
printf("\n");
void showResult(char symbols[], int winnings){
for (int i = 0; i < ROWS; i++){
printf(" %c | %c | %c\n", symbols[i * ROWS], symbols[i * ROWS + 1], symbols[i * ROWS + 2]);
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(){ void welcomeMessage(){

2
src/main/c/Stefan/slot_machine.h

@ -14,6 +14,6 @@ int subtractBetFromBalance(int bet, int balance);
void randomizeSymbols(char symbols[]); void randomizeSymbols(char symbols[]);
int spin(char symbols[], int bet, int balance); int spin(char symbols[], int bet, int balance);
int getWinnings(char symbols[], int bet); int getWinnings(char symbols[], int bet);
void showResult(char symbols[]);
void showResult(char symbols[], int winnings);
#endif // SLOT_MACHINE_H #endif // SLOT_MACHINE_H
Loading…
Cancel
Save