From e87430bfc9454b1768b5dff4853dc9298dfef036 Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Mon, 29 Jan 2024 16:28:04 +0100 Subject: [PATCH] Symbole (A,B,C,D) mit bestimmten Wahrscheinlichkeiten und Werten erstellen --- src/main/c/Stefan/slot_machine.c | 44 +++++++++++++++++++++++++++++--- src/main/c/Stefan/slot_machine.h | 8 ++++++ 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/main/c/Stefan/slot_machine.c b/src/main/c/Stefan/slot_machine.c index ef586f5..a554065 100644 --- a/src/main/c/Stefan/slot_machine.c +++ b/src/main/c/Stefan/slot_machine.c @@ -1,20 +1,23 @@ #include "slot_machine.h" #include +#include +#include void slotMachine(){ welcomeMessage(); + Symbol symbols[NUM_OF_SYMBOLS]; + int balance = getBalance(); while(balance > 0){ int bet = getBet(balance); balance = subtractBetFromBalance(bet, balance); - } - - + createSymbols(symbols); + } } @@ -50,6 +53,41 @@ int subtractBetFromBalance(int bet, int balance){ return balance - bet; } +void createSymbols(Symbol symbols[]){ + + char possibleLetter[] = "ABCD"; + int possibleValue[] = { 3,5,10,20 }; + + 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].letter = possibleLetter[0]; + symbols[i].value = possibleValue[0]; + } + // 30% chance für B + else if (r < 65) { + symbols[i].letter = possibleLetter[1]; + symbols[i].value = possibleValue[1]; + } + // 20% chance für C + else if (r < 85) { + symbols[i].letter = possibleLetter[2]; + symbols[i].value = possibleValue[2]; + } + // 15% chance für D + else { + symbols[i].letter = possibleLetter[3]; + symbols[i].value = possibleValue[3]; + } + } + +} + 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 b0119f4..5cf2295 100644 --- a/src/main/c/Stefan/slot_machine.h +++ b/src/main/c/Stefan/slot_machine.h @@ -1,11 +1,19 @@ #ifndef SLOT_MACHINE_H #define SLOT_MACHINE_H +typedef struct { + char letter; + int value; +} Symbol; + +#define NUM_OF_SYMBOLS 9 + void slotMachine(); void welcomeMessage(); int getBalance(); int userInput(); int getBet(int balance); int subtractBetFromBalance(int bet, int balance); +void createSymbols(Symbol symbols[]); #endif // SLOT_MACHINE_H \ No newline at end of file