feat: add blank status
This commit is contained in:
parent
8fa7a9830c
commit
cf79298b04
2 changed files with 45 additions and 18 deletions
|
@ -33,6 +33,7 @@ public class SlotService {
|
||||||
this.thirdReel = shuffleReel(reelStrip);
|
this.thirdReel = shuffleReel(reelStrip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public SpinResult spin(BigDecimal betAmount, UserEntity user) {
|
public SpinResult spin(BigDecimal betAmount, UserEntity user) {
|
||||||
int index1 = this.random.nextInt(REEL_LENGTH);
|
int index1 = this.random.nextInt(REEL_LENGTH);
|
||||||
int index2 = this.random.nextInt(REEL_LENGTH);
|
int index2 = this.random.nextInt(REEL_LENGTH);
|
||||||
|
@ -42,31 +43,36 @@ public class SlotService {
|
||||||
Symbol symbol2 = getSymbolAt(this.secondReel, index2);
|
Symbol symbol2 = getSymbolAt(this.secondReel, index2);
|
||||||
Symbol symbol3 = getSymbolAt(this.thirdReel, index3);
|
Symbol symbol3 = getSymbolAt(this.thirdReel, index3);
|
||||||
|
|
||||||
boolean isWin = symbol1.equals(symbol2) && symbol1.equals(symbol3);
|
Status status = determineStatus(symbol1, symbol2, symbol3);
|
||||||
|
|
||||||
SpinResult spinResult = processResult(betAmount, user, isWin, symbol1);
|
SpinResult spinResult = processResult(betAmount, user, status, symbol1);
|
||||||
buildResultMatrix(spinResult, index1, index2, index3);
|
buildResultMatrix(spinResult, index1, index2, index3);
|
||||||
|
|
||||||
return spinResult;
|
return spinResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SpinResult processResult(BigDecimal betAmount, UserEntity user, boolean isWin, Symbol winSymbol) {
|
private SpinResult processResult(BigDecimal betAmount, UserEntity user, Status status, Symbol winSymbol) {
|
||||||
BigDecimal resultAmount;
|
|
||||||
String status;
|
|
||||||
|
|
||||||
if (isWin) {
|
|
||||||
resultAmount = betAmount.multiply(winSymbol.getPayoutMultiplier());
|
|
||||||
status = "win";
|
|
||||||
this.balanceService.addFunds(user, resultAmount);
|
|
||||||
} else {
|
|
||||||
resultAmount = betAmount;
|
|
||||||
status = "lose";
|
|
||||||
this.balanceService.subtractFunds(user, betAmount);
|
|
||||||
}
|
|
||||||
|
|
||||||
SpinResult spinResult = new SpinResult();
|
SpinResult spinResult = new SpinResult();
|
||||||
spinResult.setStatus(status);
|
|
||||||
spinResult.setAmount(resultAmount);
|
switch (status) {
|
||||||
|
case WIN:
|
||||||
|
BigDecimal winAmount = betAmount.multiply(winSymbol.getPayoutMultiplier());
|
||||||
|
this.balanceService.addFunds(user, winAmount);
|
||||||
|
spinResult.setAmount(winAmount);
|
||||||
|
spinResult.setStatus(Status.WIN.name().toLowerCase());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BLANK:
|
||||||
|
spinResult.setAmount(BigDecimal.ZERO);
|
||||||
|
spinResult.setStatus(Status.BLANK.name().toLowerCase());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LOSE:
|
||||||
|
this.balanceService.subtractFunds(user, betAmount);
|
||||||
|
spinResult.setAmount(betAmount);
|
||||||
|
spinResult.setStatus(Status.LOSE.name().toLowerCase());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return spinResult;
|
return spinResult;
|
||||||
}
|
}
|
||||||
|
@ -124,4 +130,18 @@ public class SlotService {
|
||||||
|
|
||||||
return reel.get(effectiveIndex);
|
return reel.get(effectiveIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Status determineStatus(Symbol symbol1, Symbol symbol2, Symbol symbol3) {
|
||||||
|
boolean allSymbolsMatch = symbol1.equals(symbol2) && symbol1.equals(symbol3);
|
||||||
|
|
||||||
|
if (allSymbolsMatch) {
|
||||||
|
if (symbol1 == Symbol.BLANK) {
|
||||||
|
return Status.BLANK;
|
||||||
|
} else {
|
||||||
|
return Status.WIN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Status.LOSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
7
backend/src/main/java/de/szut/casino/slots/Status.java
Normal file
7
backend/src/main/java/de/szut/casino/slots/Status.java
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
package de.szut.casino.slots;
|
||||||
|
|
||||||
|
public enum Status {
|
||||||
|
WIN,
|
||||||
|
LOSE,
|
||||||
|
BLANK
|
||||||
|
}
|
Reference in a new issue