-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
283 lines (219 loc) · 8 KB
/
Copy pathPlayer.java
File metadata and controls
283 lines (219 loc) · 8 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
package utils;
import fileio.CardInput;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
public class Player {
private int gamesPlayed = 0;
private Card currentHero;
private int mana;
private int manaIncrement = 1;
private int deckCount;
private int cardsInDeckCount;
private int currentDeckIndex;
private ArrayList<Card> currentDeck;
private ArrayList<ArrayList<Card>> deckList;
private ArrayList<Card> cardsInHand = new ArrayList<>();
private ArrayList<Card> cardsInFrontRow = new ArrayList<>();
private ArrayList<Card> cardsInBackRow = new ArrayList<>();
public Player() { }
public int getMana() {
return mana;
}
public void setMana(final int mana) {
this.mana = mana;
}
public void incrementMana() {
if (manaIncrement < Constants.TEN) {
manaIncrement++;
}
mana += manaIncrement;
}
public void setManaIncrement(final int manaIncrement) {
this.manaIncrement = manaIncrement;
}
public void subtractMana(final int consumedMana) {
this.mana -= consumedMana;
}
public int getGamesPlayed() {
return gamesPlayed;
}
public void setGamesPlayed(final int gamesPlayed) {
this.gamesPlayed = gamesPlayed;
}
public void setCardsInDeckCount(final int cardsInDeckCounts) {
this.cardsInDeckCount = cardsInDeckCounts;
}
public void setDeckCount(final int deckCount) {
this.deckCount = deckCount;
}
public int getCurrentDeckIndex() {
return currentDeckIndex;
}
public void setCurrentDeckIndex(final int currentDeckIndex) {
this.currentDeckIndex = currentDeckIndex;
}
public ArrayList<Card> getCurrentDeck() {
return currentDeck;
}
public void setCurrentDeck(final ArrayList<Card> currentDeck) {
this.currentDeck = currentDeck;
}
public ArrayList<ArrayList<Card>> getDeckList() {
return deckList;
}
public void setDeckList(final ArrayList<ArrayList<CardInput>> deckList) {
this.deckList = new ArrayList<>();
for (ArrayList<CardInput> deck : deckList) {
ArrayList<Card> parsedDeck = new ArrayList<>();
for (CardInput card : deck) {
parsedDeck.add(getParsedCard(card));
}
this.deckList.add(parsedDeck);
}
}
public void resetCards() {
cardsInHand = new ArrayList<>();
cardsInFrontRow = new ArrayList<>();
cardsInBackRow = new ArrayList<>();
}
public ArrayList<Card> getCardsInHand() {
return cardsInHand;
}
public ArrayList<Card> getCardsInFrontRow() {
return cardsInFrontRow;
}
public ArrayList<Card> getCardsInBackRow() {
return cardsInBackRow;
}
public Card getCurrentHero() {
return currentHero;
}
public void setCurrentHero(final Card currentHero) {
this.currentHero = currentHero;
}
public void addCardInHand() {
if (!currentDeck.isEmpty()) {
cardsInHand.add(currentDeck.get(Constants.ZERO));
removeCardFromDeck(Constants.ZERO);
}
}
public void removeCardFromHand(final int index) {
cardsInHand.remove(index);
}
public void placeCardWithIndex(final int index) {
if (cardsInHand.isEmpty() || cardsInHand.size() <= index) {
return;
}
Card card = cardsInHand.get(index);
String cardName = card.getName();
if (isCardEligibleForFrontRow(cardName)) {
cardsInFrontRow.add(card);
}
if (isCardEligibleForBackRow(cardName)) {
cardsInBackRow.add(card);
}
subtractMana(card.getMana());
removeCardFromHand(index);
}
public boolean isCardEligibleForFrontRow(final String cardName) {
return (cardName.matches(CardNames.THE_RIPPER)
|| cardName.matches(CardNames.MIRAJ)
|| cardName.matches(CardNames.GOLIATH)
|| cardName.matches(CardNames.WARDEN))
&& cardsInFrontRow.size() < Constants.FIVE;
}
public boolean isCardEligibleForBackRow(final String cardName) {
return (cardName.matches(CardNames.SENTINEL)
|| cardName.matches(CardNames.BERSERKER)
|| cardName.matches(CardNames.THE_CURSED_ONE)
|| cardName.matches(CardNames.DISCIPLE))
&& cardsInBackRow.size() < Constants.FIVE;
}
public boolean isTheRowFullForCard(final String cardName) {
return ((cardName.matches(CardNames.THE_RIPPER)
|| cardName.matches(CardNames.MIRAJ)
|| cardName.matches(CardNames.GOLIATH)
|| cardName.matches(CardNames.WARDEN))
&& cardsInFrontRow.size() >= Constants.FIVE)
|| ((cardName.matches(CardNames.SENTINEL)
|| cardName.matches(CardNames.BERSERKER)
|| cardName.matches(CardNames.THE_CURSED_ONE)
|| cardName.matches(CardNames.DISCIPLE))
&& cardsInBackRow.size() >= Constants.FIVE);
}
public void removeCardFromDeck(final int index) {
if (!currentDeck.isEmpty() && currentDeck.size() > index) {
currentDeck.remove(index);
}
}
public void shuffleDeck(final String seed) {
Random random = new Random(Long.parseLong(seed));
Collections.shuffle(currentDeck, random);
}
public int getCardType(final String name) {
switch (name) {
case CardNames.SENTINEL, CardNames.GOLIATH,
CardNames.BERSERKER, CardNames.WARDEN,
CardNames.THE_RIPPER, CardNames.MIRAJ,
CardNames.THE_CURSED_ONE, CardNames.DISCIPLE:
return Constants.ONE;
case CardNames.LORD_ROYCE, CardNames.KING_MUDFACE,
CardNames.EMPRESS_THORINA, CardNames.GENERAL_KOCIORAW:
return Constants.TWO;
default:
return Constants.ZERO;
}
}
public Card getParsedCard(final CardInput card) {
Card parsedCard;
int cardType = getCardType(card.getName());
if (cardType == Constants.ONE)
parsedCard = new Minion();
else
parsedCard = new Hero();
parsedCard.setName(card.getName());
parsedCard.setHealth((cardType == Constants.TWO ? Constants.THIRTY : card.getHealth());
parsedCard.setMana(card.getMana());
parsedCard.setAttackDamage(card.getAttackDamage());
parsedCard.setDescription(card.getDescription());
parsedCard.setColors(card.getColors());
return parsedCard;
}
public void removeStunFromCards() {
for (Card card : cardsInBackRow) {
card.setStunned(false);
}
for (Card card : cardsInFrontRow) {
card.setStunned(false);
}
}
public void resetCardAttacks() {
for (Card card : cardsInBackRow) {
card.setHasAttackedThisTurn(false);
}
for (Card card : cardsInFrontRow) {
card.setHasAttackedThisTurn(false);
}
}
public boolean checkRowStatus(final String row) {
return (row.matches("backRow") ? cardsInBackRow.size() == Constants.FIVE
: cardsInFrontRow.size() == Constants.FIVE);
}
public void replaceDeck(final ArrayList<Card> deck) {
ArrayList<Card> newDeck = new ArrayList<>();
for (Card card : deck) {
Card newCard;
if ((getCardType(card.getName()) == 1)
newCard = new Minion();
newCard.setName(card.getName());
newCard.setMana(card.getMana());
newCard.setHealth(card.getHealth());
newCard.setDescription(card.getDescription());
newCard.setColors(card.getColors());
newCard.setAttackDamage(card.getAttackDamage());
newDeck.add(newCard);
}
this.currentDeck = newDeck;
}
}