-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCard.java
More file actions
101 lines (77 loc) · 2.28 KB
/
Copy pathCard.java
File metadata and controls
101 lines (77 loc) · 2.28 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
//Importing all HashMap libraries
import java.util.*;
import java.util.Arrays;
public class Card {
public HashMap<String, Integer> deck;
public static ArrayList<String> USED;
public Card(){
//Creating HashMap with String Keys and Integer Values
deck = new HashMap<String, Integer>();
//Creating Array list for used cards, we'll add to this list later on
USED = new ArrayList<String>();
//Creating all the cards and placing them in the HashMap called 'deck'
for(int i = 2; i < 10; i++){
deck.put(i + " of Hearts", i);
}
for(int i = 2; i < 10; i++){
deck.put(i + " of Spades", i);
}
for(int i = 2; i < 10; i++){
deck.put(i + " of Clubs", i);
}
for(int i = 2; i < 10; i++){
deck.put(i + " of Diamonds", i);
}
deck.put("Ace of Hearts", 10);
deck.put("Ace of Spades", 10);
deck.put("Ace of Clubs", 10);
deck.put("Ace of Diamonds", 10);
deck.put("King of Hearts", 10);
deck.put("King of Spades", 10);
deck.put("King of Clubs", 10);
deck.put("King of Diamonds", 10);
deck.put("Queen of Hearts", 10);
deck.put("Queen of Spades", 10);
deck.put("Queen of Clubs", 10);
deck.put("Queen of Diamonds", 10);
deck.put("Jack of Hearts", 10);
deck.put("Jack of Spades", 10);
deck.put("Jack of Clubs", 10);
deck.put("Jack of Diamonds", 10);
}
public String randomCard(){
//Selects a random card from deck
//Gets value and Key, but returns a String of the Key
Random random = new Random();
List<String> keys = new ArrayList<String>(deck.keySet());
String randomKey = keys.get(random.nextInt(keys.size()));
//Integer value = deck.get(randomKey);
return randomKey;
}
public int getValue(String key){
//returns the value of the card, given the key
//useful for adding values of cards together
int value = deck.get(key);
return value;
}
public String[] deal(){
//Returns 5 cards that are not being used in the deck
String dealCards[];
dealCards = new String[5];
int x = 0;
while(x<5){
String randomCard = randomCard();
if(USED.contains(randomCard)){
continue;
}
else{
//add random card to USED pile
USED.add(randomCard);
dealCards[x] = randomCard;
x++;
}
//CHANGE THIS LATER, if there are no cards what to do?
}
return dealCards;
}
}