From a8953e9d5a40b0668ddfc1175c17c6af1a5f6046 Mon Sep 17 00:00:00 2001 From: Abolfazl Kashi Date: Wed, 21 Jul 2021 23:52:20 +0430 Subject: [PATCH] -code cleanup --- Client/src/main/java/Main.java | 2 +- .../controller/CardCreatorController.java | 4 +- .../src/main/java/controller/DataManager.java | 15 +- .../main/java/controller/DeckController.java | 23 ++- .../java/controller/FirstSceneController.java | 1 - .../controller/GamePlaySceneController.java | 9 +- .../java/controller/ImportController.java | 9 +- .../java/controller/ProfileController.java | 2 +- .../java/controller/RegisterController.java | 14 +- .../main/java/controller/ShopController.java | 1 - Client/src/main/java/controller/User.java | 3 - .../java/controller/gameplay/AI_Player.java | 11 +- .../java/controller/gameplay/GameManager.java | 29 ++-- Client/src/main/java/model/Command.java | 2 +- Client/src/main/java/model/Deck.java | 37 ++--- Client/src/main/java/model/UserData.java | 14 +- .../java/model/animation/CoinAnimation.java | 10 +- .../model/animation/FlipCardAnimation.java | 8 +- .../animation/RotateCenterTransition.java | 6 +- Client/src/main/java/model/cards/Card.java | 2 +- .../main/java/model/cards/MonsterCard.java | 4 +- .../main/java/model/cards/data/CardData.java | 2 +- .../java/model/cards/data/SpellCardData.java | 2 +- .../java/model/cards/data/TrapCardData.java | 2 +- .../main/java/model/effectSystem/Effect.java | 4 +- .../ChangeAllAttackDefenceMonsters.java | 2 +- .../effects/ClosedForestEffect.java | 6 +- .../effectSystem/effects/ControlAMonster.java | 1 + .../effects/EquipAMonsterAttackDefence.java | 4 +- .../effectSystem/effects/GetCardFromDeck.java | 2 +- .../effects/IncreaseLPOnSpellActivate.java | 2 +- .../java/model/gameplay/AttackResult.java | 2 +- .../main/java/model/gameplay/CardSlot.java | 6 +- .../src/main/java/model/gameplay/Player.java | 14 +- .../main/java/model/gameplay/PlayerBoard.java | 14 +- .../main/java/model/graphic/GraphicCard.java | 11 +- .../java/model/graphic/GraphicCardSlot.java | 6 +- .../main/java/model/graphic/graphicBoard.java | 18 +-- Client/src/main/java/view/CardView.java | 4 +- .../java/view/menus/CardCreatorScene.java | 4 +- .../java/view/menus/CardOptionsScene.java | 12 +- Client/src/main/java/view/menus/DeckMenu.java | 4 +- .../src/main/java/view/menus/DuelScene.java | 1 - .../main/java/view/menus/GamePlayScene.java | 20 +-- .../src/main/java/view/menus/ImportScene.java | 2 +- .../src/main/java/view/menus/LobbyMenu.java | 10 +- .../src/main/java/view/menus/MainScene.java | 13 +- .../main/java/view/menus/ProfileScene.java | 4 +- .../src/main/java/view/menus/SceneName.java | 2 +- .../main/java/view/menus/ScoreboardMenu.java | 33 ++-- .../src/main/java/view/menus/ShopScene.java | 8 +- Client/src/main/java/view/menus/TVScene.java | 9 +- Server/.idea/workspace.xml | 143 ++++++++++++------ .../main/java/controller/DeckController.java | 2 +- .../src/main/java/controller/FileManager.java | 4 +- .../controller/GameConnectionController.java | 14 +- .../main/java/controller/GameController.java | 33 ++-- .../controller/GamePlaySceneController.java | 9 +- .../java/controller/RegisterController.java | 7 +- .../java/controller/ScoreboardController.java | 2 +- .../java/controller/ServerController.java | 32 ++-- .../main/java/controller/ServerManager.java | 2 +- .../main/java/controller/ShopController.java | 16 +- .../main/java/controller/TVController.java | 12 +- .../java/controller/gameplay/GameManager.java | 28 ++-- Server/src/main/java/model/Command.java | 2 +- Server/src/main/java/model/Deck.java | 36 ++--- Server/src/main/java/model/MongoManager.java | 3 - Server/src/main/java/model/User.java | 3 - Server/src/main/java/model/UserData.java | 4 +- Server/src/main/java/model/cards/Card.java | 2 - .../main/java/model/cards/MonsterCard.java | 4 +- .../main/java/model/cards/data/CardData.java | 4 +- .../java/model/cards/data/SpellCardData.java | 2 +- .../java/model/cards/data/TrapCardData.java | 2 +- .../main/java/model/effectSystem/Effect.java | 5 +- .../ChangeAllAttackDefenceMonsters.java | 2 +- .../effects/ClosedForestEffect.java | 6 +- .../effectSystem/effects/ControlAMonster.java | 1 + .../effects/EquipAMonsterAttackDefence.java | 4 +- .../effectSystem/effects/GetCardFromDeck.java | 2 +- .../effects/IncreaseLPOnSpellActivate.java | 2 +- .../java/model/gameplay/AttackResult.java | 2 +- .../main/java/model/gameplay/CardSlot.java | 6 +- .../main/java/model/gameplay/GameBoard.java | 1 - .../src/main/java/model/gameplay/Player.java | 14 +- .../main/java/model/gameplay/PlayerBoard.java | 14 +- Server/src/main/java/view/getCommand.java | 2 +- .../main/java/view/menus/GamePlayScene.java | 2 +- 89 files changed, 419 insertions(+), 440 deletions(-) diff --git a/Client/src/main/java/Main.java b/Client/src/main/java/Main.java index 472962d..3954813 100644 --- a/Client/src/main/java/Main.java +++ b/Client/src/main/java/Main.java @@ -1,4 +1,4 @@ -import com.google.gson.*; +import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import controller.ApplicationManger; import controller.User; diff --git a/Client/src/main/java/controller/CardCreatorController.java b/Client/src/main/java/controller/CardCreatorController.java index cee4b46..4fad4eb 100644 --- a/Client/src/main/java/controller/CardCreatorController.java +++ b/Client/src/main/java/controller/CardCreatorController.java @@ -14,8 +14,8 @@ public class CardCreatorController { - private User activeUser; - private CardCreatorScene scene; + private final User activeUser; + private final CardCreatorScene scene; public CardCreatorController(CardCreatorScene cardCreatorScene) { activeUser = ApplicationManger.getLoggedInUser(); diff --git a/Client/src/main/java/controller/DataManager.java b/Client/src/main/java/controller/DataManager.java index 63c661d..5123351 100644 --- a/Client/src/main/java/controller/DataManager.java +++ b/Client/src/main/java/controller/DataManager.java @@ -65,7 +65,7 @@ public static void importCard(String cardName) { } - public static void importCardGraphic(String cardName){ + public static void importCardGraphic(String cardName) { File importDir = new File("importCards"); importDir.mkdir(); String fileLocation = "importCards/" + cardName + ".json"; @@ -85,15 +85,16 @@ public static void importCardGraphic(String cardName){ cardData = new ReadSpellTrapCardsData().readACardData(fileData.split(",")); break; default: - CardOptionsScene.setMessage("couldn't find card type"); + CardOptionsScene.setMessage("couldn't find card type"); return; } - CardOptionsScene.setMessage("card imported successfully."); + CardOptionsScene.setMessage("card imported successfully."); } catch (IOException e) { - CardOptionsScene.setMessage(e.getMessage()); + CardOptionsScene.setMessage(e.getMessage()); } } - public static void exportCardGraphic(CardData cardData){ + + public static void exportCardGraphic(CardData cardData) { File exportDir = new File("exportedCards"); exportDir.mkdir(); String fileLocation = "exportedCards/" + cardData.getCardName() + ".json"; @@ -103,9 +104,9 @@ public static void exportCardGraphic(CardData cardData){ FileWriter fileWriter = new FileWriter(fileLocation); fileWriter.write(new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().toJson(cardData)); fileWriter.close(); - CardOptionsScene.setMessage("card exported successfully."); + CardOptionsScene.setMessage("card exported successfully."); } catch (IOException e) { - CardOptionsScene.setMessage("the file isn't saved yet."); + CardOptionsScene.setMessage("the file isn't saved yet."); } } } diff --git a/Client/src/main/java/controller/DeckController.java b/Client/src/main/java/controller/DeckController.java index 642ae03..fd485f2 100644 --- a/Client/src/main/java/controller/DeckController.java +++ b/Client/src/main/java/controller/DeckController.java @@ -1,20 +1,17 @@ package controller; -import javafx.event.ActionEvent; import javafx.fxml.FXML; -import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.control.Button; import javafx.scene.control.Label; -import javafx.scene.control.ScrollBar; import javafx.scene.control.TextField; -import javafx.scene.input.KeyEvent; -import javafx.scene.layout.*; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.HBox; +import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import model.Command; import model.Deck; -import model.cards.Card; import model.cards.data.CardData; import model.cards.data.SpellCardData; import model.cards.data.TrapCardData; @@ -23,7 +20,6 @@ import model.exceptions.ParseCommandException; import view.menus.DeckMenu; import view.menus.SceneName; -import view.menus.ShopScene; import java.util.ArrayList; import java.util.Comparator; @@ -67,11 +63,11 @@ public void showMessage(String message) { addOrDeleteMessage.setOpacity(1); addOrDeleteMessage.setText(message); if (message.equals("card removed from main deck successfully") || - message.equals("card removed from side deck successfully")|| - message.equals("card added to side deck successfully")|| + message.equals("card removed from side deck successfully") || + message.equals("card added to side deck successfully") || message.equals("card added to main deck successfully")) addOrDeleteMessage.setTextFill(Color.GREEN); - else addOrDeleteMessage.setTextFill(Color.RED); + else addOrDeleteMessage.setTextFill(Color.RED); } public Button getGoToMainDeckButton() { @@ -97,7 +93,7 @@ public void setDecks(VBox scrollPane, ArrayList decks) { hBox.getChildren().add(0, deckButton); hBox.getChildren().add(1, deleteButton); System.out.println(ApplicationManger.getLoggedInUser().getUserData().getActiveDeck()); - if (ApplicationManger.getLoggedInUser().getUserData().isThereADeckThatActivated()&& + if (ApplicationManger.getLoggedInUser().getUserData().isThereADeckThatActivated() && ApplicationManger.getLoggedInUser().getUserData().getActiveDeck().getName().equals(deck.getName())) { Label setActiveLabel = new Label(); setActiveLabel.setText("active"); @@ -207,12 +203,11 @@ public Label getMessage() { public void nextDeckCreate() { String deckName = deckNameTextField.getText(); - if (deckName.equals("")){ + if (deckName.equals("")) { message.setTextFill(Color.RED); message.setOpacity(1); message.setText("You have not entered any names"); - } - else { + } else { if (Deck.isThereADeckWithThisName(deckName)) { message.setTextFill(Color.RED); message.setOpacity(1); diff --git a/Client/src/main/java/controller/FirstSceneController.java b/Client/src/main/java/controller/FirstSceneController.java index f3765de..8392c05 100644 --- a/Client/src/main/java/controller/FirstSceneController.java +++ b/Client/src/main/java/controller/FirstSceneController.java @@ -1,7 +1,6 @@ package controller; import javafx.event.ActionEvent; -import javafx.fxml.FXML; import view.menus.SceneName; public class FirstSceneController { diff --git a/Client/src/main/java/controller/GamePlaySceneController.java b/Client/src/main/java/controller/GamePlaySceneController.java index 6125144..8b2373f 100644 --- a/Client/src/main/java/controller/GamePlaySceneController.java +++ b/Client/src/main/java/controller/GamePlaySceneController.java @@ -23,7 +23,7 @@ public class GamePlaySceneController { }}; private static int currentRound; private boolean isDuelStarted = false; - private GamePlayScene scene; + private final GamePlayScene scene; private GameManager gameManager; private DuelData currentDuelData; @@ -126,9 +126,10 @@ public void gameFinished(int winnerNumber, int player1LP, int player2LP) { } public static class DuelData { - private int rounds; - private boolean isPlayer; - private UserData firstPlayer, secondPlayer; + private final int rounds; + private final boolean isPlayer; + private final UserData firstPlayer; + private final UserData secondPlayer; private int firstPlayerWins, secondPlayerWins; private int maxLP1, maxLP2; diff --git a/Client/src/main/java/controller/ImportController.java b/Client/src/main/java/controller/ImportController.java index 977cb74..355482e 100644 --- a/Client/src/main/java/controller/ImportController.java +++ b/Client/src/main/java/controller/ImportController.java @@ -1,15 +1,11 @@ package controller; -import javafx.event.ActionEvent; -import javafx.scene.control.Button; import model.cards.data.CardData; import view.menus.ImportScene; -import java.awt.*; - public class ImportController { - private ImportScene importScene; + private final ImportScene importScene; public ImportController(ImportScene importScene) { this.importScene = importScene; @@ -27,7 +23,8 @@ public void exportCard(String cardName) { } DataManager.exportCard(cardData); } - public void f(){ + + public void f() { } diff --git a/Client/src/main/java/controller/ProfileController.java b/Client/src/main/java/controller/ProfileController.java index c1a0b32..85cc0e4 100644 --- a/Client/src/main/java/controller/ProfileController.java +++ b/Client/src/main/java/controller/ProfileController.java @@ -11,7 +11,7 @@ public class ProfileController { private User activeUser; - private ProfileScene profileScene; + private final ProfileScene profileScene; public ProfileController(ProfileScene profileScene) { this.activeUser = ApplicationManger.getLoggedInUser(); diff --git a/Client/src/main/java/controller/RegisterController.java b/Client/src/main/java/controller/RegisterController.java index a54a294..e9962d1 100644 --- a/Client/src/main/java/controller/RegisterController.java +++ b/Client/src/main/java/controller/RegisterController.java @@ -16,29 +16,20 @@ import javafx.scene.control.TextField; import javafx.scene.image.Image; import javafx.scene.image.ImageView; -import javafx.scene.input.KeyEvent; import javafx.scene.layout.AnchorPane; import javafx.scene.paint.Color; import model.Command; import model.UserData; -import model.cards.data.CardData; import model.enums.ChatType; import model.enums.CommandFieldType; import model.exceptions.ParseCommandException; import view.menus.SceneName; -import view.menus.ShopScene; -import javax.imageio.ImageIO; -import javax.swing.*; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.net.MalformedURLException; -import java.net.URL; -import java.nio.file.Files; -import java.util.ArrayList; import java.util.HashMap; -import java.util.Locale; public class RegisterController { public TextField usernameOfSignup; @@ -138,8 +129,7 @@ public void nextOfSignup(ActionEvent actionEvent) throws Exception { FileWriter userFile = new FileWriter("users/" + usernameOfSignup.getText() + ".json"); userFile.write(new Gson().toJson(user.getUserData())); userFile.close(); - } - else { + } else { errorOfSignup.setText(message); errorOfSignup.setTextFill(Color.RED); } @@ -188,7 +178,7 @@ public void nextOfLogin(ActionEvent actionEvent) { System.out.println(ApplicationManger.getServerResponse("scoreboard", "scoreboard", null)); HashMap data2 = new HashMap<>(); data2.put("type", ChatType.SEND.toString()); - data2.put("message", "this is a message");; + data2.put("message", "this is a message"); System.out.println(ApplicationManger.getServerResponse("lobby", "send", data2)); ApplicationManger.goToScene1(SceneName.MAIN_MENU, false); } diff --git a/Client/src/main/java/controller/ShopController.java b/Client/src/main/java/controller/ShopController.java index 1738428..623cb2a 100644 --- a/Client/src/main/java/controller/ShopController.java +++ b/Client/src/main/java/controller/ShopController.java @@ -7,7 +7,6 @@ import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.image.ImageView; -import javafx.scene.input.KeyEvent; import javafx.scene.input.MouseEvent; import javafx.scene.layout.AnchorPane; import javafx.scene.paint.Color; diff --git a/Client/src/main/java/controller/User.java b/Client/src/main/java/controller/User.java index be00315..b267636 100644 --- a/Client/src/main/java/controller/User.java +++ b/Client/src/main/java/controller/User.java @@ -3,7 +3,6 @@ import model.Deck; import model.UserData; import model.cards.Card; -import model.enums.ChatType; import java.util.ArrayList; @@ -122,7 +121,5 @@ public static void deleteAccount(User user) { } - - } diff --git a/Client/src/main/java/controller/gameplay/AI_Player.java b/Client/src/main/java/controller/gameplay/AI_Player.java index 2800888..2733aea 100644 --- a/Client/src/main/java/controller/gameplay/AI_Player.java +++ b/Client/src/main/java/controller/gameplay/AI_Player.java @@ -18,12 +18,12 @@ import java.util.stream.Collectors; public class AI_Player { - private Deck deck = new Deck("myDeck", "AI"); - private static UserData data = new UserData("AI", "AI", "@A@I@"); + private final Deck deck = new Deck("myDeck", "AI"); + private static final UserData data = new UserData("AI", "AI", "@A@I@"); private Player playerObject; private Player opponent; private PlayerBoard board; - private GameManager gameManager; + private final GameManager gameManager; { Integer[] cards = {31, 31, 31, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12, 13}; @@ -56,7 +56,7 @@ public void playATurn() { activateSpells(); summonMonster(); Thread.sleep(1000); - if(gameManager.getTurnNumber() != 1){ + if (gameManager.getTurnNumber() != 1) { gameManager.goToNextPhase(); doAttack(); Thread.sleep(1000); @@ -216,7 +216,8 @@ private class AttackResultCalculated { private int player2LPDecrease = 0; private boolean destroyCard1 = false; private boolean destroyCard2 = false; - private MonsterCard attacker, attacked; + private final MonsterCard attacker; + private final MonsterCard attacked; public AttackResultCalculated(MonsterCard attacker, MonsterCard attacked) { this.attacker = attacker; diff --git a/Client/src/main/java/controller/gameplay/GameManager.java b/Client/src/main/java/controller/gameplay/GameManager.java index 716d8c7..c6ac338 100644 --- a/Client/src/main/java/controller/gameplay/GameManager.java +++ b/Client/src/main/java/controller/gameplay/GameManager.java @@ -44,30 +44,31 @@ public static GameManager getInstance() { return instance; } - private Player player1, player2; + private final Player player1; + private final Player player2; private int turnNumber, currentPlayerTurn; private Phase currentPhase; - private GameBoard gameBoard; + private final GameBoard gameBoard; private CardSlotAddress currentSelectedCardAddress; private Card currentSelectedCard; - private GamePlayScene scene; - private GamePlaySceneController sceneController; + private final GamePlayScene scene; + private final GamePlaySceneController sceneController; - private Event onAnSpellActivated = new Event<>(); - private Event onWantAttack = new Event<>(); - private Event onSummonACard = new Event<>(); - private Event onFlipSummon = new Event<>(); - private EventNoParam onChangeTurn = new EventNoParam(); + private final Event onAnSpellActivated = new Event<>(); + private final Event onWantAttack = new Event<>(); + private final Event onSummonACard = new Event<>(); + private final Event onFlipSummon = new Event<>(); + private final EventNoParam onChangeTurn = new EventNoParam(); protected Event destroyAMonster = new Event<>(); - private boolean isFirstSetup = false; + private final boolean isFirstSetup = false; private boolean canAttack = true; - private boolean isAI; + private final boolean isAI; private AI_Player ai; public GameManager(boolean isPlayer, UserData user1, UserData user2, GamePlayScene scene, GamePlaySceneController gamePlaySceneController) { @@ -583,9 +584,9 @@ public void finishGame(int winnerNumber) { } public class CardSlotAddress { - private boolean forOpponent; - private ZoneType zone; - private int number; + private final boolean forOpponent; + private final ZoneType zone; + private final int number; public CardSlotAddress(boolean forOpponent, ZoneType zone, int number) { this.forOpponent = forOpponent; diff --git a/Client/src/main/java/model/Command.java b/Client/src/main/java/model/Command.java index 8cad263..6fc1d31 100644 --- a/Client/src/main/java/model/Command.java +++ b/Client/src/main/java/model/Command.java @@ -9,7 +9,7 @@ import java.util.regex.Pattern; public class Command { - private HashMap fieldValues; + private final HashMap fieldValues; public Command(HashMap fieldValues) { this.fieldValues = fieldValues; diff --git a/Client/src/main/java/model/Deck.java b/Client/src/main/java/model/Deck.java index 4349b8f..c21ecff 100644 --- a/Client/src/main/java/model/Deck.java +++ b/Client/src/main/java/model/Deck.java @@ -1,7 +1,6 @@ package model; import controller.ApplicationManger; -import controller.DeckController; import model.cards.Card; import model.cards.data.CardData; import model.cards.data.SpellCardData; @@ -12,10 +11,10 @@ import java.util.Collections; public class Deck { - private ArrayList mainDeck = new ArrayList<>(); - private ArrayList sideDeck = new ArrayList<>(); - private String name; - private String username; + private final ArrayList mainDeck = new ArrayList<>(); + private final ArrayList sideDeck = new ArrayList<>(); + private final String name; + private final String username; public Deck(String name, String username) { this.name = name; @@ -36,7 +35,6 @@ public String getName() { } - public static void removeADeck(String name) { Deck deck = getDeckWithName(name); if (deck == null) return; @@ -51,31 +49,25 @@ public static Deck getDeckWithName(String name) { public static boolean isMainDeckFull(String name) { Deck deck = getDeckWithName(name); if (deck == null) return false; - if (deck.mainDeck.size() == 60) return true; - else return false; + return deck.mainDeck.size() == 60; } public static boolean isSideDeckFull(String name) { Deck deck = getDeckWithName(name); if (deck == null) return false; - if (deck.sideDeck.size() == 15) return true; - else return false; + return deck.sideDeck.size() == 15; } public static boolean isThereAreThreeCardsOfThisCardInDeck(String nameOfCard, String nameOfDeck) { Deck deck = getDeckWithName(nameOfDeck); if (deck == null) return false; - if (deck.numberOfThisCardInMainDeck(nameOfCard, nameOfDeck) + deck.numberOfThisCardInSideDeck(nameOfCard, nameOfDeck) >= 3) { - return true; - } else return false; + return deck.numberOfThisCardInMainDeck(nameOfCard, nameOfDeck) + deck.numberOfThisCardInSideDeck(nameOfCard, nameOfDeck) >= 3; } public static boolean isThereAreOneCardsOfThisCardInDeck(String nameOfCard, String nameOfDeck) { Deck deck = getDeckWithName(nameOfDeck); if (deck == null) return false; - if (deck.numberOfThisCardInMainDeck(nameOfCard, nameOfDeck) + deck.numberOfThisCardInSideDeck(nameOfCard, nameOfDeck) == 1) { - return true; - } else return false; + return deck.numberOfThisCardInMainDeck(nameOfCard, nameOfDeck) + deck.numberOfThisCardInSideDeck(nameOfCard, nameOfDeck) == 1; } public static ArrayList getCardDataArrayFromIdArray(ArrayList cardIds) { @@ -124,8 +116,7 @@ public static void addCard(String nameOfCard, String nameOfDeck, String mainOrSi public static boolean isThereThisCardInSideDeckOfThisDeck(String nameOfCard, String nameOfDeck) { Deck deck = getDeckWithName(nameOfDeck); if (deck == null) return false; - else if (deck.sideDeck.contains(nameOfCard)) return true; - else return false; + else return deck.sideDeck.contains(nameOfCard); } public static boolean isThereThisCardInMainDeckOfThisDeck(String nameOfCard, String nameOfDeck) { @@ -138,10 +129,10 @@ public static boolean isThereThisCardInMainDeckOfThisDeck(String nameOfCard, Str } } - public static void addCardGraphic(String cardName,String mainOrSide,String deckName) throws Exception { + public static void addCardGraphic(String cardName, String mainOrSide, String deckName) throws Exception { Integer cardId = Card.getCardIdByName(cardName); - CardData cardData=CardData.getCardByName(cardName); - if (mainOrSide.equals("main")){ + CardData cardData = CardData.getCardByName(cardName); + if (mainOrSide.equals("main")) { if (Deck.isMainDeckFull(deckName)) { throw new Exception("main deck is full"); } else if (Deck.isThereAreThreeCardsOfThisCardInDeck(cardName, deckName)) { @@ -156,8 +147,7 @@ public static void addCardGraphic(String cardName,String mainOrSide,String deckN Deck.addCard(cardName, deckName, "main"); ApplicationManger.getLoggedInUser().getUserData().save(); } - } - else if (mainOrSide.equals("side")){ + } else if (mainOrSide.equals("side")) { if (Deck.isSideDeckFull(deckName)) { throw new Exception("side deck is full"); } else if (Deck.isThereAreThreeCardsOfThisCardInDeck(cardName, deckName)) { @@ -189,7 +179,6 @@ public static void removeCardFromDeck(String nameOfCard, String nameOfDeck, Stri } - public static boolean isThisDeckValid(Deck deck) { return deck.mainDeck.size() >= 40; } diff --git a/Client/src/main/java/model/UserData.java b/Client/src/main/java/model/UserData.java index 76849eb..a6aa325 100644 --- a/Client/src/main/java/model/UserData.java +++ b/Client/src/main/java/model/UserData.java @@ -13,15 +13,12 @@ public class UserData { private String password; private int point = 0; private int money; - private ArrayList myCardsIds = new ArrayList<>(); - private ArrayList decks = new ArrayList<>(); + private final ArrayList myCardsIds = new ArrayList<>(); + private final ArrayList decks = new ArrayList<>(); private String activeDeckName; private String profileImageUrl; - - - public UserData(String username, String nickname, String password) { this.username = username; this.nickname = nickname; @@ -88,11 +85,10 @@ public Deck getActiveDeck() { return decks.stream().filter(e -> e.getName().equals(activeDeckName)).findFirst().orElse(null); } - public boolean isThereADeckThatActivated(){ - if (activeDeckName==null) - return false; - return true; + public boolean isThereADeckThatActivated() { + return activeDeckName != null; } + public int getMoney() { return money; } diff --git a/Client/src/main/java/model/animation/CoinAnimation.java b/Client/src/main/java/model/animation/CoinAnimation.java index 6921062..c98da0b 100644 --- a/Client/src/main/java/model/animation/CoinAnimation.java +++ b/Client/src/main/java/model/animation/CoinAnimation.java @@ -11,11 +11,11 @@ import javafx.util.Duration; public class CoinAnimation extends Transition { - private Image coinImage; - private ImageView coin; - private Rectangle2D face1; - private Rectangle2D face2; - private double toAngle; + private final Image coinImage; + private final ImageView coin; + private final Rectangle2D face1; + private final Rectangle2D face2; + private final double toAngle; private final DoubleProperty angle = new SimpleDoubleProperty(0); private boolean onFace1; diff --git a/Client/src/main/java/model/animation/FlipCardAnimation.java b/Client/src/main/java/model/animation/FlipCardAnimation.java index f2712b6..156a7b5 100644 --- a/Client/src/main/java/model/animation/FlipCardAnimation.java +++ b/Client/src/main/java/model/animation/FlipCardAnimation.java @@ -11,10 +11,10 @@ public class FlipCardAnimation extends Transition { private final DoubleProperty angleY = new SimpleDoubleProperty(0); - private GraphicCard card; - private int duration; - private boolean flipped = false; - private CardStatus toStatus; + private final GraphicCard card; + private final int duration; + private final boolean flipped = false; + private final CardStatus toStatus; public FlipCardAnimation(GraphicCard card, int duration, CardStatus to) { toStatus = to; diff --git a/Client/src/main/java/model/animation/RotateCenterTransition.java b/Client/src/main/java/model/animation/RotateCenterTransition.java index f3a475b..bf847ed 100644 --- a/Client/src/main/java/model/animation/RotateCenterTransition.java +++ b/Client/src/main/java/model/animation/RotateCenterTransition.java @@ -11,9 +11,9 @@ public class RotateCenterTransition extends Transition { private final DoubleProperty angleY = new SimpleDoubleProperty(0); - private Node node; - private int duration; - private double to; + private final Node node; + private final int duration; + private final double to; public RotateCenterTransition(Node node, int duration, double toAngle, Point3D axis) { to = toAngle; diff --git a/Client/src/main/java/model/cards/Card.java b/Client/src/main/java/model/cards/Card.java index dab808e..ba37791 100644 --- a/Client/src/main/java/model/cards/Card.java +++ b/Client/src/main/java/model/cards/Card.java @@ -14,7 +14,7 @@ import model.gameplay.Player; public abstract class Card { - private static Image cardBackImage = new Image("file:" + System.getProperty("user.dir") + "/src/main/resources/asset/gameplay/cardBack.png"); + private static final Image cardBackImage = new Image("file:" + System.getProperty("user.dir") + "/src/main/resources/asset/gameplay/cardBack.png"); protected CardType cardType; protected CardData cardData; protected CardSlot cardSlot; diff --git a/Client/src/main/java/model/cards/MonsterCard.java b/Client/src/main/java/model/cards/MonsterCard.java index 57ca6f7..0c94385 100644 --- a/Client/src/main/java/model/cards/MonsterCard.java +++ b/Client/src/main/java/model/cards/MonsterCard.java @@ -13,7 +13,7 @@ public class MonsterCard extends Card { protected Event onFaceUp = new Event<>(); - private Event onAttacked = new Event<>(); + private final Event onAttacked = new Event<>(); public MonsterCard(MonsterCardData data) { super(data); @@ -66,7 +66,7 @@ public Event getOnFaceUp() { } public void onAttacked(AttackResult result) { - if(cardStatus == CardStatus.TO_BACK) { + if (cardStatus == CardStatus.TO_BACK) { cardStatus = CardStatus.FACE_UP; } onAttacked.invoke(result); diff --git a/Client/src/main/java/model/cards/data/CardData.java b/Client/src/main/java/model/cards/data/CardData.java index 1f27d89..e706cd1 100644 --- a/Client/src/main/java/model/cards/data/CardData.java +++ b/Client/src/main/java/model/cards/data/CardData.java @@ -15,7 +15,7 @@ import java.util.regex.Pattern; public abstract class CardData { - private static ArrayList allCardData = new ArrayList<>(); + private static final ArrayList allCardData = new ArrayList<>(); @Expose protected CardType cardType; @Expose diff --git a/Client/src/main/java/model/cards/data/SpellCardData.java b/Client/src/main/java/model/cards/data/SpellCardData.java index 0acb77a..4ee8d4a 100644 --- a/Client/src/main/java/model/cards/data/SpellCardData.java +++ b/Client/src/main/java/model/cards/data/SpellCardData.java @@ -7,7 +7,7 @@ import java.util.ArrayList; public class SpellCardData extends CardData { - private static ArrayList allSpellCard = new ArrayList<>(); + private static final ArrayList allSpellCard = new ArrayList<>(); @Expose private SpellTrapProperty spellProperty; @Expose diff --git a/Client/src/main/java/model/cards/data/TrapCardData.java b/Client/src/main/java/model/cards/data/TrapCardData.java index 288f0dc..4eb99cb 100644 --- a/Client/src/main/java/model/cards/data/TrapCardData.java +++ b/Client/src/main/java/model/cards/data/TrapCardData.java @@ -7,7 +7,7 @@ import java.util.ArrayList; public class TrapCardData extends CardData { - private static ArrayList allTraps = new ArrayList<>(); + private static final ArrayList allTraps = new ArrayList<>(); @Expose private SpellTrapProperty trapProperty; @Expose diff --git a/Client/src/main/java/model/effectSystem/Effect.java b/Client/src/main/java/model/effectSystem/Effect.java index 30839fb..6db662f 100644 --- a/Client/src/main/java/model/effectSystem/Effect.java +++ b/Client/src/main/java/model/effectSystem/Effect.java @@ -10,8 +10,8 @@ public abstract class Effect { protected static GameManager gameManager; - private static Set> allEffects; - private static ArrayList effects = new ArrayList<>(); + private static final Set> allEffects; + private static final ArrayList effects = new ArrayList<>(); static { Reflections r = new Reflections("model.effectSystem.effects"); diff --git a/Client/src/main/java/model/effectSystem/effects/ChangeAllAttackDefenceMonsters.java b/Client/src/main/java/model/effectSystem/effects/ChangeAllAttackDefenceMonsters.java index e821d5a..6614ab1 100644 --- a/Client/src/main/java/model/effectSystem/effects/ChangeAllAttackDefenceMonsters.java +++ b/Client/src/main/java/model/effectSystem/effects/ChangeAllAttackDefenceMonsters.java @@ -13,7 +13,7 @@ public class ChangeAllAttackDefenceMonsters extends FieldEffect { private int changedAttack; private int changedDefence; - private ArrayList monsterTypes = new ArrayList<>(); + private final ArrayList monsterTypes = new ArrayList<>(); public ChangeAllAttackDefenceMonsters(ArrayList args) { super(args); diff --git a/Client/src/main/java/model/effectSystem/effects/ClosedForestEffect.java b/Client/src/main/java/model/effectSystem/effects/ClosedForestEffect.java index 7fb6e2f..bb63964 100644 --- a/Client/src/main/java/model/effectSystem/effects/ClosedForestEffect.java +++ b/Client/src/main/java/model/effectSystem/effects/ClosedForestEffect.java @@ -10,9 +10,9 @@ public class ClosedForestEffect extends FieldEffect { - private int changedAttack; - private int changedDefence; - private ArrayList monsterTypes = new ArrayList<>(); + private final int changedAttack; + private final int changedDefence; + private final ArrayList monsterTypes = new ArrayList<>(); public ClosedForestEffect(ArrayList args) { super(args); diff --git a/Client/src/main/java/model/effectSystem/effects/ControlAMonster.java b/Client/src/main/java/model/effectSystem/effects/ControlAMonster.java index ee80578..f90f0d4 100644 --- a/Client/src/main/java/model/effectSystem/effects/ControlAMonster.java +++ b/Client/src/main/java/model/effectSystem/effects/ControlAMonster.java @@ -10,6 +10,7 @@ public class ControlAMonster extends Effect { private CardSlot originalPosition; private Card getControlledCard; + public ControlAMonster(ArrayList args) { super(args); } diff --git a/Client/src/main/java/model/effectSystem/effects/EquipAMonsterAttackDefence.java b/Client/src/main/java/model/effectSystem/effects/EquipAMonsterAttackDefence.java index 77193a7..be1271d 100644 --- a/Client/src/main/java/model/effectSystem/effects/EquipAMonsterAttackDefence.java +++ b/Client/src/main/java/model/effectSystem/effects/EquipAMonsterAttackDefence.java @@ -7,8 +7,8 @@ public class EquipAMonsterAttackDefence extends EquipEffect { ArrayList monsterTypes = new ArrayList<>(); - private int changeAttack; - private int changeDefence; + private final int changeAttack; + private final int changeDefence; public EquipAMonsterAttackDefence(ArrayList args) { super(args); diff --git a/Client/src/main/java/model/effectSystem/effects/GetCardFromDeck.java b/Client/src/main/java/model/effectSystem/effects/GetCardFromDeck.java index 36ce71e..5fd7ec3 100644 --- a/Client/src/main/java/model/effectSystem/effects/GetCardFromDeck.java +++ b/Client/src/main/java/model/effectSystem/effects/GetCardFromDeck.java @@ -5,7 +5,7 @@ import java.util.ArrayList; public class GetCardFromDeck extends Effect { - private int n; + private final int n; public GetCardFromDeck(ArrayList args) { super(args); diff --git a/Client/src/main/java/model/effectSystem/effects/IncreaseLPOnSpellActivate.java b/Client/src/main/java/model/effectSystem/effects/IncreaseLPOnSpellActivate.java index cfee9da..5faaaf9 100644 --- a/Client/src/main/java/model/effectSystem/effects/IncreaseLPOnSpellActivate.java +++ b/Client/src/main/java/model/effectSystem/effects/IncreaseLPOnSpellActivate.java @@ -5,7 +5,7 @@ import java.util.ArrayList; public class IncreaseLPOnSpellActivate extends ContinuousEffect { - private int amount; + private final int amount; public IncreaseLPOnSpellActivate(ArrayList args) { super(args); diff --git a/Client/src/main/java/model/gameplay/AttackResult.java b/Client/src/main/java/model/gameplay/AttackResult.java index 84ce265..1f19900 100644 --- a/Client/src/main/java/model/gameplay/AttackResult.java +++ b/Client/src/main/java/model/gameplay/AttackResult.java @@ -9,7 +9,7 @@ public class AttackResult { //1 for attacker //2 for attacked - private Player attackerPlayer; + private final Player attackerPlayer; private Player attackedPlayer; private int player1LPDecrease = 0; private int player2LPDecrease = 0; diff --git a/Client/src/main/java/model/gameplay/CardSlot.java b/Client/src/main/java/model/gameplay/CardSlot.java index 8a8ede8..01757b8 100644 --- a/Client/src/main/java/model/gameplay/CardSlot.java +++ b/Client/src/main/java/model/gameplay/CardSlot.java @@ -13,8 +13,8 @@ import java.util.ArrayList; public class CardSlot { - private ZoneType zoneType; - private ArrayList cards = new ArrayList<>(); + private final ZoneType zoneType; + private final ArrayList cards = new ArrayList<>(); private boolean isSingular; private Node slotView; @@ -167,7 +167,7 @@ public Card drawParticularSpellTrap(CardType cardType, SpellTrapProperty spellTr return card; } } else if (cardType.equals(CardType.TRAP)) { - TrapCardData trapCardData = (TrapCardData) ((TrapCard) card).getCardData(); + TrapCardData trapCardData = (TrapCardData) card.getCardData(); if (trapCardData.getTrapProperty().equals(spellTrapProperty)) { this.removeACard(card); return card; diff --git a/Client/src/main/java/model/gameplay/Player.java b/Client/src/main/java/model/gameplay/Player.java index 428ac78..3bde66d 100644 --- a/Client/src/main/java/model/gameplay/Player.java +++ b/Client/src/main/java/model/gameplay/Player.java @@ -16,16 +16,16 @@ import java.util.Arrays; public class Player { - private UserData userData; + private final UserData userData; private int LP = 8000; - private PlayerBoard playerBoard; - private GameManager gameManager; + private final PlayerBoard playerBoard; + private final GameManager gameManager; private int bannedCardTurn = 0; private int trapBanned = 0; - private int playerNumber; + private final int playerNumber; private boolean summonOrSetInThisTurn = false; - private EventNoParam onChangeTurnEvent = new EventNoParam(); + private final EventNoParam onChangeTurnEvent = new EventNoParam(); public Player(UserData userData, PlayerBoard playerBoard, GameManager gameManager, int playerNumber) { this.userData = userData; @@ -104,8 +104,8 @@ public void drawCard(int n, EventNoParam onEnd) { playerBoard.getHand().appendCard(c); //gameManager.getScene().draw(playerBoard.getPlayerNumber(), playerBoard.getDeckZone().getAllCards().size(), event -> drawCard(n - 1, onEnd)); - Platform.runLater(()->{ - gameManager.getScene().draw(playerBoard.getPlayerNumber(), playerBoard.getDeckZone().getAllCards().size(), event -> drawCard(n - 1, onEnd)); + Platform.runLater(() -> { + gameManager.getScene().draw(playerBoard.getPlayerNumber(), playerBoard.getDeckZone().getAllCards().size(), event -> drawCard(n - 1, onEnd)); }); System.out.println("new card added to the hand: " + c.getCardData().getCardName()); diff --git a/Client/src/main/java/model/gameplay/PlayerBoard.java b/Client/src/main/java/model/gameplay/PlayerBoard.java index 093f9e1..83f112f 100644 --- a/Client/src/main/java/model/gameplay/PlayerBoard.java +++ b/Client/src/main/java/model/gameplay/PlayerBoard.java @@ -15,18 +15,18 @@ import java.util.Collections; public class PlayerBoard { - private CardSlot graveyard = new CardSlot(ZoneType.GRAVEYARD); - private CardSlot deckZone = new CardSlot(ZoneType.DECK); - private CardSlot fieldZone = new CardSlot(ZoneType.FIELD); - private ArrayList monsterZone = new ArrayList(5) {{ + private final CardSlot graveyard = new CardSlot(ZoneType.GRAVEYARD); + private final CardSlot deckZone = new CardSlot(ZoneType.DECK); + private final CardSlot fieldZone = new CardSlot(ZoneType.FIELD); + private final ArrayList monsterZone = new ArrayList(5) {{ for (int i = 0; i < 5; i++) add(new CardSlot(i + 1, ZoneType.MONSTER)); }}; - private ArrayList spellAndTrapZone = new ArrayList(5) {{ + private final ArrayList spellAndTrapZone = new ArrayList(5) {{ for (int i = 0; i < 5; i++) add(new CardSlot(i + 1, ZoneType.SPELL_AND_TRAP)); }}; - private CardSlot hand = new CardSlot(ZoneType.HAND); + private final CardSlot hand = new CardSlot(ZoneType.HAND); - private int playerNumber; + private final int playerNumber; public PlayerBoard(Deck playerDeck, int playerNumber, AnchorPane group) { this.playerNumber = playerNumber; diff --git a/Client/src/main/java/model/graphic/GraphicCard.java b/Client/src/main/java/model/graphic/GraphicCard.java index c860f29..9cda375 100644 --- a/Client/src/main/java/model/graphic/GraphicCard.java +++ b/Client/src/main/java/model/graphic/GraphicCard.java @@ -10,19 +10,18 @@ import model.cards.data.CardData; import model.enums.CardStatus; import model.enums.ZoneType; -import model.gameplay.CardSlot; import view.CardView; import view.menus.GamePlayScene; public class GraphicCard { - private static Image back = new Image("file:" + System.getProperty("user.dir") + "/src/main/resources/asset/gameplay/cardBack.png"); - private Image face; - private ImageView shape; - private CardData data; + private static final Image back = new Image("file:" + System.getProperty("user.dir") + "/src/main/resources/asset/gameplay/cardBack.png"); + private final Image face; + private final ImageView shape; + private final CardData data; private GraphicCardSlot slot; private CardStatus status = CardStatus.TO_BACK; private boolean toAttackPosition = true; - private int cardOwnerPlayerNumber; + private final int cardOwnerPlayerNumber; public GraphicCard(CardData cardData, int cardOwnerNumber) { cardOwnerPlayerNumber = cardOwnerNumber; diff --git a/Client/src/main/java/model/graphic/GraphicCardSlot.java b/Client/src/main/java/model/graphic/GraphicCardSlot.java index 675c490..8849a91 100644 --- a/Client/src/main/java/model/graphic/GraphicCardSlot.java +++ b/Client/src/main/java/model/graphic/GraphicCardSlot.java @@ -6,10 +6,10 @@ import java.util.ArrayList; public class GraphicCardSlot { - private ArrayList cards = new ArrayList<>(); - private ZoneType type; + private final ArrayList cards = new ArrayList<>(); + private final ZoneType type; private int number; - private Node imageView; + private final Node imageView; public GraphicCardSlot(ZoneType type, Node imageView) { this.type = type; diff --git a/Client/src/main/java/model/graphic/graphicBoard.java b/Client/src/main/java/model/graphic/graphicBoard.java index 8c74da3..03ff6df 100644 --- a/Client/src/main/java/model/graphic/graphicBoard.java +++ b/Client/src/main/java/model/graphic/graphicBoard.java @@ -12,8 +12,8 @@ import java.util.ArrayList; public class graphicBoard { - private GraphicPlayerBoard player1Board; - private GraphicPlayerBoard player2Board; + private final GraphicPlayerBoard player1Board; + private final GraphicPlayerBoard player2Board; public graphicBoard(AnchorPane board) { player1Board = new GraphicPlayerBoard(1, (AnchorPane) board.lookup("#player1Board")); @@ -43,14 +43,14 @@ public GraphicCardSlot getCardSlot(boolean forOpponent, ZoneType zone, int numbe } public class GraphicPlayerBoard { - private AnchorPane playerBoard; - private GraphicCardSlot deck; - private GraphicCardSlot hand; - private ArrayList monster = new ArrayList<>(5); - private ArrayList spell = new ArrayList<>(5); + private final AnchorPane playerBoard; + private final GraphicCardSlot deck; + private final GraphicCardSlot hand; + private final ArrayList monster = new ArrayList<>(5); + private final ArrayList spell = new ArrayList<>(5); private GraphicCardSlot field; - private GraphicCardSlot graveyard; - private int playerNumber; + private final GraphicCardSlot graveyard; + private final int playerNumber; public GraphicPlayerBoard(int playerNumber, AnchorPane playerBoard) { this.playerBoard = playerBoard; diff --git a/Client/src/main/java/view/CardView.java b/Client/src/main/java/view/CardView.java index 4f53232..f64b7cf 100644 --- a/Client/src/main/java/view/CardView.java +++ b/Client/src/main/java/view/CardView.java @@ -18,11 +18,11 @@ public static CardView getInstance() { return instance; } - public void initialize(){ + public void initialize() { instance = this; } - public void showCard(CardData cardData){ + public void showCard(CardData cardData) { cardImage.setImage(cardData.getCardImage()); description.setText(cardData.toString()); } diff --git a/Client/src/main/java/view/menus/CardCreatorScene.java b/Client/src/main/java/view/menus/CardCreatorScene.java index 86341a7..2e4ead3 100644 --- a/Client/src/main/java/view/menus/CardCreatorScene.java +++ b/Client/src/main/java/view/menus/CardCreatorScene.java @@ -30,8 +30,8 @@ public class CardCreatorScene extends Scene { public Label message; public Label cardPrice; public ChoiceBox monsterCardType; - private CardCreatorController controller; - private HashMap effects = new HashMap<>(); + private final CardCreatorController controller; + private final HashMap effects = new HashMap<>(); public CardCreatorScene() { this.controller = new CardCreatorController(this); diff --git a/Client/src/main/java/view/menus/CardOptionsScene.java b/Client/src/main/java/view/menus/CardOptionsScene.java index b987d94..4dd9f62 100644 --- a/Client/src/main/java/view/menus/CardOptionsScene.java +++ b/Client/src/main/java/view/menus/CardOptionsScene.java @@ -12,7 +12,7 @@ public class CardOptionsScene extends Scene { public Button next; public TextField cardName; - public Label message; + public Label message; public Label cardNameLabel; String name; private static String messageText; @@ -34,7 +34,7 @@ public void importCardRun(ActionEvent actionEvent) { next.setOpacity(1); cardNameLabel.setOpacity(1); next.setOnMouseClicked(event -> { - name=cardName.getText(); + name = cardName.getText(); DataManager.importCardGraphic(name); showMessage(messageText); }); @@ -48,7 +48,7 @@ public void exportCardRun(ActionEvent actionEvent) { next.setOpacity(1); cardNameLabel.setOpacity(1); next.setOnMouseClicked(event -> { - name=cardName.getText(); + name = cardName.getText(); CardData cardData = CardData.getCardByName(name); if (cardData == null) { message.setText("There is no card with this name."); @@ -64,11 +64,11 @@ public void back(ActionEvent actionEvent) { } - public static void setMessage(String messageText1){ - messageText=messageText1; + public static void setMessage(String messageText1) { + messageText = messageText1; } - public void showMessage(String messageText){ + public void showMessage(String messageText) { message.setText(messageText); } } diff --git a/Client/src/main/java/view/menus/DeckMenu.java b/Client/src/main/java/view/menus/DeckMenu.java index b2c3ac2..613eadb 100644 --- a/Client/src/main/java/view/menus/DeckMenu.java +++ b/Client/src/main/java/view/menus/DeckMenu.java @@ -21,8 +21,8 @@ public class DeckMenu extends Scene { - private User activeUser; - private DeckController deckController; + private final User activeUser; + private final DeckController deckController; public void setCards(AnchorPane anchorPane, ArrayList cards, String scrollPaneType, String deckName) { diff --git a/Client/src/main/java/view/menus/DuelScene.java b/Client/src/main/java/view/menus/DuelScene.java index 2b82398..2e89d2a 100644 --- a/Client/src/main/java/view/menus/DuelScene.java +++ b/Client/src/main/java/view/menus/DuelScene.java @@ -2,7 +2,6 @@ import controller.ApplicationManger; import controller.DuelController; -import javafx.application.Application; import javafx.event.ActionEvent; import javafx.scene.control.CheckBox; import javafx.scene.control.Label; diff --git a/Client/src/main/java/view/menus/GamePlayScene.java b/Client/src/main/java/view/menus/GamePlayScene.java index 110f164..21bea82 100644 --- a/Client/src/main/java/view/menus/GamePlayScene.java +++ b/Client/src/main/java/view/menus/GamePlayScene.java @@ -294,11 +294,7 @@ public void changePhase(Phase toPhase, int currentPlayer) { currentPhaseLabel.getStyleClass().clear(); currentPhaseLabel.getStyleClass().add("redPlayer"); } - if (currentPlayer != playerNumber) { - nextPhaseButton.setVisible(false); - } else { - nextPhaseButton.setVisible(true); - } + nextPhaseButton.setVisible(currentPlayer == playerNumber); } private int cheatCommand(String userInput) { @@ -607,13 +603,13 @@ public void applyAttackResultGraphic(AttackResultJson result, int playerNumber, } public static class AttackResultJson { - private int attackerPlayerNumber; - private int attackedPlayerNumber; - private int player1LPDecrease; - private int player2LPDecrease; - private boolean destroyCard1; - private boolean destroyCard2; - private boolean attackedFlip; + private final int attackerPlayerNumber; + private final int attackedPlayerNumber; + private final int player1LPDecrease; + private final int player2LPDecrease; + private final boolean destroyCard1; + private final boolean destroyCard2; + private final boolean attackedFlip; public AttackResultJson(AttackResult attackResult) { attackerPlayerNumber = attackResult.getAttackerPlayer().getPlayerNumber(); diff --git a/Client/src/main/java/view/menus/ImportScene.java b/Client/src/main/java/view/menus/ImportScene.java index 2f37c8c..c59cbfe 100644 --- a/Client/src/main/java/view/menus/ImportScene.java +++ b/Client/src/main/java/view/menus/ImportScene.java @@ -8,7 +8,7 @@ public class ImportScene extends Scene { - private ImportController importController; + private final ImportController importController; public ImportScene() { importController = new ImportController(this); diff --git a/Client/src/main/java/view/menus/LobbyMenu.java b/Client/src/main/java/view/menus/LobbyMenu.java index ef0cb1f..de3b504 100644 --- a/Client/src/main/java/view/menus/LobbyMenu.java +++ b/Client/src/main/java/view/menus/LobbyMenu.java @@ -34,9 +34,9 @@ public class LobbyMenu { public Label editedMessageLabel; public Button editButton; public Button cancelButton; - private ArrayList idOfMessage = new ArrayList<>(); + private final ArrayList idOfMessage = new ArrayList<>(); - private static int idCounter = 0; + private static final int idCounter = 0; private boolean isGameStarted = false; @@ -305,9 +305,9 @@ public void refresh(ActionEvent actionEvent) { class DuelData { - private UserData user1Data; - private UserData user2Data; - private int rounds; + private final UserData user1Data; + private final UserData user2Data; + private final int rounds; public DuelData(UserData user1Data, UserData user2Data, int rounds) { this.user1Data = user1Data; diff --git a/Client/src/main/java/view/menus/MainScene.java b/Client/src/main/java/view/menus/MainScene.java index 3f4daf9..03042dc 100644 --- a/Client/src/main/java/view/menus/MainScene.java +++ b/Client/src/main/java/view/menus/MainScene.java @@ -3,19 +3,14 @@ import controller.ApplicationManger; import controller.MainMenuController; import javafx.animation.SequentialTransition; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; -import javafx.event.EventHandler; import javafx.fxml.FXML; import javafx.geometry.Rectangle2D; import javafx.scene.Cursor; -import javafx.scene.Node; import javafx.scene.control.Label; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.MouseEvent; import javafx.scene.paint.Color; -import javafx.scene.text.Font; import javafx.util.Duration; import model.animation.SpriteAnimation; @@ -89,16 +84,16 @@ void initialize() { private void setTV() { tv.setCursor(Cursor.HAND); tv.setOnMouseEntered(event -> { - setRatio(1.2, tv); + setRatio(1.2, tv); }); tv.setOnMouseExited(event -> { - setRatio(1/1.2, tv); + setRatio(1 / 1.2, tv); }); } private void setRatio(double ratio, ImageView node) { node.setLayoutX(node.getLayoutX() + node.getFitWidth() * -0.5 * (ratio - 1)); - node.setLayoutY(node.getLayoutY() + node.getFitHeight() * - 0.5 * (ratio - 1)); + node.setLayoutY(node.getLayoutY() + node.getFitHeight() * -0.5 * (ratio - 1)); node.setFitWidth(node.getFitWidth() * ratio); node.setFitHeight(node.getFitHeight() * ratio); } @@ -201,6 +196,6 @@ public void card(MouseEvent mouseEvent) { } public void enterTV(MouseEvent mouseEvent) { - goToScene1(SceneName.TV_SCENE, false); + goToScene1(SceneName.TV_SCENE, false); } } diff --git a/Client/src/main/java/view/menus/ProfileScene.java b/Client/src/main/java/view/menus/ProfileScene.java index 38a5865..e66f4ba 100644 --- a/Client/src/main/java/view/menus/ProfileScene.java +++ b/Client/src/main/java/view/menus/ProfileScene.java @@ -146,11 +146,11 @@ public void back(ActionEvent actionEvent) { } public void showScoreboard(ActionEvent actionEvent) { - ApplicationManger.goToScene1(SceneName.SCOREBOARD_MENU,false); + ApplicationManger.goToScene1(SceneName.SCOREBOARD_MENU, false); } public void logout(ActionEvent actionEvent) { System.out.println(getServerResponse("register", "logout", null)); - ApplicationManger.goToScene1(SceneName.FIRST_SCENE,false); + ApplicationManger.goToScene1(SceneName.FIRST_SCENE, false); } } diff --git a/Client/src/main/java/view/menus/SceneName.java b/Client/src/main/java/view/menus/SceneName.java index f6f1608..95fba76 100644 --- a/Client/src/main/java/view/menus/SceneName.java +++ b/Client/src/main/java/view/menus/SceneName.java @@ -13,5 +13,5 @@ public enum SceneName { GAMEPLAY_SCENE, DUEL_SCENE, LOBBY_SCENE, - TV_SCENE; + TV_SCENE } diff --git a/Client/src/main/java/view/menus/ScoreboardMenu.java b/Client/src/main/java/view/menus/ScoreboardMenu.java index c2b9645..1c1c6ff 100644 --- a/Client/src/main/java/view/menus/ScoreboardMenu.java +++ b/Client/src/main/java/view/menus/ScoreboardMenu.java @@ -8,19 +8,12 @@ import javafx.fxml.FXML; import javafx.geometry.Pos; import javafx.scene.control.Label; -import javafx.scene.control.ScrollBar; -import javafx.scene.control.ScrollPane; import javafx.scene.input.MouseEvent; -import javafx.scene.layout.Background; -import javafx.scene.layout.BackgroundFill; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; -import javafx.scene.paint.Paint; import model.UserData; -import javax.swing.*; -import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; @@ -32,26 +25,26 @@ public class ScoreboardMenu extends Scene { @FXML void initialize() { - int i,size,counter=0; + int i, size, counter = 0; int[] ranks; - String result=ApplicationManger.getServerResponse("scoreboard","scoreboard",null); + String result = ApplicationManger.getServerResponse("scoreboard", "scoreboard", null); JsonElement jsonElement = JsonParser.parseString(result); JsonObject jsonObject = jsonElement.getAsJsonObject(); String returnObject = jsonObject.get("returnObject").getAsString(); String[] parts = returnObject.split(","); - HashMap jsonHash = new HashMap<>(); - for(i=0;i jsonHash = new HashMap<>(); + for (i = 0; i < parts.length; i++) { + parts[i] = parts[i].replace("\"", ""); + parts[i] = parts[i].replace("{", ""); + parts[i] = parts[i].replace("}", ""); + parts[i] = parts[i].replace(" ", ""); String[] subparts = parts[i].split("="); - if (i==20) break; - jsonHash.put(subparts[0],Integer.parseInt(subparts[1])); + if (i == 20) break; + jsonHash.put(subparts[0], Integer.parseInt(subparts[1])); } size = Math.min(20, parts.length); ranks = getRankServer(jsonHash, size); - for (String j:jsonHash.keySet()) { + for (String j : jsonHash.keySet()) { Label rank = new Label(); Label nickName = new Label(); Label point = new Label(); @@ -201,11 +194,11 @@ public int[] getRank(UserData[] topPlayers, int size) { return rank; } - public int[] getRankServer(HashMap jsonHash,int size){ + public int[] getRankServer(HashMap jsonHash, int size) { int counterOfSamePoint = 1; int pointOfPreviousUser = 0; int[] rank = new int[size]; - int i,counter=0; + int i, counter = 0; for (i = 0; i < size; i++) rank[i] = i; for (String j : jsonHash.keySet()) { if (jsonHash.get(j) == pointOfPreviousUser) { diff --git a/Client/src/main/java/view/menus/ShopScene.java b/Client/src/main/java/view/menus/ShopScene.java index a9e7ec0..36d70bc 100644 --- a/Client/src/main/java/view/menus/ShopScene.java +++ b/Client/src/main/java/view/menus/ShopScene.java @@ -24,8 +24,8 @@ public class ShopScene extends Scene { - private User activeUser; - private ShopController shopController; + private final User activeUser; + private final ShopController shopController; private Label cardPrice; private Label userMoney; private Label message; @@ -139,11 +139,11 @@ private void addCardImage(AnchorPane anchorPane, CardData cardData, int index, b if (isBuying) { if (isBanned) { message.setText("this card is banned"); - }else if (inventory < 1) { + } else if (inventory < 1) { message.setText("there is no card in the inventory"); } else if (activeUser.getUserData().getMoney() < cardData.getPrice()) { notEnoughMoneyAction(); - }else { + } else { buyCard(cardData); } } else { diff --git a/Client/src/main/java/view/menus/TVScene.java b/Client/src/main/java/view/menus/TVScene.java index 9c34541..e122baf 100644 --- a/Client/src/main/java/view/menus/TVScene.java +++ b/Client/src/main/java/view/menus/TVScene.java @@ -6,19 +6,12 @@ import com.google.gson.JsonParser; import controller.ApplicationManger; import javafx.event.ActionEvent; -import javafx.event.EventHandler; import javafx.fxml.FXML; -import javafx.geometry.Insets; import javafx.scene.Cursor; import javafx.scene.control.Button; import javafx.scene.control.Label; -import javafx.scene.input.MouseEvent; import javafx.scene.layout.AnchorPane; -import javafx.scene.layout.Background; -import javafx.scene.layout.BackgroundFill; -import javafx.scene.layout.CornerRadii; import javafx.scene.text.Font; -import javafx.scene.paint.Color; import java.util.HashMap; @@ -44,7 +37,7 @@ private void buttonInit(Button button, double ratio) { private void setButtonRatio(double ratio, Button node) { node.setLayoutX(node.getLayoutX() + node.getPrefWidth() * -0.5 * (ratio - 1)); - node.setLayoutY(node.getLayoutY() + node.getPrefHeight() * - 0.5 * (ratio - 1)); + node.setLayoutY(node.getLayoutY() + node.getPrefHeight() * -0.5 * (ratio - 1)); node.setPrefWidth(node.getPrefWidth() * ratio); node.setPrefHeight(node.getPrefHeight() * ratio); //node.setTextFill(ratio > 1 ? Color.YELLOW : Color.WHITE); diff --git a/Server/.idea/workspace.xml b/Server/.idea/workspace.xml index 21ac1d5..a8179b0 100644 --- a/Server/.idea/workspace.xml +++ b/Server/.idea/workspace.xml @@ -2,17 +2,95 @@ - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +