-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLesson-25_BlackJack
More file actions
102 lines (76 loc) · 2.57 KB
/
Copy pathLesson-25_BlackJack
File metadata and controls
102 lines (76 loc) · 2.57 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package lesson25;
// Берем 1 колоду =
import java.util.ArrayList;
import java.util.Random;
public class BlackJack {
// имя игрока
public String playerName;
// тип играка: человек или компютер
public boolean isHuman = false;
// создаем колоду карт
public static ArrayList<Integer> cardPack = new ArrayList<>();
// очки на руках у игрока
int scores = 0;
// случайное значение
Random random = new Random();
// конструктор
public BlackJack(boolean isHuman) {
this.isHuman = isHuman;
this.playerName = "Компьютер";
}
// конструктор
public BlackJack(boolean isHuman, String name ) {
this.isHuman = isHuman;
this.playerName = name;
}
// наполняем колоду
public static ArrayList<Integer> createCardPack() {
// наполняем колоду картами от 2 до Туза
for (int i = 0; i < 4; i++) { // четыре масти
for (int j = 2; j < 12; j++) { // очки карты
cardPack.add(j); //
if (j == 10) {
cardPack.add(j); // +J Валет
cardPack.add(j); // +Q Дама
cardPack.add(j); // +K Король
}
}
}
return cardPack;
}
// метод взять карту
public void getCard() {
System.out.println(this.playerName + " : Взята карта: ");
int card = selectCard();
scoreCount(card); // добавили карту к сумме очков
cardPack.remove(card); // удалили карту из колоды
// показать взятую карту и очки только для живого игрока
if (this.isHuman == true) {
System.out.println(card);
System.out.println("Сумма очков: " + this.scores);
}
// // набор карт игрока
// ArrayList<Integer> playerCards = new ArrayList<>();
// playerCards.add(card);
}
// выбор карты из колоды
public int selectCard() {
int randomPosition = random.nextInt(cardPack.size());
int card = cardPack.get(randomPosition); // рендомная карта в колоде
return card;
}
// раздача
public static void deal(BlackJack player1, BlackJack player2) {
System.out.println("Карты розданы!");
player1.getCard();
player2.getCard();
player1.getCard();
player2.getCard();
}
// метод подсчёт очков
public int scoreCount(int card) {
scores += card;
//System.out.println("Набрано очков: " + scores);
return scores;
}
}