forked from mattlevan/Simple_Card_Game
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHand.java
More file actions
75 lines (62 loc) · 1.83 KB
/
Hand.java
File metadata and controls
75 lines (62 loc) · 1.83 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
/*
* Matt Levan
* CSC 331, Dr. Amlan Chatterjee
* Data Structures
*
* Project 3 -- Simple Card Game
*
* Hand.java
*
* CITATION:
* Java Programming: From the Ground Up by Bravaco, Simonson
* Page 481
*
* Original code modified to fit the needs of the project.
*
* Due in full by 11/16/2015 @ 11:59 PM.
*
*/
public class Hand {
// Attributes
private SingleLinkedList cards; // Cards in hand
// Default constructor
public Hand() {
cards = new SingleLinkedList(); // A singly linked list of cards
}
// Methods
public void addCard(Card card) {
cards.add(card);
}
public Card playCard() {
Card cardToPlay = (Card) cards.removeFirst();
return cardToPlay;
}
public int getSize() {
return cards.size;
}
public void display() {
String[][] tempArray = new String[13][4];
int k = 1;
// Populate tempArray with cards
for (int i = 0; i < 13; i++) {
for (int j = 0; j < 4; j++) {
if (cards.getNode(k) != null) {
tempArray[i][j] = cards.getNode(k).data.toString();
k++;
}
}
}
for (int i = 0; i < 13; i++) {
if (tempArray[i][0] != null) {
for (int j = 0; j < 4; j++) {
if (tempArray[i][j] != null) {
System.out.print(String.format("%3s", tempArray[i][j]));
System.out.print(" ");
}
}
System.out.println();
}
}
// cards.printList(cards.getNode(0));
}
}