-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameLogic.java
38 lines (38 loc) · 1.17 KB
/
GameLogic.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public class GameLogic{
GameEngine engine;
public GameLogic(Ui inout){
engine = new GameEngine();
inout.setMessage("Welcome to BlackJack.");
while(true){
engine.startGame();
int bet;
do{
inout.displayPot(engine.getPot());
bet = inout.getWager();
}while(!engine.setWager(bet));
inout.displayHand("Player", engine.getPlayerHand(), engine.calPlayerHand());
inout.setMessage("Hit or stay? ");
String response = inout.getResponse();
while(response.equals("hit")){
engine.playerDeal();
inout.displayHand("Player", engine.getPlayerHand(), engine.calPlayerHand());
if(engine.calPlayerHand() > 21) break;
inout.setMessage("Hit or stay? ");
response = inout.getResponse();
}
engine.dealerPlays();
inout.displayHand("Dealer", engine.getDealerHand(), engine.calDealerHand());
inout.displayHand("Player", engine.getPlayerHand(), engine.calPlayerHand());
if(engine.isPlayerWin()){
inout.setMessage("Congratulations, you win!\n");
engine.payoutPlayer();
}else {
inout.setMessage("Suck it up, you lost!\n");
}
if(engine.getPot() <= 0){
inout.setMessage("You're out of money, get out!\n");
break;
}
}
}
}