-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPlayer.java
92 lines (81 loc) · 2.93 KB
/
Player.java
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
package Crazy8;
import java.util.ArrayList;
/**
* A class that provides framework for a Player character in the Crazy 8s game.
*/
public class Player
{
/** The Player name. */
public String name = "";
/** For use at the beginning of the game, the character will have a unique line of dialogue to say. */
public String openingText = "";
/** Their greeting response to the player. */
public String greetingText = "";
/** Their taunt to the player. */
public String tauntText = "";
/** Their hand of cards. */
public ArrayList<Card> hand;
/** Manually set the AI behavior when you create this object. */
public Behavior behavior;
public Ability ability;
/**
* @param newName Their new name.
* @param opening Their opening line.
* @param greeting Their greeting line.
* @param taunt Their taunt response.
*/
public Player(String newName, String opening, String greeting, String taunt)
{
this.name = newName;
this.greetingText = greeting;
this.tauntText = taunt;
this.openingText = opening;
}
/**
* A lazy way to create -somewhat- descriptive dialogue. This method will return a string like:
* Jaina shouted, "My magic will tear you apart!"
* Malfurion lazily mumbled, "This game is crazy."
*
* @param message What you want the character to say.
* @param description How you want them to say it.
* @return A string in the form: {Character.name} {description} "{message}"
*/
public String say(String message, String description)
{
String dialogue = this.name + " " + description + " \"" + message + "\"";
return dialogue;
}
public Player() {}
/**
* Print the player's hand in a list from 1-8.
*
*/
public void printHand()
{
// Here we are scrolling through every card in the player's hand and printing it, using .format() to make sure
// everything is spaced correctly.
// Note on this format: The specific %-20s merely specifies a left-aligned message of 20 characters in length.
// So if the string we're passing in place of that argument is not 20 characters in length, the rest of the space
// will be filled in with whitespace.
String handText = "";
for(Card card : this.hand)
{
int cardIndex = this.hand.indexOf(card) + 1;
handText += String.format("%-3s %-25s", cardIndex + ")", card);
// Make every row 4 cards in length, for less wide displays.
if(((this.hand.indexOf(card) + 1) % 4) == 0) handText += "\n";
}
handText += "\n\n";
System.out.println(handText);
}
public Card draw(Deck deck)
{
Card drawCard = deck.pop();
hand.add(drawCard);
return drawCard;
}
public String toString()
{
return this.name;
}
}