-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeck.java
More file actions
63 lines (54 loc) · 1.87 KB
/
Deck.java
File metadata and controls
63 lines (54 loc) · 1.87 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
package com.victor.pokerproject;
import java.util.LinkedList;
import java.util.Collections;
import java.util.Random;
public class Deck {
private LinkedList<Card> cartas;
private Random aleatorio;
public Deck() {
cartas = new LinkedList<>();
aleatorio = new Random();
String[] palos = {"Tréboles", "Corazones", "Picas", "Diamantes"};
String[] valores = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "A", "J", "Q", "K"};
for (String palo : palos) {
String color = (palo.equals("Corazones") || palo.equals("Diamantes")) ? "Rojo" : "Negro";
for (String valor : valores) {
cartas.add(new Card(palo, color, valor));
}
}
}
public void shuffle() {
Collections.shuffle(cartas);
System.out.println("Se mezcló el Deck.");
}
public void head() {
if (cartas.isEmpty()) {
System.out.println("No quedan cartas en el deck.");
return;
}
Card carta = cartas.remove(0);
System.out.println(carta);
System.out.println("Quedan " + cartas.size());
}
public void pick() {
if (cartas.isEmpty()) {
System.out.println("No quedan cartas en el deck.");
return;
}
int indiceAzar = aleatorio.nextInt(cartas.size());
Card carta = cartas.remove(indiceAzar);
System.out.println(carta);
System.out.println("Quedan " + cartas.size());
}
public void hand() {
if (cartas.size() < 5) {
System.out.println("No hay suficientes cartas para entregar una mano (quedan " + cartas.size() + ").");
return;
}
for (int i = 0; i < 5; i++) {
Card carta = cartas.remove(0);
System.out.println(carta);
}
System.out.println("Quedan " + cartas.size());
}
}