forked from fjricci/monopoly
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputDeck.java
More file actions
57 lines (47 loc) · 1.22 KB
/
InputDeck.java
File metadata and controls
57 lines (47 loc) · 1.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
package monopoly;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
/**
* Created by fjricci on 5/4/2015.
* Manual card input
*/
public class InputDeck implements Deck {
private final ArrayList<Card> deck; //store array of cards
private final Input input; //store current card
private int SIZE; //store number of cards
//create shuffled deck of cards
public InputDeck() {
deck = new ArrayList<>();
input = new Input();
}
public void initialize(Card[] cards) {
if (!deck.isEmpty())
return;
SIZE = cards.length;
deck.addAll(Arrays.asList(cards));
Collections.shuffle(deck);
}
//draw next card from deck
public Card drawCard() {
System.out.println("Please select appropriate card.");
for (int i = 0; i < SIZE; i++) {
Card card = deck.get(i);
System.out.println(i + ") " + card.textA());
}
int card = -1;
while (card < 0) {
card = input.inputInt();
if (card < 0 || card >= SIZE) {
System.out.println("Invalid decision. Enter a valid number.");
card = -1;
}
}
return deck.get(card);
}
public void returnOutOfJail() {
}
public Iterable<Card> cards() {
return new ArrayList<>(deck);
}
}