forked from relaxingstew/GameCodeScaffolding
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Hand.java
84 lines (67 loc) · 1.93 KB
/
Hand.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
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
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
public class Hand
{
private Deck deck;
private ArrayList<Card> cardsInHand;
private int handSize;
private Random rand = new Random();
private boolean[] dealBool;
private int numberOfCardsDealt;
public Hand(Deck deck)
{
dealBool = new boolean[deck.getCards().size()];
cardsInHand = new ArrayList<Card>();
this.handSize = cardsInHand.size();
for (int x = 0; x < deck.getCards().size(); x++)
{
dealBool[x] = false;
}
}
public void deal(Deck deck, Hand hand, int numberOfCardsDealt)
{
for (int i = 0; i <= numberOfCardsDealt; i++)
{
int handCards = rand.nextInt(deck.getCards().size());
if (dealBool[handCards] == false){
cardsInHand.add(deck.getCards().get(handCards));
dealBool[handCards] = true;
}
else if (hand.isOut(dealBool) == true){continue;}
else if (dealBool[handCards] = true){
i--;
}
}
}
public boolean isOut(boolean[] dealBoo)
{
for (int i = 0; i < dealBool.length; i++){
if (!dealBoo[i]) return false;
}
return true;
}
public Card playCard(Hand hand, int cardNumber)
{
Card card = hand.getCardsInHand().get(cardNumber);
hand.getCardsInHand().remove(cardNumber);
return card;
}
public String toString()
{
System.out.println("Name\t\tStrength\tDefense");
String string = "";
for (int i = 0; i < cardsInHand.size(); i++)
{
string += i + ". ";
string += cardsInHand.get(i).toString() + "\n";
}
return string;
}
public int getHandSize() {
return handSize;
}
public ArrayList<Card> getCardsInHand() {
return cardsInHand;
}
}