forked from jarolrod/java-solitaire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStockPile.java
More file actions
90 lines (77 loc) · 2 KB
/
StockPile.java
File metadata and controls
90 lines (77 loc) · 2 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
81
82
83
84
85
86
87
88
89
90
package code;
import java.util.ArrayList;
import javafx.animation.TranslateTransition;
import javafx.scene.Cursor;
import javafx.scene.image.Image;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.paint.ImagePattern;
import javafx.scene.shape.Rectangle;
import javafx.util.Duration;
public class StockPile extends StackPane {
private Deck gameDeck;
public ArrayList<Card> store;
public StockPile() {
super();
gameDeck = new Deck();
gameDeck.deckShuffle();
store = gameDeck.getStore();
super.setWidth(156);
super.setHeight(204);
super.setPrefSize(156, 204);
addGroups();
updateTopGroup();
}
private void addGroups() {
int y = 5;
int x = 5;
for (int i = 0; i < 12; i++) {
Rectangle temp = new Rectangle(146,194);
temp.setArcHeight(15);
temp.setArcWidth(15);
String imageLocation = "/assets/card_assets/cards/backofHand.png";
Image tempImage = new Image(imageLocation);
temp.setFill(new ImagePattern(tempImage));
temp.setStroke(Color.GRAY);
temp.setVisible(true);
temp.toFront();
temp.setManaged(false);
temp.setLayoutX(x);
temp.setLayoutY(y);
super.getChildren().add(temp);
x-=1;
y-=1;
}
}
public void updateTopGroup() {
if(!store.isEmpty()) {
Rectangle temp = (Rectangle) super.getChildren().get(super.getChildren().size()-1);
temp.setOnMouseEntered(e -> {
temp.setStroke(Color.GOLD);
temp.setStrokeWidth(2);
});
temp.setOnMouseExited(e -> {
temp.setStroke(Color.GRAY);
temp.setStrokeWidth(1);
});
}
}
public void dealCards(ArrayList<TableauPile> param) {
if (!store.isEmpty()) {
for (TableauPile pile : param) {
pile.addCard(store.remove(store.size()-1));
pile.updateTopCard();
}
super.getChildren().remove(super.getChildren().size()-1);
updateTopGroup();
}
}
public Card removeCard() {
Card retVal = store.remove(store.size() -1);
return retVal;
}
public boolean isEmpty() {
if (store.isEmpty()) return true;
return false;
}
}