-
Notifications
You must be signed in to change notification settings - Fork 2
/
game_blackjack.java
45 lines (32 loc) · 1.35 KB
/
game_blackjack.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
39
40
41
42
43
44
45
package blackjack;
import blackjack.card.Deck;
import blackjack.player.Dealer;
import blackjack.player.Player;
import blackjack.player.AbstractPlayer;
public class game_blackjack {
public int start() {
System.out.println("welcome to blackjack");
System.out.println("game start");
Deck deck = new Deck();
AbstractPlayer player = new Player("あなた");
AbstractPlayer dealer = new Dealer("ディーラー");
player.initCardList(deck);
dealer.initCardList(deck);
player.drawCard(deck);
dealer.drawCard(deck);
printGameResult(player, dealer);
System.out.println("game finish\n");
System.out.println("Come again!\n");
if (player.calcScore() == dealer.calcScore()) return 2;
else if(!player.getIsBurst() && (dealer.getIsBurst() || player.calcScore() > dealer.calcScore())) return 1;
else return 0;
}
private void printGameResult(AbstractPlayer player, AbstractPlayer dealer) {
if (player.calcScore() == dealer.calcScore()) {
System.out.println("引き分け");
}
if(!player.getIsBurst() && (dealer.getIsBurst() || player.calcScore() > dealer.calcScore())){
System.out.println(player.getName() + "の勝利\n");
} else System.out.println(player.getName() + "の敗北\n");
}
}