librejack

Blackjack clone written in java
git clone https://github.com/michaelneuper/librejack.git
README | Files | Log | Refs | LICENSE

commit 74c0d760befbfa7db59e3423ad4d51aa84b8cf79
parent c55e5eb8c1b5e730f8f75661d234b7b5ecc273d4
Author: Michael Neuper <73108749+michaelneuper@users.noreply.github.com>
Date:   Sat,  8 Oct 2022 15:09:34 +0200

clean code

Diffstat:
Msrc/controller/Controller.java | 24++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/src/controller/Controller.java b/src/controller/Controller.java @@ -110,7 +110,15 @@ public class Controller { player.makeDecision(deck, discarded); - // check whether they busted + checkWhoWins(); + + // start a new round + startRound(); + } + + private void checkWhoWins() { + + // check whether player busted if(player.getHand().calculateValue() > 21) { System.out.println("Busted"); balance -= bet; @@ -128,8 +136,15 @@ public class Controller { if(dealer.getHand().calculateValue() > 21) { System.out.println("Dealer busts"); balance += bet; - ++wins; - } else if(dealer.getHand().calculateValue() > player.getHand().calculateValue()) { + } + + if(dealer.getHand().calculateValue() > player.getHand().calculateValue() && dealer.getHand().calculateValue() <= 21) { + System.out.println("You lose"); + balance -= bet; + ++losses; + } + + if(dealer.getHand().calculateValue() > player.getHand().calculateValue()) { System.out.println("You lose"); balance -= bet; ++losses; @@ -145,9 +160,6 @@ public class Controller { System.out.println("Push"); ++pushes; } - - // start a new round - startRound(); } }