forked from mattlevan/Simple_Card_Game
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
60 lines (49 loc) · 1.21 KB
/
Player.java
File metadata and controls
60 lines (49 loc) · 1.21 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
/*
* Matt Levan
* CSC 331, Dr. Amlan Chatterjee
* Data Structures
*
* Project 3 -- Simple Card Game
*
* Player.java
* Player class.
*
* CITATION:
* Java Programming: From the Ground Up by Bravaco, Simonson
* Page 496
*
* Original code modified to fit the needs of the project.
*
* Due in full by 11/14/2015 @ midnight
*
*/
public class Player {
// Attributes
private Hand hand;
private String name;
// Default constructor
public Player(String name) {
hand = new Hand(); // Instantiate new hand object
this.name = name;
}
// Methods
public Card playCard() {
Card c = hand.playCard();
System.out.println(String.format("%5s", name) + " plays a " + c.getName() + "!");
return c;
}
public void takeCard(Card card) {
hand.addCard(card);
}
public String getName() {
return name;
}
public void displayHand() {
System.out.println(name + "\'s hand (" + hand.getSize() + "):");
hand.display();
System.out.println();
}
public int handSize() {
return hand.getSize();
}
}