-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientPlayer.java
More file actions
108 lines (92 loc) · 3.35 KB
/
ClientPlayer.java
File metadata and controls
108 lines (92 loc) · 3.35 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
102
103
104
105
106
107
108
package logic.utils.players;
import logic.utils.Card;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public abstract class ClientPlayer extends Player {
protected boolean canPlay;
public ClientPlayer(String name) {
super(name);
}
/**
* Checks if the player is able to play in the game.
*
* @return {@code true} if the player can play, {@code false} otherwise.
*/
public boolean canPlay() {
return canPlay;
}
/**
* Sets the player's hand of cards based on the given string representation of cards.
* The string should contain the names of the cards separated by commas.
*
* @param cards A string representation of the cards in the player's hand.
* Each card should be represented by its name, separated by commas.
*/
public void setCards(String cards) {
String[] rawCards;
if (cards.isEmpty()) rawCards = new String[0];
else rawCards = cards.split(",");
hand = Stream.of(rawCards).map(Card::valueOf).collect(Collectors.toList());
}
/**
* Retrieves the string representation of the player's hand of cards.
* The hand is displayed as a numbered list of cards.
* Each card is represented by its index in the hand.
*
* @return The string representation of the player's hand of cards.
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(name).append("'s cards:\n");
int i = 1;
for (Card card : hand) {
sb.append(i).append(". ").append(card).append("\n");
i++;
}
return sb.toString();
}
/**
* Represents the end of a player's turn.
* This method should be implemented by the player to handle any necessary actions at the end of their turn.
*/
public void endTurn() {
canPlay = false;
}
/**
* Represents a player taking their turn.
*
* @return A CompletableFuture that will eventually complete with the card chosen by the player.
*/
public abstract CompletableFuture<Card> takeTurn();
/**
* Represents a method for a player to choose a card.
*
* @return A CompletableFuture that will eventually complete with the chosen card.
*/
public abstract CompletableFuture<Card> chooseCard();
/**
* Represents a method for a player to choose a target player.
*
* @param players A list of player names from which the target player will be chosen.
* @return A CompletableFuture that will eventually complete with the chosen target player as a String.
*/
public abstract CompletableFuture<String> choosePlayer(List<String> players);
/**
* Player chooses a position to insert an exploding kitten back at
*
* @return A CompletableFuture that will eventually complete with the chosen position as an Integer.
*/
public abstract CompletableFuture<Integer> choosePosition();
/**
* Confirms the player's move, indicating that they are unable to play in the game.
* For example, printing a message or taking a specific action.
*/
public abstract void confirmMove();
/**
* Stops the player from continuing to play in the game.
*/
public abstract void stop();
}