-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathPile.java
More file actions
91 lines (74 loc) · 2.22 KB
/
Pile.java
File metadata and controls
91 lines (74 loc) · 2.22 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
91
package com.codecool.klondike;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.effect.GaussianBlur;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import java.util.List;
import java.util.ListIterator;
public class Pile extends Pane {
private PileType pileType;
private String name;
private double cardGap;
private ObservableList<Card> cards = FXCollections.observableArrayList();
public Pile(PileType pileType, String name, double cardGap) {
this.pileType = pileType;
this.cardGap = cardGap;
}
public PileType getPileType() {
return pileType;
}
public String getName() {
return name;
}
public double getCardGap() {
return cardGap;
}
public ObservableList<Card> getCards() {
return cards;
}
public int numOfCards() {
return cards.size();
}
public boolean isEmpty() {
return cards.isEmpty();
}
public void clear() {
cards.removeAll(cards);
}
public void addCard(Card card) {
cards.add(card);
card.setContainingPile(this);
card.toFront();
layoutCard(card);
}
private void layoutCard(Card card) {
card.relocate(card.getLayoutX() + card.getTranslateX(), card.getLayoutY() + card.getTranslateY());
card.setTranslateX(0);
card.setTranslateY(0);
card.setLayoutX(getLayoutX());
card.setLayoutY(getLayoutY() + (cards.size() - 1) * cardGap);
}
public Card getTopCard() {
if (cards.isEmpty())
return null;
else
return cards.get(cards.size() - 1);
}
public void setBlurredBackground() {
setPrefSize(Card.WIDTH, Card.HEIGHT);
BackgroundFill backgroundFill = new BackgroundFill(Color.gray(0.0, 0.2), null, null);
Background background = new Background(backgroundFill);
GaussianBlur gaussianBlur = new GaussianBlur(10);
setBackground(background);
setEffect(gaussianBlur);
}
public enum PileType {
STOCK,
DISCARD,
FOUNDATION,
TABLEAU
}
}