forked from jarolrod/java-solitaire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFreecellPile.java
More file actions
62 lines (51 loc) · 1.13 KB
/
FreecellPile.java
File metadata and controls
62 lines (51 loc) · 1.13 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
package code;
import java.util.ArrayList;
import javafx.scene.layout.StackPane;
public class FreecellPile extends StackPane {
private ArrayList<Card> store = new ArrayList<Card>();
Card topCard;
public FreecellPile() {
super();
super.setWidth(156);
super.setHeight(204);
super.setPrefSize(156, 204);
}
public boolean removeCard() {
if (!store.isEmpty()) {
store.remove(store.size()-1);
topCard = null;
return true;
} else return false;
}
public void addCard(Card newCard) {
if(addTest()) {
newCard.setVisible(true);
newCard.setManaged(true);
newCard.toFront();
super.getChildren().add(newCard);
store.add(newCard);
updateTopCard();
}
}
public boolean isEmpty() {
if (store.size() == 0) return true;
return false;
}
public boolean addTest() {
if (store.isEmpty()) return true;
else return false;
}
public void updateTopCard() {
if (!store.isEmpty()) {
Card top = store.get(0);
top.setDraggable(true);
topCard = top;
} else topCard = null;
}
public Card getTopCard() {
return this.topCard;
}
public int getNumberOfCards() {
return this.store.size();
}
}