Skip to content

Commit d253ee7

Browse files
committed
name of cards in hand
1 parent fda542b commit d253ee7

File tree

9 files changed

+4542
-3010
lines changed

9 files changed

+4542
-3010
lines changed

accounts.json

Lines changed: 4473 additions & 2959 deletions
Large diffs are not rendered by default.

src/Main.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import view.Graphic;
1313
import view.UI;
1414

15+
import java.io.File;
1516
import java.io.FileReader;
1617
import java.io.Reader;
1718
import java.lang.reflect.Type;
@@ -50,10 +51,16 @@ public static void main(String[] args) {
5051
private static void loadAccounts() {
5152
try {
5253
YaGson yaGson = new YaGsonBuilder().setPrettyPrinting().create();
53-
Reader reader = new FileReader("accounts.json");
54-
HashMap<String, Account> accounts = yaGson.fromJson(reader, (Type) Account[].class);
55-
if (accounts != null) {
56-
DataCenter.getInstance().setAccounts(accounts);
54+
File file = new File("Player");
55+
File[] allAccounts = file.listFiles();
56+
if (allAccounts != null) {
57+
for (File file1 : allAccounts) {
58+
Reader reader = new FileReader(file1.getName());
59+
HashMap<String, Account> accounts = yaGson.fromJson(reader, (Type) Account[].class);
60+
if (accounts != null) {
61+
DataCenter.getInstance().getAccounts().putAll(accounts);
62+
}
63+
}
5764
}
5865
} catch (Exception e) {
5966
e.printStackTrace();

src/model/Account.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ void setMainDeck(Deck deck) throws CloneNotSupportedException {
9292
for (Card card : deck.getCards()) {
9393
Card mainDeckCard = card.clone();
9494
mainDeck.addCard(mainDeckCard);
95+
mainDeck.getHand().allCardsInDeck.add(mainDeckCard);
9596
}
9697
if (deck.getItem() != null) {
9798
Item mainDeckItem = deck.getItem().clone();
@@ -116,16 +117,18 @@ public static void saveAccounts() {
116117

117118
YaGson yaGson = new YaGsonBuilder().setPrettyPrinting().create();
118119
try {
119-
Writer writer = new FileWriter("accounts.json");
120-
String string = yaGson.toJson(DataCenter.getInstance().getAccounts());
121-
writer.write(string);
122-
writer.close();
120+
for (Account account : DataCenter.getInstance().getAccounts().values()) {
121+
if (account.getUsername() != null) {
122+
Writer writer = new FileWriter("Players/" + account.getUsername());
123+
String string = yaGson.toJson(account);
124+
writer.write(string);
125+
writer.close();
126+
}
127+
}
123128

124129
} catch (Exception e) {
125130
e.printStackTrace();
126131
}
127-
128-
129132
}
130133

131134
boolean soldCard(Card card) {

src/model/Collection.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,9 @@ public void selectDeck(String deckName) throws CloneNotSupportedException {
228228
return;
229229
}
230230
Controller.currentAccount.setMainDeck(deck);
231-
deck.hand.allCardsInDeck = deck.cards;
232231
Controller.currentAccount.getMainDeck().validated = true;
232+
Controller.currentAccount.getMainDeck().getHand().initializeHand();
233233
view.setMainDeck();
234-
deck.getHand().initializeHand();
235234
}
236235

237236
public void showAllDecks() {

src/model/Game.java

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ public class Game {
1717
private int timeOfGame;
1818
public Card currentCard;
1919
public Item currentItem;
20-
private Account activeAccount;
2120
private boolean storyMode = false;
2221
private View view = View.getInstance();
2322

24-
public Game(){
25-
activeAccount = Controller.currentAccount;
23+
public Account whoseTurn(){
24+
if(Controller.currentAccount.myTurn){
25+
return Controller.currentAccount;
26+
}
27+
return Controller.enemyAccount;
2628
}
2729
Map getMap() {
2830
return map;
@@ -345,7 +347,7 @@ private boolean distanceTooLong(Card card, int x, int y) {
345347
public void attack(Card myCard, Card opponentCard) throws CloneNotSupportedException {
346348
if (!myCard.disarmed) {
347349
myCard.attack(opponentCard);
348-
if (activeAccount.equals(Controller.currentAccount)) {
350+
if (whoseTurn().equals(Controller.currentAccount)) {
349351
player1Mp -= myCard.Mp;
350352
} else {
351353
player2Mp -= myCard.Mp;
@@ -425,7 +427,7 @@ public void useSpecialPower(int x, int y) {
425427
}
426428

427429
public void showHand() {
428-
activeAccount.getMainDeck().showHand();
430+
whoseTurn().getMainDeck().showHand();
429431
}
430432

431433
public void endTurn() {
@@ -436,19 +438,21 @@ public void endTurn() {
436438
for (Card card : Controller.enemyAccount.getCardsInGame()) {
437439
card.getCurrentBlock().blockEffect();
438440
}
439-
if (activeAccount.equals(Controller.currentAccount)) {
440-
activeAccount = Controller.enemyAccount;
441+
if (whoseTurn().equals(Controller.currentAccount)) {
442+
Controller.currentAccount.myTurn = false;
443+
Controller.enemyAccount.myTurn = true;
441444
} else {
442-
activeAccount = Controller.currentAccount;
445+
Controller.currentAccount.myTurn = true;
446+
Controller.enemyAccount.myTurn = false;
443447
}
444-
for (Card card : activeAccount.getCardsInGame()) {
448+
for (Card card : whoseTurn().getCardsInGame()) {
445449
card.attackedThisTurn = false;
446450
}
447-
if (activeAccount.getMainDeck().getItem().getItemName().equals("KingWisom")) {
448-
activeAccount.getMainDeck().getItem().KingWisdom(activeAccount.getUsername());
451+
if (whoseTurn().getMainDeck().getItem().getItemName().equals("KingWisom")) {
452+
whoseTurn().getMainDeck().getItem().KingWisdom(whoseTurn().getUsername());
449453
}
450-
if (activeAccount.getMainDeck().getItem().getItemName().equals("TajDanaii")) {
451-
activeAccount.getMainDeck().getItem().tajeDanaii(activeAccount.getUsername());
454+
if (whoseTurn().getMainDeck().getItem().getItemName().equals("TajDanaii")) {
455+
whoseTurn().getMainDeck().getItem().tajeDanaii(whoseTurn().getUsername());
452456
}
453457
map.checkIfCollectibleOrFlagIsTaken();
454458
updateGraveYard();
@@ -470,7 +474,7 @@ private void buffEffect() throws CloneNotSupportedException {
470474
}
471475

472476
private void addToMana() {
473-
if (activeAccount.equals(Controller.currentAccount)) {
477+
if (whoseTurn().equals(Controller.currentAccount)) {
474478
if (turn < 14) {
475479
player1Mp = (turn / 2) + 2;
476480
} else {
@@ -488,7 +492,7 @@ private void addToMana() {
488492
public void help() {
489493
view.showMyMinions();
490494
view.showEnemyMinion();
491-
activeAccount.getMainDeck().showHand();
495+
whoseTurn().getMainDeck().showHand();
492496
}
493497

494498
public void useItem(Item item, int x, int y) {
@@ -504,7 +508,7 @@ public void useItem(Item item, int x, int y) {
504508

505509
public void addCardsToGame(String cardName, int x, int y) {
506510
Card card = Card.returnCardByName(cardName);
507-
if (card == null || !activeAccount.getMainDeck().hand.returnHand().contains(card)) {
511+
if (card == null || !whoseTurn().getMainDeck().hand.returnHand().contains(card)) {
508512
view.invalidCardNameInGame();
509513
return;
510514
}
@@ -529,7 +533,7 @@ public void addCardsToGame(String cardName, int x, int y) {
529533
view.invalidTarget();
530534
return;
531535
}
532-
boolean whichAccount = activeAccount.equals(Controller.currentAccount);
536+
boolean whichAccount = whoseTurn().equals(Controller.currentAccount);
533537
if (whichAccount) {
534538
if ((Controller.currentGame.player1Mp - card.Mp) < 0) {
535539
view.notEnoughMana();
@@ -548,7 +552,7 @@ public void addCardsToGame(String cardName, int x, int y) {
548552
}
549553
cardsInGame.add(card);
550554
block.cardMovedToBlock(card);
551-
if (activeAccount.equals(Controller.currentAccount)) {
555+
if (whoseTurn().equals(Controller.currentAccount)) {
552556
Controller.currentAccount.getMainDeck().hand.deleteFromHand(card);
553557
if (Controller.currentAccount.getMainDeck().getItem().getItemName().equals("ghosleTamid") && card.getTypeOfAttack().equals(TypeOfCard.Minion)) {
554558
Item item = Controller.currentAccount.getMainDeck().getItem();
@@ -582,30 +586,30 @@ public void addCardsToGame(String cardName, int x, int y) {
582586
private boolean checkSurroundingBlocks(int x, int y, boolean canBeEnserted) {
583587
Block surrondingBlock = map.getBlock(x - 1, y);
584588
if (surrondingBlock != null) {
585-
if (!surrondingBlock.isEmpty() && activeAccount.getCardsInGame().contains(surrondingBlock.card)) {
589+
if (!surrondingBlock.isEmpty() && whoseTurn().getCardsInGame().contains(surrondingBlock.card)) {
586590
canBeEnserted = true;
587591
}
588592
}
589593
if (!canBeEnserted) {
590594
surrondingBlock = map.getBlock(x, y - 1);
591595
if (surrondingBlock != null) {
592-
if (!surrondingBlock.isEmpty() && !activeAccount.getCardsInGame().contains(surrondingBlock.card)) {
596+
if (!surrondingBlock.isEmpty() && !whoseTurn().getCardsInGame().contains(surrondingBlock.card)) {
593597
canBeEnserted = true;
594598
}
595599
}
596600
}
597601
if (!canBeEnserted) {
598602
surrondingBlock = map.getBlock(x + 1, y);
599603
if (surrondingBlock != null) {
600-
if (surrondingBlock.isEmpty() && !activeAccount.getCardsInGame().contains(surrondingBlock.card)) {
604+
if (surrondingBlock.isEmpty() && !whoseTurn().getCardsInGame().contains(surrondingBlock.card)) {
601605
canBeEnserted = true;
602606
}
603607
}
604608
}
605609
if (!canBeEnserted) {
606610
surrondingBlock = map.getBlock(x, y + 1);
607611
if (surrondingBlock != null) {
608-
if (surrondingBlock.isEmpty() && !activeAccount.getCardsInGame().contains(surrondingBlock.card)) {
612+
if (surrondingBlock.isEmpty() && !whoseTurn().getCardsInGame().contains(surrondingBlock.card)) {
609613
canBeEnserted = true;
610614
}
611615
}
@@ -635,11 +639,11 @@ public void showCard(String cardIdInGame) {
635639
}
636640

637641
public Account getActiveAccount() {
638-
return this.activeAccount;
642+
return this.whoseTurn();
639643
}
640644

641645
public void showCollectibles() {
642-
for (Card card : activeAccount.getCardsInGame()) {
646+
for (Card card : whoseTurn().getCardsInGame()) {
643647
for (Collectible collectible : card.getCollectibles()) {
644648
view.showCollectible(collectible);
645649
}

src/model/Hand.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@ public void initializeHand() {
1919
}
2020
}
2121
allCardsInDeck.remove(hero);
22-
for(index = 0; index < 6; index++) {
23-
cardsInHand.add(allCardsInDeck.get(index));
24-
System.out.println(cardsInHand.get(index).getName());
22+
for(Card card : allCardsInDeck) {
23+
if(index < 6) {
24+
cardsInHand.add(card);
25+
index++;
26+
}
27+
else {
28+
break;
29+
}
2530
}
2631
}
2732

src/view/BattleMap1.fxml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@
143143
</ImageView>
144144
</children>
145145
</HBox>
146-
<HBox layoutX="306.0" layoutY="800.0" prefHeight="194.0" prefWidth="1009.0" spacing="70.0">
147-
<Label fx:id="firstCardName" prefHeight="50" prefWidth="180" scaleX="1.1" scaleY="1.1"/>
148-
<Label fx:id="secondCardName" prefHeight="50" prefWidth="180" scaleX="1.1" scaleY="1.1"/>
149-
<Label fx:id="thirdCardName" prefHeight="50" prefWidth="180" scaleX="1.1" scaleY="1.1"/>
150-
<Label fx:id="fourthCardName" prefHeight="50" prefWidth="180" scaleX="1.1" scaleY="1.1"/>
151-
<Label fx:id="fifthCardName" prefHeight="50" prefWidth="180" scaleX="1.1" scaleY="1.1"/>
152-
<Label fx:id="sixthCardName" prefHeight="50" prefWidth="173" scaleX="1.1" scaleY="1.1"/>
146+
<HBox layoutX="306.0" layoutY="800.0" prefHeight="194.0" prefWidth="1009.0" spacing="90.0">
147+
<Label fx:id="firstCardName" prefHeight="50" prefWidth="180" scaleX="1.1" scaleY="1.1" textFill="snow"/>
148+
<Label fx:id="secondCardName" prefHeight="50" prefWidth="180" scaleX="1.1" scaleY="1.1" textFill="snow"/>
149+
<Label fx:id="thirdCardName" prefHeight="50" prefWidth="180" scaleX="1.1" scaleY="1.1" textFill="snow"/>
150+
<Label fx:id="fourthCardName" prefHeight="50" prefWidth="180" scaleX="1.1" scaleY="1.1" textFill="snow"/>
151+
<Label fx:id="fifthCardName" prefHeight="50" prefWidth="180" scaleX="1.1" scaleY="1.1" textFill="snow"/>
152+
<Label fx:id="sixthCardName" prefHeight="50" prefWidth="173" scaleX="1.1" scaleY="1.1" textFill="snow"/>
153153
</HBox>
154154
<StackPane layoutX="14.0" layoutY="710.0" prefHeight="254.0" prefWidth="271.0">
155155
<children>

src/view/BattleMap1.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ public void initialize(){
6565
}
6666

6767
private void cardsInHand() {
68-
/*ArrayList<Card> cardsInHand = new ArrayList<>();
68+
ArrayList<Card> cardsInHand = new ArrayList<>();
6969
cardsInHand.addAll(Controller.currentGame.getActiveAccount().getMainDeck().getHand().returnHand());
7070
firstCardName.setText(cardsInHand.get(0).getName());
7171
secondCardName.setText(cardsInHand.get(1).getName());
7272
thirdCardName.setText(cardsInHand.get(2).getName());
7373
fourthCardName.setText(cardsInHand.get(3).getName());
7474
fifthCardName.setText(cardsInHand.get(4).getName());
75-
sixthCardName.setText(cardsInHand.get(5).getName());*/
75+
sixthCardName.setText(cardsInHand.get(5).getName());
7676
}
7777

7878
public void changeColor(MouseEvent mouseEvent) {

src/view/Graphic.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ public void collectionMenuFunc(MouseEvent mouseEvent) throws IOException {
5151

5252
public void battleMenuFunc(MouseEvent mouseEvent) throws IOException {
5353
Controller.currentGame = new Game();
54-
/*if (Controller.currentAccount.getMainDeck() == null || !Controller.currentAccount.getMainDeck().validated) {
54+
if (Controller.currentAccount.getMainDeck() == null || !Controller.currentAccount.getMainDeck().validated) {
5555
View.getInstance().notValidDeck();
56-
} else {*/
56+
} else {
5757
Parent battleMenu = FXMLLoader.load(view.BattleMenu.class.getResource("BattleMenu.fxml"));
5858
Stage primaryStage = UI.getInstance().getPrimaryStage();
5959
primaryStage.setTitle("Battle menu");
6060
primaryStage.setScene(new Scene(battleMenu, 3000, 1000));
6161
primaryStage.show();
62-
//}
62+
}
6363
}
6464
}

0 commit comments

Comments
 (0)