-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathCards.java
More file actions
104 lines (80 loc) · 1.85 KB
/
Cards.java
File metadata and controls
104 lines (80 loc) · 1.85 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
92
93
94
95
96
97
98
99
100
101
102
103
104
package monopoly;
public class Cards implements Square {
private final int DECK_SIZE = 16; //16 cards in either type of deck
private final Deck deck; //store deck of cards
private String name;
private int pos;
private Card.CardType type;
//construct square of type cards
public Cards(String name, int pos, Card.CardType type, Deck deck) {
this.deck = deck;
if (type != Card.CardType.COMMUNITY && type != Card.CardType.CHANCE)
throw new IllegalArgumentException("Card type invalid!");
if (type == Card.CardType.CHANCE)
chance();
else
community();
this.name = name;
this.pos = pos;
this.type = type;
}
public Card.CardType type() {
return type;
}
public boolean isOwnable() {
return false;
}
public boolean isMortgaged() {
return false;
}
public int mortgageCost() {
return 0;
}
public int position() {
return pos;
}
public String name() {
return name;
}
public boolean isOwned() {
return false;
}
public int mortgage() {
return 0;
}
//create deck of community chest cards
private void community() {
Card[] cards = new Card[DECK_SIZE];
for (int i = 0; i < DECK_SIZE; i++)
cards[i] = new Card(Card.CardType.COMMUNITY, i);
deck.initialize(cards);
}
//create deck of chance cards
private void chance() {
Card[] cards = new Card[DECK_SIZE];
for (int i = 0; i < DECK_SIZE; i++)
cards[i] = new Card(Card.CardType.CHANCE, i);
deck.initialize(cards);
}
//draw next card
public Card draw() {
return deck.drawCard();
}
public int cost() {
return 0;
}
public void purchase(Player player) {
}
public int rent(int val) {
return 0;
}
public Player owner() {
return null;
}
public String toString() {
return name;
}
public Iterable<Card> cards() {
return deck.cards();
}
}