forked from jarolrod/java-solitaire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomecellPile.java
More file actions
80 lines (63 loc) · 1.56 KB
/
HomecellPile.java
File metadata and controls
80 lines (63 loc) · 1.56 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
package code;
import java.util.ArrayList;
import javafx.scene.layout.StackPane;
public class HomecellPile extends StackPane {
private ArrayList<Card> store = new ArrayList<Card>();
private String gameType;
private int numberOfCards;
Card topCard;
public HomecellPile(String gameType) {
super();
super.setWidth(156);
super.setHeight(204);
super.setPrefSize(156, 204);
this.gameType = gameType;
numberOfCards = 0;
}
public boolean removeCard() {
return false;
}
public void addCard(Card newCard) {
if (addTest(newCard)) {
newCard.setVisible(true);
newCard.toFront();
newCard.setManaged(true);
super.getChildren().add(newCard);
store.add(newCard);
updateTopCard();
numberOfCards++;
}
}
public boolean addTest(Card newCard) {
if (gameType.equals("Aces_Up")) {
return true;
} else {
if (store.isEmpty()) {
int rank = newCard.getRank();
if (rank == 1) return true;
} else if (topCard.getSuit().equals(newCard.getSuit())) {
int topCardRank = topCard.getRank();
int newCardRank = newCard.getRank();
if ((newCardRank - topCardRank) == 1) return true;
} return false;
}
}
public Card getTopCard() {
return this.topCard;
}
private void updateTopCard() {
if (!store.isEmpty()) {
for (int i = 0; i < store.size(); i++) {
Card source = store.get(i);
source.setDraggable(false);
if (i == store.size()-1) {
Card top = store.get(i);
topCard = top;
}
}
} else topCard = null;
}
public int getNumberOfCards() {
return this.numberOfCards;
}
}