Browse Source

Implementierung Max Win bei slot machine + Test

remotes/origin/stefan
fdai7472 11 months ago
parent
commit
2618917dd7
  1. 17
      src/main/c/Stefan/slot_machine.c
  2. 2
      src/main/c/Stefan/slot_machine.h
  3. 4
      src/test/c/Stefan/test_slot_machine.c

17
src/main/c/Stefan/slot_machine.c

@ -3,6 +3,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
#include <string.h> #include <string.h>
#include <stdbool.h>
void slotMachine(){ void slotMachine(){
@ -117,6 +118,11 @@ int getWinnings(char symbols[], int bet){
} }
} }
} }
if(checkForMaxWin(symbols)){
winnings *= 10;
}
if (winnings > 0) { if (winnings > 0) {
printf("\nDu hast %d gewonnen!\n", winnings - bet); printf("\nDu hast %d gewonnen!\n", winnings - bet);
} }
@ -127,6 +133,17 @@ int getWinnings(char symbols[], int bet){
return winnings; return winnings;
} }
bool checkForMaxWin(char symbols[]){
bool maxWin = true;
for(int i = 1; i < NUM_OF_SYMBOLS; i++){
if(symbols[0] != symbols[i]){
maxWin = false;
return maxWin;
}
}
return maxWin;
}
void showResult(char symbols[], int winnings){ void showResult(char symbols[], int winnings){
char winnerMessage[10] = {""}; char winnerMessage[10] = {""};

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

@ -1,6 +1,7 @@
#ifndef SLOT_MACHINE_H #ifndef SLOT_MACHINE_H
#define SLOT_MACHINE_H #define SLOT_MACHINE_H
#include <stdbool.h>
#define NUM_OF_SYMBOLS 9 #define NUM_OF_SYMBOLS 9
#define ROWS 3 #define ROWS 3
@ -15,5 +16,6 @@ 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[], int winnings); void showResult(char symbols[], int winnings);
bool checkForMaxWin(char symbols[]);
#endif // SLOT_MACHINE_H #endif // SLOT_MACHINE_H

4
src/test/c/Stefan/test_slot_machine.c

@ -195,12 +195,12 @@ void test_3_C_3_D_won_bet_equals_10() {
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); TEST_ASSERT_EQUAL_INT(expectedResult, actualResult);
} }
void test_9_A_won_bet_equals_10() {
void test_9_A_max_win_bet_equals_10() {
//arrange //arrange
char testSymbols[] = {"AAAAAAAAA"}; char testSymbols[] = {"AAAAAAAAA"};
int expectedResult = 90;
int expectedResult = 900;
//act //act
int actualResult = getWinnings(testSymbols, 10); int actualResult = getWinnings(testSymbols, 10);

Loading…
Cancel
Save