-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHand.java
73 lines (60 loc) · 1.66 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
import java.util.ArrayList;
public class Hand {
private ArrayList<Card> list = new ArrayList<Card>();
public boolean isEmpty() {
return getList().isEmpty();
}
/**
* This method will add a card to the end of the list.
*
* @param x The card to be added.
*
*/
public void addCard(Card x) {
getList().add(x);
}
/**
* Iterates through the list and removes the selected card.
* @param x The card to be removed.
*/
// modified and fix by LOnique. damn u gil ^_^~
public void removeCard(Card x){
for (int i=0;i<getList().size();i++){
if((getList().get(i).getSuit().equalsIgnoreCase(x.getSuit()))&& getList().get(i).getValue()==x.getValue()){
getList().remove(i);
}
}
}
//for user to check if he played invalid move
public boolean isInHand(Card x){
for (int i=0;i<getList().size();i++){
if((getList().get(i).getSuit().equalsIgnoreCase(x.getSuit()))&& getList().get(i).getValue()==x.getValue()){
return true;
}
}
System.out.println("Invalid move, This card is not in your hand.");
return false;
}
public Card isValidInHand(Card x){
for (int i=0;i<getList().size();i++){
if((getList().get(i).getSuit().charAt(0)==x.getSuit().charAt(0))|| getList().get(i).getValue()==x.getValue()){
return getList().get(i);
}
}
return null;
}
public String searchForSuit(){
int i=0;
while(getList().get(i)!= null){
return getList().get(i).getSuit();
}
System.out.println("hand is empty");
return null;
}
public void setList(ArrayList<Card> list) {
this.list = list;
}
public ArrayList<Card> getList() {
return list;
}
}