Browse Source

Symbole (A,B,C,D) mit bestimmten Wahrscheinlichkeiten und Werten erstellen

remotes/origin/dev
fdai7472 11 months ago
parent
commit
e87430bfc9
  1. 44
      src/main/c/Stefan/slot_machine.c
  2. 8
      src/main/c/Stefan/slot_machine.h

44
src/main/c/Stefan/slot_machine.c

@ -1,20 +1,23 @@
#include "slot_machine.h" #include "slot_machine.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <time.h>
void slotMachine(){ void slotMachine(){
welcomeMessage(); welcomeMessage();
Symbol symbols[NUM_OF_SYMBOLS];
int balance = getBalance(); int balance = getBalance();
while(balance > 0){ while(balance > 0){
int bet = getBet(balance); int bet = getBet(balance);
balance = subtractBetFromBalance(bet, balance); balance = subtractBetFromBalance(bet, balance);
}
createSymbols(symbols);
}
} }
@ -50,6 +53,41 @@ int subtractBetFromBalance(int bet, int balance){
return balance - bet; 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(){ void welcomeMessage(){
printf("Herzlich Willkommen zur \n\n" printf("Herzlich Willkommen zur \n\n"
" _ _ _ _ \n" " _ _ _ _ \n"

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

@ -1,11 +1,19 @@
#ifndef SLOT_MACHINE_H #ifndef SLOT_MACHINE_H
#define SLOT_MACHINE_H #define SLOT_MACHINE_H
typedef struct {
char letter;
int value;
} Symbol;
#define NUM_OF_SYMBOLS 9
void slotMachine(); void slotMachine();
void welcomeMessage(); void welcomeMessage();
int getBalance(); int getBalance();
int userInput(); int userInput();
int getBet(int balance); int getBet(int balance);
int subtractBetFromBalance(int bet, int balance); int subtractBetFromBalance(int bet, int balance);
void createSymbols(Symbol symbols[]);
#endif // SLOT_MACHINE_H #endif // SLOT_MACHINE_H
Loading…
Cancel
Save