From a6c1db18fa8553c5adebce8d6c0e3fd2c9f0ccaf Mon Sep 17 00:00:00 2001 From: Abolfazl Ghalandary Date: Sun, 11 Jul 2021 00:06:53 +0430 Subject: [PATCH] reformat code & make ready for presentation --- .../yugioh/controller/CheatController.java | 6 +- .../yugioh/controller/DataBaseController.java | 106 ++++++++-------- .../BattlePhaseController.java | 5 +- .../CardSelectionMenuController.java | 41 +++--- .../DrawPhaseController.java | 8 +- .../gamephasescontrollers/GameController.java | 34 +++-- .../MainPhasesController.java | 70 +++++------ .../CardGeneratorMenuController.java | 117 +++++++++--------- .../menucontroller/DeckMenuController.java | 4 +- .../DetermineStarterMenuController.java | 1 - .../menucontroller/DuelMenuController.java | 6 - .../EditDeckMenuController.java | 1 - .../menucontroller/GameMenuController.java | 9 +- .../menucontroller/MenuController.java | 2 +- .../menucontroller/ProfileMenuController.java | 2 +- src/main/java/yugioh/model/Player.java | 7 +- src/main/java/yugioh/model/board/Cell.java | 9 +- .../java/yugioh/model/board/GameBoard.java | 33 +++-- src/main/java/yugioh/model/cards/Card.java | 27 ++-- .../java/yugioh/model/cards/SpellAndTrap.java | 26 ++-- .../model/cards/monsters/Texchanger.java | 29 ++--- .../model/cards/trapandspells/Forest.java | 4 +- .../cards/trapandspells/NegateAttack.java | 4 +- .../cards/trapandspells/Terraforming.java | 2 +- .../model/cards/trapandspells/Umiiruka.java | 4 +- .../view/gamephases/CardActionsMenu.java | 30 ++--- .../view/gamephases/CardSelectionMenu.java | 4 +- .../java/yugioh/view/gamephases/Duel.java | 2 - .../yugioh/view/gamephases/Graveyard.java | 1 - .../yugioh/view/gamephases/MainPhase1.java | 2 +- .../yugioh/view/gamephases/MainPhase2.java | 5 +- .../yugioh/view/menus/CardGeneratorMenu.java | 4 - .../view/menus/DetermineStarterMenu.java | 1 - .../java/yugioh/view/menus/EndOfGameMenu.java | 57 ++++----- src/main/java/yugioh/view/menus/Toast.java | 5 +- 35 files changed, 301 insertions(+), 367 deletions(-) diff --git a/src/main/java/yugioh/controller/CheatController.java b/src/main/java/yugioh/controller/CheatController.java index f001a698..ba060e28 100644 --- a/src/main/java/yugioh/controller/CheatController.java +++ b/src/main/java/yugioh/controller/CheatController.java @@ -58,11 +58,11 @@ public String selectHandForce(String cardName, GameController gameController) th return response; } - public String addOptionalCardAndSelect(String cardName, GameController gameController,boolean shouldBeSelected) throws GameException { + public String addOptionalCardAndSelect(String cardName, GameController gameController, boolean shouldBeSelected) throws GameException { Card toBeAdded = Card.getNewCardObjectByName(cardName); if (toBeAdded == null) throw new GameException(Responses.NO_CARD_EXISTS.response); - gameController.getDrawPhaseController().addCardToHandDeck(gameController.getCurrentTurnPlayer(), toBeAdded,shouldBeSelected); + gameController.getDrawPhaseController().addCardToHandDeck(gameController.getCurrentTurnPlayer(), toBeAdded, shouldBeSelected); return "new card added to the hand and selected: " + cardName; } @@ -101,7 +101,7 @@ public String processCommand(String command) { } else if (command.matches(GameRegexes.CHEAT_ADD_OPTIONAL_CARD.regex)) { Matcher matcher = ViewInterface.getCommandMatcher(command, GameRegexes.CHEAT_ADD_OPTIONAL_CARD.regex); try { - response = addOptionalCardAndSelect(matcher.group(1), Duel.getGameController(),false); + response = addOptionalCardAndSelect(matcher.group(1), Duel.getGameController(), false); } catch (GameException e) { response = e.toString(); } diff --git a/src/main/java/yugioh/controller/DataBaseController.java b/src/main/java/yugioh/controller/DataBaseController.java index fd29f018..7f3c6d58 100644 --- a/src/main/java/yugioh/controller/DataBaseController.java +++ b/src/main/java/yugioh/controller/DataBaseController.java @@ -77,25 +77,20 @@ public static void saveUserInfo(User user) throws IOException { } public static void saveCardInfo(Card card) throws IOException { - // writeJSON(card,"src\\resources\\cards\\" + card.getName() + ".json"); + // writeJSON(card,"src\\resources\\cards\\" + card.getName() + ".json"); if (card.getCardKind() == Card.Kind.MAGIC) { SpellAndTrap spellAndTrap = (SpellAndTrap) card; writeJSON(spellAndTrap, "src\\resources\\cards\\SpellAndTraps\\" + card.getName() + ".json"); } else { Monster monster = (Monster) card; - if(!card.isCustom) - writeJSON(monster, "src\\resources\\cards\\Monsters\\" + card.getName() + ".json"); - else{ + if (!card.isCustom) + writeJSON(monster, "src\\resources\\cards\\Monsters\\" + card.getName() + ".json"); + else { writeJSON(monster, "src\\resources\\cards\\Monsters\\Customs\\" + card.getName() + ".json"); } } } - public void setImportExportMenuBackground(){ - MediaPlayer mediaPlayer = new MediaPlayer(new Media(new File("src\\resources\\yugioh\\Backgrounds\\main.mp4").toURI().toString())); - mediaPlayer.play(); - mediaPlayer.setCycleCount(-1); - importExportMenuBackground.setMediaPlayer(mediaPlayer); - } + public static void writeFile(String fileAddress, String content) throws IOException { FileWriter writer = new FileWriter(fileAddress); writer.write(content); @@ -118,21 +113,21 @@ public static void usersDataBaseInitialization() throws FileNotFoundException { User.setAllUsers(dataBaseUsers); } - public static void cardsDataBaseInitialization()throws FileNotFoundException { + public static void cardsDataBaseInitialization() throws FileNotFoundException { initializeMonsterCards(); initializeMagicCards(); } - private static void initializeMonsterCards() throws FileNotFoundException{ - File cardsFolder=new File("src\\resources\\cards\\Monsters\\Customs"); + private static void initializeMonsterCards() throws FileNotFoundException { + File cardsFolder = new File("src\\resources\\cards\\Monsters\\Customs"); GsonBuilder builder = new GsonBuilder(); Gson gson = builder.create(); - for(File file:cardsFolder.listFiles()){ - if(file.getPath().endsWith(".json")){ + for (File file : cardsFolder.listFiles()) { + if (file.getPath().endsWith(".json")) { BufferedReader bufferedReader = new BufferedReader( new FileReader(file.getPath()) ); - Monster monster=gson.fromJson(bufferedReader,Monster.class); + Monster monster = gson.fromJson(bufferedReader, Monster.class); Card.allCards.add(monster); } } @@ -179,7 +174,7 @@ private static void initializeMonsterCards() throws FileNotFoundException{ Card CommandKnight = new CommandKnight(); } - private static void initializeMagicCards()throws FileNotFoundException { + private static void initializeMagicCards() throws FileNotFoundException { // File cardsFolder=new File("src\\resources\\cards\\SpellAndTraps"); // GsonBuilder builder = new GsonBuilder(); // Gson gson = builder.create(); @@ -192,41 +187,48 @@ private static void initializeMagicCards()throws FileNotFoundException { // Card.allCards.add(spellAndTrap); // } // } - Card TrapHole = new TrapHole(); - Card MirrorForce = new MirrorForce(); - Card MagicCylinder = new MagicCylinder(); - Card MindCrush = new MindCrush(); - Card TorrentialTribute = new TorrentialTribute(); - Card TimeSeal = new TimeSeal(); - Card NegateAttack = new NegateAttack(); - Card SolemnWarning = new SolemnWarning(); - Card MagicJamamer = new MagicJamamer(); - Card CallofTheHaunted = new CallofTheHaunted(); - Card VanitysEmptiness = new VanitysEmptiness(); - Card WallofRevealingLight = new WallofRevealingLight(); - Card MonsterReborn = new MonsterReborn(); - Card Terraforming = new Terraforming(); - Card PotofGreed = new PotofGreed(); - Card Raigeki = new Raigeki(); - Card ChangeofHeart = new ChangeofHeart(); - Card SwordsofRevealingLight = new SwordsofRevealingLight(); - Card HarpiesFeatherDuster = new HarpiesFeatherDuster(); - Card DarkHole = new DarkHole(); - Card SupplySquad = new SupplySquad(); - Card SpellAbsorption = new SpellAbsorption(); - Card Messengerofpeace = new Messengerofpeace(); - Card TwinTwisters = new TwinTwisters(); - Card Mysticalspacetyphoon = new Mysticalspacetyphoon(); - Card Ringofdefense = new Ringofdefense(); - Card Yami = new Yami(); - Card Forest = new Forest(); - Card ClosedForest = new ClosedForest(); - Card Umiiruka = new Umiiruka(); - Card Swordofdarkdestruction = new Swordofdarkdestruction(); - Card BlackPendant = new BlackPendant(); - Card UnitedWeStand = new UnitedWeStand(); - Card MagnumShield = new MagnumShield(); - Card AdvancedRitualArt = new AdvancedRitualArt(); + Card TrapHole = new TrapHole(); + Card MirrorForce = new MirrorForce(); + Card MagicCylinder = new MagicCylinder(); + Card MindCrush = new MindCrush(); + Card TorrentialTribute = new TorrentialTribute(); + Card TimeSeal = new TimeSeal(); + Card NegateAttack = new NegateAttack(); + Card SolemnWarning = new SolemnWarning(); + Card MagicJamamer = new MagicJamamer(); + Card CallofTheHaunted = new CallofTheHaunted(); + Card VanitysEmptiness = new VanitysEmptiness(); + Card WallofRevealingLight = new WallofRevealingLight(); + Card MonsterReborn = new MonsterReborn(); + Card Terraforming = new Terraforming(); + Card PotofGreed = new PotofGreed(); + Card Raigeki = new Raigeki(); + Card ChangeofHeart = new ChangeofHeart(); + Card SwordsofRevealingLight = new SwordsofRevealingLight(); + Card HarpiesFeatherDuster = new HarpiesFeatherDuster(); + Card DarkHole = new DarkHole(); + Card SupplySquad = new SupplySquad(); + Card SpellAbsorption = new SpellAbsorption(); + Card Messengerofpeace = new Messengerofpeace(); + Card TwinTwisters = new TwinTwisters(); + Card Mysticalspacetyphoon = new Mysticalspacetyphoon(); + Card Ringofdefense = new Ringofdefense(); + Card Yami = new Yami(); + Card Forest = new Forest(); + Card ClosedForest = new ClosedForest(); + Card Umiiruka = new Umiiruka(); + Card Swordofdarkdestruction = new Swordofdarkdestruction(); + Card BlackPendant = new BlackPendant(); + Card UnitedWeStand = new UnitedWeStand(); + Card MagnumShield = new MagnumShield(); + Card AdvancedRitualArt = new AdvancedRitualArt(); + } + + public void setImportExportMenuBackground() { + MediaPlayer mediaPlayer = new MediaPlayer(new Media(new File("src\\resources\\yugioh\\Backgrounds\\main.mp4").toURI().toString())); + mediaPlayer.play(); + mediaPlayer.setCycleCount(-1); + importExportMenuBackground.setMediaPlayer(mediaPlayer); } public String readFileContent(String address) { diff --git a/src/main/java/yugioh/controller/gamephasescontrollers/BattlePhaseController.java b/src/main/java/yugioh/controller/gamephasescontrollers/BattlePhaseController.java index 0e6a6c81..025289e9 100644 --- a/src/main/java/yugioh/controller/gamephasescontrollers/BattlePhaseController.java +++ b/src/main/java/yugioh/controller/gamephasescontrollers/BattlePhaseController.java @@ -126,7 +126,7 @@ private void activateTrapIfCanBeActivated(GameController gameController, boolean } } new Thread(() -> { - Platform.runLater(()->{ + Platform.runLater(() -> { while (!gameController.getGameMenuController().choiceHasBeenMade || gameController.getGameMenuController().shouldActivateEffectsNow == true) { } @@ -194,7 +194,8 @@ private String attackToDefensiveHiddenCell(Cell attackerCell, Cell attackedCell, response += Marshmallon.handleEffect(gameController, attackerCell, attackedCell); if (!Marshmallon.isMarshmallon(attackedCell)) { Rectangle graveyard = GameMenuController.getGameMenuController().rivalGraveyard; - if (CardActionsMenu.isBoardInverse()) graveyard = GameMenuController.getGameMenuController().userGraveyard; + if (CardActionsMenu.isBoardInverse()) + graveyard = GameMenuController.getGameMenuController().userGraveyard; Rectangle finalGraveyard = graveyard; Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(2), event -> { moveCardToGraveyard(attackedCell, finalGraveyard, gameController.currentTurnOpponentPlayer); diff --git a/src/main/java/yugioh/controller/gamephasescontrollers/CardSelectionMenuController.java b/src/main/java/yugioh/controller/gamephasescontrollers/CardSelectionMenuController.java index fcbced97..01517d68 100644 --- a/src/main/java/yugioh/controller/gamephasescontrollers/CardSelectionMenuController.java +++ b/src/main/java/yugioh/controller/gamephasescontrollers/CardSelectionMenuController.java @@ -1,64 +1,59 @@ package yugioh.controller.gamephasescontrollers; -import javafx.event.Event; import javafx.event.EventHandler; import javafx.fxml.Initializable; import javafx.geometry.Insets; import javafx.scene.control.ScrollPane; import javafx.scene.input.MouseEvent; -import javafx.scene.layout.Background; -import javafx.scene.layout.BackgroundFill; -import javafx.scene.layout.CornerRadii; import javafx.scene.layout.GridPane; -import javafx.scene.paint.Color; -import javafx.scene.paint.Paint; import javafx.scene.shape.Rectangle; import yugioh.model.board.Cell; import yugioh.model.exceptions.GameException; import yugioh.view.gamephases.CardSelectionMenu; import yugioh.view.gamephases.Duel; -import java.awt.*; import java.net.URL; import java.util.ArrayList; import java.util.ResourceBundle; public class CardSelectionMenuController implements Initializable { - public ScrollPane scrollBar; - public static ArrayList cardsToShow=new ArrayList<>(); + public static ArrayList cardsToShow = new ArrayList<>(); static { } + + public ScrollPane scrollBar; + + public static void setCardsToShow(ArrayList cardsToShow) { + CardSelectionMenuController.cardsToShow = cardsToShow; + } + @Override public void initialize(URL url, ResourceBundle resourceBundle) { GridPane cardsPane = new GridPane(); cardsPane.setHgap(10); cardsPane.setVgap(10); cardsPane.setPadding(new Insets(10, 10, 10, 10)); - for(Cell cell : cardsToShow){ - Rectangle rectangle =cell.getCellRectangle(); + for (Cell cell : cardsToShow) { + Rectangle rectangle = cell.getCellRectangle(); rectangle.setOnMouseClicked(new EventHandler() { @Override public void handle(MouseEvent mouseEvent) { Cell.setSelectedCell(Cell.getSelectedCellByRectangle(rectangle)); - GameController gameController= Duel.getGameController(); - try { - gameController.getMainPhase1Controller().specialSummon(gameController); - } catch (GameException e) { - e.printStackTrace(); - } + GameController gameController = Duel.getGameController(); + try { + gameController.getMainPhase1Controller().specialSummon(gameController); + } catch (GameException e) { + e.printStackTrace(); + } CardSelectionMenu.cardSelectionStage.close(); - Cell.deselectCell(); - gameController.changeTurn(true,true); + Cell.deselectCell(); + gameController.changeTurn(true, true); } }); cardsPane.getChildren().add(cell.getCellRectangle()); } scrollBar.contentProperty().set(cardsPane); } - - public static void setCardsToShow(ArrayList cardsToShow) { - CardSelectionMenuController.cardsToShow = cardsToShow; - } } diff --git a/src/main/java/yugioh/controller/gamephasescontrollers/DrawPhaseController.java b/src/main/java/yugioh/controller/gamephasescontrollers/DrawPhaseController.java index 68f99f32..57bb5413 100644 --- a/src/main/java/yugioh/controller/gamephasescontrollers/DrawPhaseController.java +++ b/src/main/java/yugioh/controller/gamephasescontrollers/DrawPhaseController.java @@ -16,12 +16,12 @@ public DrawPhaseController(GameController gameController) { this.gameController = gameController; } - public void addCardToHandDeck(Player player, Card toBeAdded,boolean shouldBeSelected) { - Cell cell=new Cell(toBeAdded); - if(shouldBeSelected){ + public void addCardToHandDeck(Player player, Card toBeAdded, boolean shouldBeSelected) { + Cell cell = new Cell(toBeAdded); + if (shouldBeSelected) { Cell.setSelectedCell(cell); } - player.getGameBoard().addCardToHandDeck(toBeAdded,true); + player.getGameBoard().addCardToHandDeck(toBeAdded, true); } public String removeFirstDeckCardFromDeckToPlay(Player player) throws GameException { diff --git a/src/main/java/yugioh/controller/gamephasescontrollers/GameController.java b/src/main/java/yugioh/controller/gamephasescontrollers/GameController.java index 7836d0a3..246d5ab9 100644 --- a/src/main/java/yugioh/controller/gamephasescontrollers/GameController.java +++ b/src/main/java/yugioh/controller/gamephasescontrollers/GameController.java @@ -22,7 +22,6 @@ import yugioh.model.board.GameBoard; import yugioh.model.cards.Card; import yugioh.model.cards.Deck; -import yugioh.model.cards.SpellAndTrap; import yugioh.model.exceptions.GameException; import yugioh.view.GameRegexes; import yugioh.view.ViewInterface; @@ -36,8 +35,6 @@ import java.net.URL; import java.util.ArrayList; -import static yugioh.view.SoundPlayable.playButtonSound; - public class GameController { public Player currentTurnPlayer; @@ -204,8 +201,8 @@ public void deselect() throws GameException { public void changePhase() { // Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(3.5), event -> { CardActionsMenu.close(); - // if (isGameEnded()) { - endGameRound(); + // if (isGameEnded()) { + endGameRound(); // return; // } switch (currentPhase) { @@ -244,12 +241,12 @@ public void changePhase() { } public void changeTurn(boolean isTemporary, boolean backToPlayer) { - if(isTemporary){ - Platform.runLater(()->{ + if (isTemporary) { + Platform.runLater(() -> { if (isTemporary && !backToPlayer) { ViewInterface.showResult("now it will be " + currentTurnOpponentPlayer.getUser().getNickname() + "’s turn"); ViewInterface.showResult(mainPhase1Controller.showGameBoard(currentTurnOpponentPlayer, currentTurnPlayer)); - Toast.makeText(WelcomeMenu.getStage(),"now it will be " + currentTurnOpponentPlayer.getUser().getNickname() + "’s turn"); + Toast.makeText(WelcomeMenu.getStage(), "now it will be " + currentTurnOpponentPlayer.getUser().getNickname() + "’s turn"); gameMenuController.changeGameBoard(); gameMenuController.nextPhaseTriangle.setDisable(true); @@ -275,8 +272,7 @@ public void changeTurn(boolean isTemporary, boolean backToPlayer) { mainPhase1Controller.showGameBoard(currentTurnPlayer, currentTurnOpponentPlayer); }); - } - else { + } else { gameMenuController.changeGameBoard(); Player player = currentTurnPlayer; currentTurnPlayer = currentTurnOpponentPlayer; @@ -304,21 +300,21 @@ public void activateTrapEffect(ArrayList trapsCanBeActivated) { Pane pane = FXMLLoader.load(url); Scene scene = WelcomeMenu.createScene(pane); activateStage.setScene(scene); - Button yesButton = (Button) ((HBox)((VBox)pane.getChildren().get(0)).getChildren().get(1)).getChildren().get(0); - Button noButton = (Button) ((HBox)((VBox)pane.getChildren().get(0)).getChildren().get(1)).getChildren().get(1); + Button yesButton = (Button) ((HBox) ((VBox) pane.getChildren().get(0)).getChildren().get(1)).getChildren().get(0); + Button noButton = (Button) ((HBox) ((VBox) pane.getChildren().get(0)).getChildren().get(1)).getChildren().get(1); yesButton.setOnMouseClicked(new EventHandler() { @Override public void handle(MouseEvent mouseEvent) { activateStage.close(); - gameMenuController.choiceHasBeenMade=true; - gameMenuController.shouldActivateEffectsNow=true; - gameMenuController.canBeActivatedCards=trapsCanBeActivated; + gameMenuController.choiceHasBeenMade = true; + gameMenuController.shouldActivateEffectsNow = true; + gameMenuController.canBeActivatedCards = trapsCanBeActivated; } }); noButton.setOnMouseClicked(new EventHandler() { @Override public void handle(MouseEvent mouseEvent) { - gameMenuController.choiceHasBeenMade=true; + gameMenuController.choiceHasBeenMade = true; activateStage.close(); } }); @@ -417,7 +413,7 @@ public void endGameRound() { ViewInterface.showResult(response); isGameEnded = true; try { - new EndOfGameMenu().execute(response,true); + new EndOfGameMenu().execute(response, true); new DuelMenu().execute(); } catch (Exception e) { e.printStackTrace(); @@ -429,8 +425,8 @@ public void endGameRound() { //changeCards(currentTurnPlayer); //changeCards(currentTurnOpponentPlayer); try { - new EndOfGameMenu().execute(response,false); - }catch (Exception e){ + new EndOfGameMenu().execute(response, false); + } catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/java/yugioh/controller/gamephasescontrollers/MainPhasesController.java b/src/main/java/yugioh/controller/gamephasescontrollers/MainPhasesController.java index 85243630..bdd388e8 100644 --- a/src/main/java/yugioh/controller/gamephasescontrollers/MainPhasesController.java +++ b/src/main/java/yugioh/controller/gamephasescontrollers/MainPhasesController.java @@ -21,7 +21,6 @@ import yugioh.model.cards.trapandspells.TorrentialTribute; import yugioh.model.exceptions.GameException; import yugioh.view.ConsoleColors; -import yugioh.view.ViewInterface; import yugioh.view.gamephases.GameResponses; import java.util.ArrayList; @@ -77,7 +76,7 @@ default void continueMonsterSummon(GameController gameController, boolean isNorm default boolean isSummonedMonsterATKMoreThan1000(Cell summonedCell) { try { return ((Monster) summonedCell.getCellCard()).getAtk() >= 1000; - }catch (Exception e){ + } catch (Exception e) { return false; } } @@ -86,22 +85,22 @@ private void activateTrapIfCanBeActivated(GameController gameController, SummonT for (Cell cell : gameController.currentTurnPlayer.getGameBoard().getSpellAndTrapCardZone()) { if (!cell.isEmpty() && cell.getCardStatus() == CardStatus.HIDDEN) { if (summonType == SummonTypes.NormalSummon) { - if(summonEffectSpellAndTrap.contains(cell.getCellCard())) { + if (summonEffectSpellAndTrap.contains(cell.getCellCard())) { gameController.activateTrapEffect(summonEffectSpellAndTrap); break; } } else if (summonType == SummonTypes.FlipSummon) { - if(flipSummonEffectSpellAndTrap.contains(cell.getCellCard())) { + if (flipSummonEffectSpellAndTrap.contains(cell.getCellCard())) { gameController.activateTrapEffect(flipSummonEffectSpellAndTrap); break; } } else if (summonType == SummonTypes.SpecialSummon) { - if(SpecialSummonEffectSpellAndTrap.contains(cell.getCellCard())) { + if (SpecialSummonEffectSpellAndTrap.contains(cell.getCellCard())) { gameController.activateTrapEffect(SpecialSummonEffectSpellAndTrap); break; } } else if (summonType == SummonTypes.RitualSummon) { - if(ritualSummonEffectSpellAndTrap.contains(cell.getCellCard())) { + if (ritualSummonEffectSpellAndTrap.contains(cell.getCellCard())) { gameController.activateTrapEffect(ritualSummonEffectSpellAndTrap); break; } @@ -111,28 +110,28 @@ private void activateTrapIfCanBeActivated(GameController gameController, SummonT for (Cell cell : gameController.currentTurnOpponentPlayer.getGameBoard().getSpellAndTrapCardZone()) { if (!cell.isEmpty() && cell.getCardStatus() == CardStatus.HIDDEN) { if (summonType == SummonTypes.NormalSummon) { - if(summonEffectSpellAndTrap.contains(cell.getCellCard())) { + if (summonEffectSpellAndTrap.contains(cell.getCellCard())) { gameController.changeTurn(true, false); gameController.activateTrapEffect(summonEffectSpellAndTrap); //gameController.changeTurn(true, true); break; } } else if (summonType == SummonTypes.FlipSummon) { - if(flipSummonEffectSpellAndTrap.contains(cell.getCellCard())) { + if (flipSummonEffectSpellAndTrap.contains(cell.getCellCard())) { gameController.changeTurn(true, false); gameController.activateTrapEffect(flipSummonEffectSpellAndTrap); //gameController.changeTurn(true, true); break; } } else if (summonType == SummonTypes.SpecialSummon) { - if(SpecialSummonEffectSpellAndTrap.contains(cell.getCellCard())) { + if (SpecialSummonEffectSpellAndTrap.contains(cell.getCellCard())) { gameController.changeTurn(true, false); gameController.activateTrapEffect(SpecialSummonEffectSpellAndTrap); - // gameController.changeTurn(true, true); + // gameController.changeTurn(true, true); break; } } else if (summonType == SummonTypes.RitualSummon) { - if(ritualSummonEffectSpellAndTrap.contains(cell.getCellCard())) { + if (ritualSummonEffectSpellAndTrap.contains(cell.getCellCard())) { gameController.changeTurn(true, false); gameController.activateTrapEffect(ritualSummonEffectSpellAndTrap); //gameController.changeTurn(true, true); @@ -163,15 +162,12 @@ default boolean hasEnoughTribute(Card card, Player currentPlayer, boolean isSpec int monsterLevel = ((Monster) card).getLevel(); if (monsterLevel > 4 || isSpecialSummon) { if (isSpecialSummon) { - if (currentPlayer.getGameBoard().getNumberOfMonstersOnMonsterCardZone() < 1) - return false; + return currentPlayer.getGameBoard().getNumberOfMonstersOnMonsterCardZone() >= 1; } else { if (monsterLevel < 7) { - if (currentPlayer.getGameBoard().getNumberOfMonstersOnMonsterCardZone() < 1) - return false; + return currentPlayer.getGameBoard().getNumberOfMonstersOnMonsterCardZone() >= 1; } else { - if (currentPlayer.getGameBoard().getNumberOfMonstersOnMonsterCardZone() < 2) - return false; + return currentPlayer.getGameBoard().getNumberOfMonstersOnMonsterCardZone() >= 2; } } } @@ -271,7 +267,7 @@ default void setCard(GameController gameController) throws GameException { // gameController.changedPositionCells.add(selectedCell); // gameController.setDidPlayerSetOrSummonThisTurn(true); } else { - playerGameBoard.addCardToSpellAndTrapCardZone(selectedCard, CardStatus.HIDDEN, gameController,false); + playerGameBoard.addCardToSpellAndTrapCardZone(selectedCard, CardStatus.HIDDEN, gameController, false); playerGameBoard.removeCardFromHand(selectedCell); gameController.changedPositionCells.add(selectedCell); TimeSeal.setActivated(gameController); @@ -392,7 +388,7 @@ default void flipSummon(GameController gameController) throws GameException { } selectedCell.setCardStatus(CardStatus.OFFENSIVE_OCCUPIED); gameController.currentTurnPlayer.getGameBoard().setFlipTransition(selectedCell.getCellCard(), - selectedCell.getCellRectangle(), false,false); + selectedCell.getCellRectangle(), false, false); ManEaterBug.handleEffect(gameController, selectedCell); activateTrapIfCanBeActivated(gameController, SummonTypes.FlipSummon); Cell.deselectCell(); @@ -413,20 +409,20 @@ default void specialSummon(GameController gameController) throws GameException { // ViewInterface.showResult(GameResponses.YOU_SHOULD_SPECIAL_SUMMON_NOW.response); // continue; // } - //int monsterLevel = ((Monster) selectedCell.getCellCard()).getLevel(); - //handleTribute(currentPlayer, gameController, monsterLevel, true, false); - - currentPlayer.getGameBoard().addCardToMonsterCardZone(selectedCell.getCellCard(), - CardStatus.OFFENSIVE_OCCUPIED, gameController); - currentPlayer.getGameBoard().removeCardFromHand(selectedCell); - TerratigertheEmpoweredWarrior.handleEffect(gameController, selectedCell); - gameController.setDidPlayerSetOrSummonThisTurn(true); - gameController.shouldSpecialSummonNow = false; - gameController.setLastSummonedMonster(selectedCell); - addMonstersToSpecialSummonEffectSpellAndTrap(); - Cell.deselectCell(); - // break; - // } + //int monsterLevel = ((Monster) selectedCell.getCellCard()).getLevel(); + //handleTribute(currentPlayer, gameController, monsterLevel, true, false); + + currentPlayer.getGameBoard().addCardToMonsterCardZone(selectedCell.getCellCard(), + CardStatus.OFFENSIVE_OCCUPIED, gameController); + currentPlayer.getGameBoard().removeCardFromHand(selectedCell); + TerratigertheEmpoweredWarrior.handleEffect(gameController, selectedCell); + gameController.setDidPlayerSetOrSummonThisTurn(true); + gameController.shouldSpecialSummonNow = false; + gameController.setLastSummonedMonster(selectedCell); + addMonstersToSpecialSummonEffectSpellAndTrap(); + Cell.deselectCell(); + // break; + // } activateTrapIfCanBeActivated(gameController, SummonTypes.SpecialSummon); } @@ -468,8 +464,8 @@ default String showGameBoard(Player currentPlayer, Player opponentPlayer) { imageView.setFitWidth(70); imageView.rotateProperty().set(180.0); imageView.setLayoutX(paneX - i / 2); - if(!gameMenuController.rivalDeckZoneContainer.getChildren().contains(imageView)) - Platform.runLater(()-> gameMenuController.rivalDeckZoneContainer.getChildren().add(imageView)); + if (!gameMenuController.rivalDeckZoneContainer.getChildren().contains(imageView)) + Platform.runLater(() -> gameMenuController.rivalDeckZoneContainer.getChildren().add(imageView)); } @@ -583,8 +579,8 @@ default String showGameBoard(Player currentPlayer, Player opponentPlayer) { ImageView imageView = playerGameBoard.getDeckZone().get(i).getCellCard().getCardBackImage(); imageView.setFitWidth(70); imageView.setLayoutX(xPane + i / 2); - if(!gameMenuController.userDeckZoneContainer.getChildren().contains(imageView)) - Platform.runLater(()->{ + if (!gameMenuController.userDeckZoneContainer.getChildren().contains(imageView)) + Platform.runLater(() -> { gameMenuController.userDeckZoneContainer.getChildren().add(imageView); }); //gameMenuController.addEventForCardImage(imageView,null); diff --git a/src/main/java/yugioh/controller/menucontroller/CardGeneratorMenuController.java b/src/main/java/yugioh/controller/menucontroller/CardGeneratorMenuController.java index e4003215..c45959ba 100644 --- a/src/main/java/yugioh/controller/menucontroller/CardGeneratorMenuController.java +++ b/src/main/java/yugioh/controller/menucontroller/CardGeneratorMenuController.java @@ -7,7 +7,6 @@ import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.fxml.Initializable; - import javafx.scene.control.*; import javafx.scene.image.Image; import javafx.scene.image.ImageView; @@ -16,7 +15,6 @@ import javafx.scene.media.MediaPlayer; import javafx.scene.media.MediaView; import yugioh.model.User; -import yugioh.model.cards.Card; import yugioh.model.cards.Monster; import yugioh.model.cards.cardfeaturesenums.CardType; import yugioh.model.cards.cardfeaturesenums.MonsterAttribute; @@ -25,18 +23,16 @@ import yugioh.view.menus.CardGeneratorMenu; import yugioh.view.menus.PopUpWindow; import yugioh.view.menus.WelcomeMenu; -import yugioh.view.transitions.CoinTransition; import java.io.File; import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.ArrayList; import java.util.ResourceBundle; -public class CardGeneratorMenuController extends MenuController implements Initializable{ +public class CardGeneratorMenuController extends MenuController implements Initializable { public TextField attackField; public TextField defenseField; public TextField cardName; @@ -59,7 +55,7 @@ public class CardGeneratorMenuController extends MenuController implements Initi public void backToShop(MouseEvent mouseEvent) throws Exception { SoundPlayable.playButtonSound("backButton"); - shopMenu.execute(); + shopMenu.execute(); } @Override @@ -72,11 +68,13 @@ public void initialize(URL url, ResourceBundle resourceBundle) { attackField.textProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue observableValue, String s, String t1) { - Platform.runLater(()->{ - int priceValue=0; - if(attackField.getText().matches("^(\\d+)$"))priceValue+=Integer.parseInt(attackField.getText())*10; - if(defenseField.getText().matches("^(\\d+)$"))priceValue+=Integer.parseInt(defenseField.getText())*5; - priceValue+=level.getValue()*100; + Platform.runLater(() -> { + int priceValue = 0; + if (attackField.getText().matches("^(\\d+)$")) + priceValue += Integer.parseInt(attackField.getText()) * 10; + if (defenseField.getText().matches("^(\\d+)$")) + priceValue += Integer.parseInt(defenseField.getText()) * 5; + priceValue += level.getValue() * 100; price.setText(String.valueOf(priceValue)); }); } @@ -84,11 +82,13 @@ public void changed(ObservableValue observableValue, String s, defenseField.textProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue observableValue, String s, String t1) { - Platform.runLater(()->{ - int priceValue=0; - if(attackField.getText().matches("^(\\d+)$"))priceValue+=Integer.parseInt(attackField.getText())*10; - if(defenseField.getText().matches("^(\\d+)$"))priceValue+=Integer.parseInt(defenseField.getText())*5; - priceValue+=level.getValue()*100; + Platform.runLater(() -> { + int priceValue = 0; + if (attackField.getText().matches("^(\\d+)$")) + priceValue += Integer.parseInt(attackField.getText()) * 10; + if (defenseField.getText().matches("^(\\d+)$")) + priceValue += Integer.parseInt(defenseField.getText()) * 5; + priceValue += level.getValue() * 100; price.setText(String.valueOf(priceValue)); }); } @@ -96,11 +96,13 @@ public void changed(ObservableValue observableValue, String s, level.valueProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue observableValue, Number number, Number t1) { - Platform.runLater(()->{ - int priceValue=0; - if(attackField.getText().matches("^(\\d+)$"))priceValue+=Integer.parseInt(attackField.getText())*10; - if(defenseField.getText().matches("^(\\d+)$"))priceValue+=Integer.parseInt(defenseField.getText())*5; - priceValue+=level.getValue()*100; + Platform.runLater(() -> { + int priceValue = 0; + if (attackField.getText().matches("^(\\d+)$")) + priceValue += Integer.parseInt(attackField.getText()) * 10; + if (defenseField.getText().matches("^(\\d+)$")) + priceValue += Integer.parseInt(defenseField.getText()) * 5; + priceValue += level.getValue() * 100; price.setText(String.valueOf(priceValue)); }); } @@ -110,22 +112,17 @@ public void changed(ObservableValue observableValue, Number nu setMenuItemsValues(); cardImage.setImage(new Image(new File("src\\resources\\yugioh\\PNG\\cardsImages\\questionMark.jpg") .toURI().toString())); - Platform.runLater(()->usersCoin.setText(String.valueOf(User.loggedInUser.getMoney()))); + Platform.runLater(() -> usersCoin.setText(String.valueOf(User.loggedInUser.getMoney()))); price.textProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue observableValue, String s, String t1) { - if(Integer.parseInt(t1)>User.loggedInUser.getMoney()){ - generateButton.setDisable(true); - } - else{ - generateButton.setDisable(false); - } + generateButton.setDisable(Integer.parseInt(t1) > User.loggedInUser.getMoney()); } }); } private void handleAllMenuItems() { - for(MenuItem menuItem:cardType.getItems()){ + for (MenuItem menuItem : cardType.getItems()) { menuItem.setOnAction(new EventHandler() { @Override public void handle(ActionEvent actionEvent) { @@ -133,7 +130,7 @@ public void handle(ActionEvent actionEvent) { } }); } - for(MenuItem menuItem:monsterType.getItems()){ + for (MenuItem menuItem : monsterType.getItems()) { menuItem.setOnAction(new EventHandler() { @Override public void handle(ActionEvent actionEvent) { @@ -141,7 +138,7 @@ public void handle(ActionEvent actionEvent) { } }); } - for(MenuItem menuItem:monsterAttribute.getItems()){ + for (MenuItem menuItem : monsterAttribute.getItems()) { menuItem.setOnAction(new EventHandler() { @Override public void handle(ActionEvent actionEvent) { @@ -152,7 +149,7 @@ public void handle(ActionEvent actionEvent) { } private void setMenuItemsValues() { - ObservableList attributes=monsterAttribute.getItems(); + ObservableList attributes = monsterAttribute.getItems(); attributes.get(0).setUserData(MonsterAttribute.DARK); attributes.get(1).setUserData(MonsterAttribute.EARTH); attributes.get(2).setUserData(MonsterAttribute.FIRE); @@ -160,7 +157,7 @@ private void setMenuItemsValues() { attributes.get(4).setUserData(MonsterAttribute.WATER); attributes.get(5).setUserData(MonsterAttribute.WIND); - ObservableListmonsterTypes=monsterType.getItems(); + ObservableList monsterTypes = monsterType.getItems(); monsterTypes.get(0).setUserData(MonsterType.BEAST_WARRIOR); monsterTypes.get(1).setUserData(MonsterType.WARRIOR); monsterTypes.get(2).setUserData(MonsterType.AQUA); @@ -177,7 +174,7 @@ private void setMenuItemsValues() { monsterTypes.get(13).setUserData(MonsterType.FAIRY); monsterTypes.get(14).setUserData(MonsterType.SEA_SERPENT); - ObservableListcardTypes=cardType.getItems(); + ObservableList cardTypes = cardType.getItems(); cardTypes.get(0).setUserData(CardType.NORMAL); cardTypes.get(1).setUserData(CardType.EFFECTIVE); cardTypes.get(2).setUserData(CardType.RITUAL); @@ -185,29 +182,28 @@ private void setMenuItemsValues() { } - public void generateClicked(MouseEvent mouseEvent)throws Exception { - if( - monsterType.getText().equals("Monster type")||cardType.getText().equals("Card type") - ||monsterAttribute.getText().equals("Monster attribute")||attackField.getText().equals("")|| - !attackField.getText().matches("^(\\d+)$")||defenseField.getText().equals("")|| - !defenseField.getText().matches("^(\\d+)$")||descriptionBox.getText().equals("")||cardName.getText().equals("")){ + public void generateClicked(MouseEvent mouseEvent) throws Exception { + if ( + monsterType.getText().equals("Monster type") || cardType.getText().equals("Card type") + || monsterAttribute.getText().equals("Monster attribute") || attackField.getText().equals("") || + !attackField.getText().matches("^(\\d+)$") || defenseField.getText().equals("") || + !defenseField.getText().matches("^(\\d+)$") || descriptionBox.getText().equals("") || cardName.getText().equals("")) { new PopUpWindow("Error: fill all the fields!").start(WelcomeMenu.stage); - } - else{ - User.loggedInUser.changeMoney((int) (-Integer.parseInt(price.getText())*0.1)); - Monster monster=new Monster(cardName.getText(),descriptionBox.getText(),Integer.parseInt(price.getText()), - Integer.parseInt(attackField.getText()),Integer.parseInt(defenseField.getText()),(int)level.getValue(), - (MonsterAttribute) getMenuItem(monsterAttribute.getText(),"Monster attribute"),(MonsterType) getMenuItem(monsterType.getText(), - "Monster type"),(CardType) getMenuItem(cardType.getText(),"Card type")); + } else { + User.loggedInUser.changeMoney((int) (-Integer.parseInt(price.getText()) * 0.1)); + Monster monster = new Monster(cardName.getText(), descriptionBox.getText(), Integer.parseInt(price.getText()), + Integer.parseInt(attackField.getText()), Integer.parseInt(defenseField.getText()), (int) level.getValue(), + (MonsterAttribute) getMenuItem(monsterAttribute.getText(), "Monster attribute"), (MonsterType) getMenuItem(monsterType.getText(), + "Monster type"), (CardType) getMenuItem(cardType.getText(), "Card type")); monster.setIsCustom(); monster.setImage(cardImage); monster.setImage(); Path sourceDirectory = Paths.get("src\\resources\\yugioh\\PNG\\cardsImages\\questionMark.jpg"); - Path targetDirectory = Paths.get("src\\resources\\yugioh\\PNG\\cardsImages\\" + cardName.getText()+ ".jpg"); + Path targetDirectory = Paths.get("src\\resources\\yugioh\\PNG\\cardsImages\\" + cardName.getText() + ".jpg"); try { Files.copy(sourceDirectory, targetDirectory); - }catch (Exception e){ + } catch (Exception e) { new PopUpWindow("Error: card with this name already exists!").start(WelcomeMenu.stage); } new CardGeneratorMenu().execute(); @@ -216,24 +212,23 @@ public void generateClicked(MouseEvent mouseEvent)throws Exception { } } - private Object getMenuItem(String name,String from){ - if(from.equals("Monster attribute")){ - for(MenuItem menuItem:monsterAttribute.getItems()){ - if(menuItem.getText().equals(name)){ + + private Object getMenuItem(String name, String from) { + if (from.equals("Monster attribute")) { + for (MenuItem menuItem : monsterAttribute.getItems()) { + if (menuItem.getText().equals(name)) { return menuItem.getUserData(); } } - } - else if(from.equals("Card type")){ - for(MenuItem menuItem:cardType.getItems()){ - if(menuItem.getText().equals(name)){ + } else if (from.equals("Card type")) { + for (MenuItem menuItem : cardType.getItems()) { + if (menuItem.getText().equals(name)) { return menuItem.getUserData(); } } - } - else if(from.equals("Monster type")){ - for(MenuItem menuItem:monsterType.getItems()){ - if(menuItem.getText().equals(name)){ + } else if (from.equals("Monster type")) { + for (MenuItem menuItem : monsterType.getItems()) { + if (menuItem.getText().equals(name)) { return menuItem.getUserData(); } } diff --git a/src/main/java/yugioh/controller/menucontroller/DeckMenuController.java b/src/main/java/yugioh/controller/menucontroller/DeckMenuController.java index 082e5016..baad2742 100644 --- a/src/main/java/yugioh/controller/menucontroller/DeckMenuController.java +++ b/src/main/java/yugioh/controller/menucontroller/DeckMenuController.java @@ -1,7 +1,5 @@ package yugioh.controller.menucontroller; -import javafx.event.EventType; -import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.geometry.Pos; import javafx.scene.control.Button; @@ -12,7 +10,6 @@ import javafx.scene.image.ImageView; import javafx.scene.input.MouseEvent; import javafx.scene.layout.GridPane; -import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; import javafx.scene.media.Media; import javafx.scene.media.MediaPlayer; @@ -51,6 +48,7 @@ public class DeckMenuController extends MenuController implements Initializable public Button activateDeckButton; public MediaView deckMenuBackground; private MenuItem selectedMenuItem; + public DeckMenuController() { } diff --git a/src/main/java/yugioh/controller/menucontroller/DetermineStarterMenuController.java b/src/main/java/yugioh/controller/menucontroller/DetermineStarterMenuController.java index b3daea95..e191956a 100644 --- a/src/main/java/yugioh/controller/menucontroller/DetermineStarterMenuController.java +++ b/src/main/java/yugioh/controller/menucontroller/DetermineStarterMenuController.java @@ -7,7 +7,6 @@ import javafx.scene.media.MediaPlayer; import javafx.scene.media.MediaView; import yugioh.controller.gamephasescontrollers.GameController; -import yugioh.view.SoundPlayable; import yugioh.view.gamephases.Duel; import yugioh.view.menus.DetermineStarterMenu; import yugioh.view.menus.Toast; diff --git a/src/main/java/yugioh/controller/menucontroller/DuelMenuController.java b/src/main/java/yugioh/controller/menucontroller/DuelMenuController.java index 39e72a8e..b5570976 100644 --- a/src/main/java/yugioh/controller/menucontroller/DuelMenuController.java +++ b/src/main/java/yugioh/controller/menucontroller/DuelMenuController.java @@ -1,7 +1,5 @@ package yugioh.controller.menucontroller; -import javafx.scene.media.Media; -import javafx.scene.media.MediaPlayer; import javafx.scene.media.MediaView; import yugioh.controller.gamephasescontrollers.GameController; import yugioh.model.Player; @@ -12,11 +10,7 @@ import yugioh.view.Responses; import yugioh.view.SoundPlayable; import yugioh.view.gamephases.Duel; -import yugioh.view.menus.PopUpWindow; import yugioh.view.menus.RivalSelectionMenu; -import yugioh.view.menus.WelcomeMenu; - -import java.io.File; public class DuelMenuController extends MenuController { diff --git a/src/main/java/yugioh/controller/menucontroller/EditDeckMenuController.java b/src/main/java/yugioh/controller/menucontroller/EditDeckMenuController.java index c65279a5..3829b349 100644 --- a/src/main/java/yugioh/controller/menucontroller/EditDeckMenuController.java +++ b/src/main/java/yugioh/controller/menucontroller/EditDeckMenuController.java @@ -16,7 +16,6 @@ import javafx.scene.paint.Color; import yugioh.model.User; import yugioh.model.cards.Card; -import yugioh.view.SoundPlayable; import yugioh.view.menus.DeckMenu; import yugioh.view.menus.EditDeckMenu; diff --git a/src/main/java/yugioh/controller/menucontroller/GameMenuController.java b/src/main/java/yugioh/controller/menucontroller/GameMenuController.java index 543c4a54..2c309876 100644 --- a/src/main/java/yugioh/controller/menucontroller/GameMenuController.java +++ b/src/main/java/yugioh/controller/menucontroller/GameMenuController.java @@ -54,6 +54,7 @@ public class GameMenuController extends MenuController implements Initializable { + public static Stage pauseStage; private static GameMenuController gameMenuController; public Pane gamePane; public Rectangle hoveredImageRectangle; @@ -98,7 +99,6 @@ public class GameMenuController extends MenuController implements Initializable public boolean shouldActivateEffectsNow = false; public ArrayList canBeActivatedCards; public boolean choiceHasBeenMade = true; - public static Stage pauseStage; public static GameMenuController getGameMenuController() { return gameMenuController; @@ -254,13 +254,14 @@ public void updateGameStatusUIs() { currentNickname.setText("Nickname : " + gameController.currentTurnPlayer. getUser().getNickname()); if (gameController.currentTurnPlayer.getUser().isImageIsChanged()) - currentImage.setImage(new Image(gameController.currentTurnPlayer.getUser().getProfileImageFile().toURI().toString())); + currentImage.setImage(new Image(gameController.currentTurnPlayer.getUser().getProfileImageFile().toURI().toString())); else currentImage.setImage(new Image(gameController.currentTurnPlayer.getUser().getProfileImageString())); currentImage.setPreserveRatio(true); currentImage.setFitHeight(85); if (gameController.currentTurnOpponentPlayer.getUser().isImageIsChanged()) opponentImage.setImage(new Image(gameController.currentTurnOpponentPlayer.getUser().getProfileImageFile().toURI().toString())); - else opponentImage.setImage(new Image(gameController.currentTurnOpponentPlayer.getUser().getProfileImageString())); + else + opponentImage.setImage(new Image(gameController.currentTurnOpponentPlayer.getUser().getProfileImageString())); opponentImage.setPreserveRatio(true); opponentImage.setFitHeight(85); rivalLPBar.setProgress((double) opponentLP / 8000); @@ -279,7 +280,7 @@ public void removeCardHoveredImageAndInfo(Paint paint) { public void addEventForCardImageRectangle(Rectangle rectangle, Cell cellToAddEvent) { rectangle.addEventHandler(MouseEvent.MOUSE_ENTERED, event -> { - Card card=cellToAddEvent.getCellCard(); + Card card = cellToAddEvent.getCellCard(); if (card == null || rectangle.getFill() == null || (rectangle.getFill().equals(card.getCardBackImagePattern()) && !gameController. currentTurnPlayer.getGameBoard().isCellInMonsterZone(Cell.getSelectedCellByRectangle(rectangle)) && !gameController.currentTurnPlayer.getGameBoard().isCellInSpellAndTrapZone diff --git a/src/main/java/yugioh/controller/menucontroller/MenuController.java b/src/main/java/yugioh/controller/menucontroller/MenuController.java index ea25792a..60cbcd3e 100644 --- a/src/main/java/yugioh/controller/menucontroller/MenuController.java +++ b/src/main/java/yugioh/controller/menucontroller/MenuController.java @@ -15,6 +15,6 @@ abstract public class MenuController implements SoundPlayable { protected ShopMenu shopMenu = new ShopMenu(); protected ImportExportMenu importExportMenu = new ImportExportMenu(); protected SelectDeckNamePage selectDeckNamePage = new SelectDeckNamePage(); - protected CardGeneratorMenu cardGeneratorMenu=new CardGeneratorMenu(); + protected CardGeneratorMenu cardGeneratorMenu = new CardGeneratorMenu(); } diff --git a/src/main/java/yugioh/controller/menucontroller/ProfileMenuController.java b/src/main/java/yugioh/controller/menucontroller/ProfileMenuController.java index 7a4f9415..635b16fb 100644 --- a/src/main/java/yugioh/controller/menucontroller/ProfileMenuController.java +++ b/src/main/java/yugioh/controller/menucontroller/ProfileMenuController.java @@ -96,7 +96,7 @@ public void initialize(URL url, ResourceBundle resourceBundle) { mediaPlayer.play(); mediaPlayer.setCycleCount(-1); profileMenuBackground.setMediaPlayer(mediaPlayer); - System.out.println(User.loggedInUser.getProfileImageFile().toURI().toString()); + System.out.println(User.loggedInUser.getProfileImageFile().toURI()); Image image = new Image(User.loggedInUser.getProfileImageFile().toURI().toString()); profileImage.setImage(image); changePasswordButton.setDisable(true); diff --git a/src/main/java/yugioh/model/Player.java b/src/main/java/yugioh/model/Player.java index adc28520..24190ccc 100644 --- a/src/main/java/yugioh/model/Player.java +++ b/src/main/java/yugioh/model/Player.java @@ -1,9 +1,6 @@ package yugioh.model; -import javafx.animation.KeyFrame; -import javafx.animation.Timeline; import javafx.application.Platform; -import javafx.util.Duration; import yugioh.controller.menucontroller.GameMenuController; import yugioh.model.board.GameBoard; import yugioh.model.cards.Deck; @@ -50,13 +47,13 @@ public void decreaseLP(int amount) { private void updateLP() { if (this == Duel.getGameController().currentTurnPlayer) { - Platform.runLater(()->{ + Platform.runLater(() -> { GameMenuController.getGameMenuController().userLP.setText(getLP() + ""); GameMenuController.getGameMenuController().userLPBar.setProgress((double) getLP() / 8000); }); } else { - Platform.runLater(()->{ + Platform.runLater(() -> { GameMenuController.getGameMenuController().rivalLP.setText(getLP() + ""); GameMenuController.getGameMenuController().rivalLPBar.setProgress((double) getLP() / 8000); }); diff --git a/src/main/java/yugioh/model/board/Cell.java b/src/main/java/yugioh/model/board/Cell.java index d4041d03..58249938 100644 --- a/src/main/java/yugioh/model/board/Cell.java +++ b/src/main/java/yugioh/model/board/Cell.java @@ -1,6 +1,5 @@ package yugioh.model.board; -import javafx.application.Platform; import javafx.scene.control.Label; import javafx.scene.paint.ImagePattern; import javafx.scene.paint.Paint; @@ -20,12 +19,12 @@ public class Cell { private static final ArrayList allCells = new ArrayList<>(); private static Cell selectedCell; public CardStatus cardStatus; + public transient boolean isEventSet = false; private Card card; private double xPosition; private double yPosition; private transient Rectangle cellRectangle; - private transient Label cellInfo=new Label(); - public transient boolean isEventSet=false; + private transient Label cellInfo = new Label(); public Cell() { allCells.add(this); @@ -125,7 +124,7 @@ public void removeCardFromCell(GameBoard gameBoard) { // timeline.play(); if (Cell.getSelectedCell() == this) selectedCell = null; cellRectangle.setStrokeWidth(0); - cellInfo.setText(""); + cellInfo.setText(""); cellRectangle.setFill(null); this.card = null; @@ -182,6 +181,6 @@ public double getyPosition() { } public void setEventIsSet() { - isEventSet =true; + isEventSet = true; } } diff --git a/src/main/java/yugioh/model/board/GameBoard.java b/src/main/java/yugioh/model/board/GameBoard.java index 73f0718f..8dd8a033 100644 --- a/src/main/java/yugioh/model/board/GameBoard.java +++ b/src/main/java/yugioh/model/board/GameBoard.java @@ -52,9 +52,9 @@ public class GameBoard { private final ArrayList deckZone; private final ArrayList handCards; private final Cell fieldZone; + public transient HashMap rectanglesInitRotateValues = new HashMap<>(); private transient Rectangle graveyardPlace; private transient HBox handDeck; - public transient HashMap rectanglesInitRotateValues=new HashMap<>(); { monsterCardZone = new Cell[5]; @@ -86,10 +86,10 @@ public GameBoard(Deck deck) { public void setBoardRectangles(Pane gamePane, boolean isOpponent) { GameBoard.gamePane = gamePane; fieldZone.setCellRectangle((Rectangle) gamePane.getChildren().get(36)); - rectanglesInitRotateValues.put(fieldZone.getCellRectangle(),fieldZone.getCellRectangle().rotateProperty().get()); + rectanglesInitRotateValues.put(fieldZone.getCellRectangle(), fieldZone.getCellRectangle().rotateProperty().get()); if (!isOpponent) { graveyardPlace = (Rectangle) gamePane.getChildren().get(4); - rectanglesInitRotateValues.put(graveyardPlace,graveyardPlace.rotateProperty().get()); + rectanglesInitRotateValues.put(graveyardPlace, graveyardPlace.rotateProperty().get()); monsterCardZone[0].setCellRectangle((Rectangle) gamePane.getChildren().get(8)); monsterCardZone[1].setCellRectangle((Rectangle) gamePane.getChildren().get(9)); monsterCardZone[2].setCellRectangle((Rectangle) gamePane.getChildren().get(7)); @@ -97,7 +97,6 @@ public void setBoardRectangles(Pane gamePane, boolean isOpponent) { monsterCardZone[4].setCellRectangle((Rectangle) gamePane.getChildren().get(6)); - spellAndTrapCardZone[0].setCellRectangle((Rectangle) gamePane.getChildren().get(13)); spellAndTrapCardZone[1].setCellRectangle((Rectangle) gamePane.getChildren().get(14)); spellAndTrapCardZone[2].setCellRectangle((Rectangle) gamePane.getChildren().get(12)); @@ -107,7 +106,7 @@ public void setBoardRectangles(Pane gamePane, boolean isOpponent) { } else { graveyardPlace = (Rectangle) gamePane.getChildren().get(5); - rectanglesInitRotateValues.put(graveyardPlace,graveyardPlace.rotateProperty().get()); + rectanglesInitRotateValues.put(graveyardPlace, graveyardPlace.rotateProperty().get()); Rectangle rectangle1 = (Rectangle) gamePane.getChildren().get(18); rectangle1.rotateProperty().set(180); Rectangle rectangle2 = (Rectangle) gamePane.getChildren().get(19); @@ -142,11 +141,11 @@ public void setBoardRectangles(Pane gamePane, boolean isOpponent) { spellAndTrapCardZone[3].setCellRectangle(rectangle9); spellAndTrapCardZone[4].setCellRectangle(rectangle10); } - for(Cell cell:monsterCardZone){ - rectanglesInitRotateValues.put(cell.getCellRectangle(),cell.getCellRectangle().rotateProperty().get()); + for (Cell cell : monsterCardZone) { + rectanglesInitRotateValues.put(cell.getCellRectangle(), cell.getCellRectangle().rotateProperty().get()); } - for(Cell cell:spellAndTrapCardZone){ - rectanglesInitRotateValues.put(cell.getCellRectangle(),cell.getCellRectangle().rotateProperty().get()); + for (Cell cell : spellAndTrapCardZone) { + rectanglesInitRotateValues.put(cell.getCellRectangle(), cell.getCellRectangle().rotateProperty().get()); } } @@ -452,7 +451,7 @@ public void handle(ActionEvent actionEvent) { } private void setTranslationAnimation(ImagePattern imagePattern, Cell cell, Card card) { - Rectangle rectangle=cell.getCellRectangle(); + Rectangle rectangle = cell.getCellRectangle(); TranslateTransition trans = new TranslateTransition(Duration.seconds(2), rectangle); trans.setToX(rectangle.getX()); double constant = 1; @@ -462,8 +461,8 @@ private void setTranslationAnimation(ImagePattern imagePattern, Cell cell, Card trans.setFromX(constant * CardActionsMenu.getLastMousePositionX()); trans.setToY(rectangle.getY()); trans.setFromY(constant * CardActionsMenu.getLastMousePositionY()); - if(card.isMonster()) - cell.getCellInfo().setText(((Monster) card).getAtk() + "/" + ((Monster) card).getDef()); + if (card.isMonster()) + cell.getCellInfo().setText(((Monster) card).getAtk() + "/" + ((Monster) card).getDef()); rectangle.setFill(imagePattern); trans.play(); } @@ -560,7 +559,7 @@ public void addCardToHandDeck(Card cardToAdd, boolean isForce) { Card card = deckZone.get(i).getCellCard(); Cell cell = new Cell(card); Rectangle rectangle = new Rectangle(); - Duel.getGameController().getGameMenuController().addEventForCardImageRectangle(rectangle,cell); + Duel.getGameController().getGameMenuController().addEventForCardImageRectangle(rectangle, cell); rectangle.setWidth(90); rectangle.setHeight(120); @@ -709,11 +708,11 @@ public void addAllMonstersATK(int amount) { public ArrayList getAllMonstersFromAllFieldsWithType(MonsterType monsterType) { ArrayList result = new ArrayList<>(); - for(Cell cell:deckZone){ + for (Cell cell : deckZone) { try { - Monster monster=(Monster)cell.getCellCard(); - if(monster.getMonsterType()==monsterType)result.add(cell); - }catch (Exception e){ + Monster monster = (Monster) cell.getCellCard(); + if (monster.getMonsterType() == monsterType) result.add(cell); + } catch (Exception e) { } } diff --git a/src/main/java/yugioh/model/cards/Card.java b/src/main/java/yugioh/model/cards/Card.java index 6f51f99a..18cfb2ba 100644 --- a/src/main/java/yugioh/model/cards/Card.java +++ b/src/main/java/yugioh/model/cards/Card.java @@ -22,6 +22,7 @@ public class Card { allCards = new ArrayList<>(); } + public boolean isCustom = false; protected String name; protected String description; protected int price; @@ -32,7 +33,6 @@ public class Card { transient protected ImagePattern cardImagePattern; transient protected ImageView backImage; transient protected ImagePattern backImagePattern; - public boolean isCustom=false; public Card(String name, String description, int price, Kind cardKind, SpellOrTrap magicType) { @@ -354,7 +354,7 @@ public static ImageView getCardImage(Card card, int width) { // } // else name = card.getClass().getName().replaceAll("yugioh.model.cards.monsters.", // "").replaceAll("yugioh.model.cards.trapandspells.", ""); - else name= card.image; + else name = card.image; File imageFile = new File(name); if (!imageFile.exists()) { System.out.println(name); @@ -391,6 +391,10 @@ public String getImage() { return image; } + public void setImage(ImageView imageView) { + this.cardImage = imageView; + } + public String getDescription() { return description; } @@ -445,12 +449,12 @@ public Kind getCardKind() { } public void setImage() { - String name=""; - if(!isCustom) - name = getClass().getName().replaceAll("yugioh.model.cards.monsters.", - "").replaceAll("yugioh.model.cards.trapandspells.", ""); - else{ - name=this.name; + String name = ""; + if (!isCustom) + name = getClass().getName().replaceAll("yugioh.model.cards.monsters.", + "").replaceAll("yugioh.model.cards.trapandspells.", ""); + else { + name = this.name; } image = "src/resources/yugioh/PNG/cardsImages/" + name + ".jpg"; cardImage = new ImageView(new Image(new File(image).toURI().toString())); @@ -459,9 +463,6 @@ public void setImage() { toURI().toString())); backImagePattern = new ImagePattern(new Image(new File("src/resources/yugioh/PNG/cardsImages/Unknown.jpg").toURI().toString())); } - public void setImage(ImageView imageView){ - this.cardImage=imageView; - } public ImageView getCardImageForDeck(int width) { if (cardImage == null) { @@ -490,9 +491,9 @@ public ImagePattern getCardBackImagePattern() { return backImagePattern; } - public enum Kind {MONSTER, MAGIC} - public void setIsCustom() { isCustom = true; } + + public enum Kind {MONSTER, MAGIC} } diff --git a/src/main/java/yugioh/model/cards/SpellAndTrap.java b/src/main/java/yugioh/model/cards/SpellAndTrap.java index b84ffe1e..76378f94 100644 --- a/src/main/java/yugioh/model/cards/SpellAndTrap.java +++ b/src/main/java/yugioh/model/cards/SpellAndTrap.java @@ -1,8 +1,5 @@ package yugioh.model.cards; -import javafx.animation.KeyFrame; -import javafx.animation.Timeline; -import javafx.util.Duration; import yugioh.controller.gamephasescontrollers.GameController; import yugioh.model.board.CardStatus; import yugioh.model.board.Cell; @@ -41,13 +38,13 @@ public static void activateSpellEffects(GameController gameController, String sp else if (spellAndTrapName.equals("Swords of Revealing Light")) SwordsofRevealingLight.setActivated(gameController); else if (spellAndTrapName.equals("Twin Twisters")) TwinTwisters.setActivated(gameController); - else if(spellAndTrapName.equals("Umiiruka"))Umiiruka.setActivated(gameController); + else if (spellAndTrapName.equals("Umiiruka")) Umiiruka.setActivated(gameController); else if (spellAndTrapName.equals("Mystical space typhoon")) Mysticalspacetyphoon.setActivated(gameController); else if (spellAndTrapName.equals("Black Pendant")) BlackPendant.setActivated(gameController); else if (spellAndTrapName.equals("United We Stand")) UnitedWeStand.setActivated(gameController); else if (spellAndTrapName.equals("Sword of dark destruction")) Swordofdarkdestruction.setActivated(gameController); - else if(spellAndTrapName.equals("Raigeki"))Raigeki.setActivated(gameController); + else if (spellAndTrapName.equals("Raigeki")) Raigeki.setActivated(gameController); else if (spellAndTrapName.equals("Magnum Shield")) MagnumShield.setActivated(gameController); else if (spellAndTrapName.equals("Advanced Ritual Art")) AdvancedRitualArt.setActivated(gameController); else if (spellAndTrapName.equals("Torrential Tribute")) TorrentialTribute.setActivated(gameController); @@ -55,7 +52,7 @@ else if (spellAndTrapName.equals("Sword of dark destruction")) else if (spellAndTrapName.equals("Mirror Force")) MirrorForce.setActivated(gameController); else if (spellAndTrapName.equals("Negate Attack")) NegateAttack.setActivated(gameController); else if (spellAndTrapName.equals("Magic Cylinder")) MagicCylinder.setActivated(gameController); - else if(spellAndTrapName.equals("Forest"))Forest.setActivated(gameController); + else if (spellAndTrapName.equals("Forest")) Forest.setActivated(gameController); else { ViewInterface.showResult(GameResponses.ACTIVATION_ONLY_FOR_SPELL.response); } @@ -76,12 +73,8 @@ public static void updateSpellInGameBoard(GameController gameController) { } else { try { - if (!(((SpellAndTrap) card).getAttribute() == SpellOrTrapAttribute.CONTINUOUS) && - !(((SpellAndTrap) card).getAttribute() == SpellOrTrapAttribute.EQUIP)) { - playerGameBoard.addCardToSpellAndTrapCardZone(card, CardStatus.OCCUPIED, gameController, true); - } else { - playerGameBoard.addCardToSpellAndTrapCardZone(card, CardStatus.OCCUPIED, gameController, false); - } + playerGameBoard.addCardToSpellAndTrapCardZone(card, CardStatus.OCCUPIED, gameController, !(((SpellAndTrap) card).getAttribute() == SpellOrTrapAttribute.CONTINUOUS) && + !(((SpellAndTrap) card).getAttribute() == SpellOrTrapAttribute.EQUIP)); } catch (GameException ignored) { } } @@ -89,13 +82,8 @@ public static void updateSpellInGameBoard(GameController gameController) { } else { SpellAbsorption.handleEffect(); selectedCell.setCardStatus(CardStatus.OCCUPIED); - if (!(((SpellAndTrap) card).getAttribute() == SpellOrTrapAttribute.CONTINUOUS) && - !(((SpellAndTrap) card).getAttribute() == SpellOrTrapAttribute.EQUIP)) { - gameController.currentTurnPlayer.getGameBoard().setFlipTransition(selectedCell.getCellCard(), selectedCell.getCellRectangle(), false,true); - } - else{ - gameController.currentTurnPlayer.getGameBoard().setFlipTransition(selectedCell.getCellCard(), selectedCell.getCellRectangle(), false,false); - } + gameController.currentTurnPlayer.getGameBoard().setFlipTransition(selectedCell.getCellCard(), selectedCell.getCellRectangle(), false, !(((SpellAndTrap) card).getAttribute() == SpellOrTrapAttribute.CONTINUOUS) && + !(((SpellAndTrap) card).getAttribute() == SpellOrTrapAttribute.EQUIP)); Cell.deselectCell(); } } diff --git a/src/main/java/yugioh/model/cards/monsters/Texchanger.java b/src/main/java/yugioh/model/cards/monsters/Texchanger.java index 4e14f1dd..db160cf1 100644 --- a/src/main/java/yugioh/model/cards/monsters/Texchanger.java +++ b/src/main/java/yugioh/model/cards/monsters/Texchanger.java @@ -1,30 +1,15 @@ package yugioh.model.cards.monsters; -import javafx.application.Platform; -import javafx.event.EventHandler; -import javafx.geometry.Insets; -import javafx.scene.Scene; -import javafx.scene.control.ScrollPane; -import javafx.scene.image.ImageView; -import javafx.scene.input.MouseEvent; -import javafx.scene.layout.GridPane; -import javafx.scene.layout.HBox; -import javafx.scene.shape.Rectangle; -import javafx.stage.Stage; -import yugioh.controller.CheatController; import yugioh.controller.gamephasescontrollers.CardSelectionMenuController; import yugioh.controller.gamephasescontrollers.GameController; import yugioh.model.board.Cell; -import yugioh.model.cards.Card; import yugioh.model.cards.Monster; import yugioh.model.cards.cardfeaturesenums.CardType; import yugioh.model.cards.cardfeaturesenums.MonsterAttribute; import yugioh.model.cards.cardfeaturesenums.MonsterType; -import yugioh.model.exceptions.GameException; import yugioh.view.ViewInterface; import yugioh.view.gamephases.CardSelectionMenu; import yugioh.view.menus.PopUpWindow; -import yugioh.view.menus.Toast; import yugioh.view.menus.WelcomeMenu; import java.util.ArrayList; @@ -53,16 +38,16 @@ public static boolean handleEffect(GameController gameController, Cell attackedC ViewInterface.showResult("Texchanger effect activated:"); ViewInterface.showResult("Turn changed temporary."); gameController.changeTurn(true, false); - if(gameController.currentTurnPlayer.getGameBoard().isMonsterZoneFull()){ + if (gameController.currentTurnPlayer.getGameBoard().isMonsterZoneFull()) { ViewInterface.showResult("Error: monster zone is full"); - gameController.changeTurn(true,true); - } - else { + gameController.changeTurn(true, true); + } else { CardSelectionMenuController.setCardsToShow(monsters); try { new CardSelectionMenu().execute(); new PopUpWindow("select a monster to special summon").start(WelcomeMenu.stage); - } catch (Exception e) {} + } catch (Exception e) { + } Cell oldSelectedCell = Cell.getSelectedCell(); Cell.setSelectedCell(oldSelectedCell); usedTexChangerCellsThisTurn.add(attackedCell); @@ -85,7 +70,7 @@ public static boolean handleEffect(GameController gameController, Cell attackedC // gameController.changeTurn(true,true); // } // }); - // } + // } // Scene scene = WelcomeMenu.createScene(hBox); @@ -147,7 +132,7 @@ public static boolean handleEffect(GameController gameController, Cell attackedC // }); // }).start(); } - return true; + return true; } public static void makeArrayEmpty() { diff --git a/src/main/java/yugioh/model/cards/trapandspells/Forest.java b/src/main/java/yugioh/model/cards/trapandspells/Forest.java index 575b115c..514a1bdc 100644 --- a/src/main/java/yugioh/model/cards/trapandspells/Forest.java +++ b/src/main/java/yugioh/model/cards/trapandspells/Forest.java @@ -31,7 +31,7 @@ public static void setActivated(GameController gameController) { } public static void deActivateEffect(GameController gameController) { - if(Cell.getSelectedCell()!=null&&!Cell.getSelectedCell().isEmpty()&&Cell.getSelectedCell().getCellCard().getName().equals("Forest")) { + if (Cell.getSelectedCell() != null && !Cell.getSelectedCell().isEmpty() && Cell.getSelectedCell().getCellCard().getName().equals("Forest")) { Cell[] currentTurnPlayerMonsterCardZone = gameController.getCurrentTurnPlayer().getGameBoard().getMonsterCardZone(); Cell[] currentTurnOpponentPlayerMonsterCardZone = gameController.getCurrentTurnOpponentPlayer().getGameBoard().getMonsterCardZone(); ViewInterface.showResult("Forest effect deactivated : All Insect, Beast, Plant, and Beast-Warrior monsters on the field lose 200 ATK/DEF."); @@ -44,7 +44,7 @@ public static void deActivateEffect(GameController gameController) { private static void increaseOpponentPlayerMonstersAttack(Cell[] monsterCardZone) { for (Cell monster : monsterCardZone ) { - if (!monster.isEmpty()&&isForForest(monster)) { + if (!monster.isEmpty() && isForForest(monster)) { ((Monster) monster.getCellCard()).addATK(200); ((Monster) monster.getCellCard()).addDEF(200); effectedMonsters.add((Monster) monster.getCellCard()); diff --git a/src/main/java/yugioh/model/cards/trapandspells/NegateAttack.java b/src/main/java/yugioh/model/cards/trapandspells/NegateAttack.java index be26e7e1..671dd2f8 100644 --- a/src/main/java/yugioh/model/cards/trapandspells/NegateAttack.java +++ b/src/main/java/yugioh/model/cards/trapandspells/NegateAttack.java @@ -2,7 +2,6 @@ import yugioh.controller.gamephasescontrollers.GameController; import yugioh.model.board.Cell; -import yugioh.model.cards.Monster; import yugioh.model.cards.SpellAndTrap; import yugioh.model.cards.cardfeaturesenums.EffectiveTerm; import yugioh.model.cards.cardfeaturesenums.SpellOrTrap; @@ -11,6 +10,7 @@ public class NegateAttack extends SpellAndTrap { public static Cell attackerCell; + public NegateAttack() { super("Negate Attack", "When an opponent's monster declares an attack: Target the attacking monster; negate the attack, then end the Battle Phase.", 3000, SpellOrTrap.TRAP, SpellOrTrapAttribute.COUNTER, EffectiveTerm.UNLIMITED); @@ -18,7 +18,7 @@ public NegateAttack() { public static void setActivated(GameController gameController) { gameController.getBattlePhaseController().setAttackDisabled(); - // gameController.currentTurnOpponentPlayer.decreaseLP(((Monster)attackerCell.getCellCard()).getAtk()); + // gameController.currentTurnOpponentPlayer.decreaseLP(((Monster)attackerCell.getCellCard()).getAtk()); ViewInterface.showResult("Negate Attack effect activated : attack is negated and opponent Battle Phase ended"); gameController.changePhase(); updateSpellInGameBoard(gameController); diff --git a/src/main/java/yugioh/model/cards/trapandspells/Terraforming.java b/src/main/java/yugioh/model/cards/trapandspells/Terraforming.java index b7a94ecf..e8110998 100644 --- a/src/main/java/yugioh/model/cards/trapandspells/Terraforming.java +++ b/src/main/java/yugioh/model/cards/trapandspells/Terraforming.java @@ -23,7 +23,7 @@ public static void setActivated(GameController gameController) { for (Cell cell : playerGameBoard.getDeckZone()) { if (cell.getCellCard().isSpell() && ((SpellAndTrap) cell.getCellCard()).getAttribute() == SpellOrTrapAttribute.FIELD) { fieldSpell = cell; - playerGameBoard.addCardToHandDeck(fieldSpell.getCellCard(),false); + playerGameBoard.addCardToHandDeck(fieldSpell.getCellCard(), false); break; } } diff --git a/src/main/java/yugioh/model/cards/trapandspells/Umiiruka.java b/src/main/java/yugioh/model/cards/trapandspells/Umiiruka.java index fb1ff372..e4de496e 100644 --- a/src/main/java/yugioh/model/cards/trapandspells/Umiiruka.java +++ b/src/main/java/yugioh/model/cards/trapandspells/Umiiruka.java @@ -35,7 +35,7 @@ public static void setActivated(GameController gameController) { } public static void deActivateEffect(Cell cell) { - if(!cell.isEmpty()&&cell.getCellCard().getName().equals("Umiiruka")) { + if (!cell.isEmpty() && cell.getCellCard().getName().equals("Umiiruka")) { ViewInterface.showResult("Umiiruka deactivated: all WATER monsters ATK decrease by 500 points and their DEF increased by 400 points."); deactivateForPlayersMonsters(); } @@ -44,7 +44,7 @@ public static void deActivateEffect(Cell cell) { private static void activateForPlayersMonsters(Cell[] monsterCardZone) { for (Cell monster : monsterCardZone ) { - if (!monster.isEmpty()&&isForUmiiruka(monster)) { + if (!monster.isEmpty() && isForUmiiruka(monster)) { ((Monster) monster.getCellCard()).addATK(500); ((Monster) monster.getCellCard()).addDEF(-400); effectedMonsters.add((Monster) monster.getCellCard()); diff --git a/src/main/java/yugioh/view/gamephases/CardActionsMenu.java b/src/main/java/yugioh/view/gamephases/CardActionsMenu.java index 8b09c2ad..03047484 100644 --- a/src/main/java/yugioh/view/gamephases/CardActionsMenu.java +++ b/src/main/java/yugioh/view/gamephases/CardActionsMenu.java @@ -42,36 +42,36 @@ public class CardActionsMenu implements MainPhasesController { private static HashMap> toBeRemovedSelectionEventHandlers = new HashMap<>(); - private static HashMap>> allCellEventHandlers = new HashMap<>(); - private static Stage actionsStage = new Stage(); - private static Stage errorStage = new Stage(); + private static final HashMap>> allCellEventHandlers = new HashMap<>(); + private static final Stage actionsStage = new Stage(); + private static final Stage errorStage = new Stage(); private static double xImage; private static double yImage; private static ImageView actionButton; private static Rectangle imageRectangle; - private static ArrayList handMonsterActions = new ArrayList<>(); - private static ArrayList handSpellAndTrapActions = new ArrayList<>(); - private static ArrayList boardMonsterActions = new ArrayList<>(); - private static ArrayList boardSpellAndTrapActions = new ArrayList<>(); + private static final ArrayList handMonsterActions = new ArrayList<>(); + private static final ArrayList handSpellAndTrapActions = new ArrayList<>(); + private static final ArrayList boardMonsterActions = new ArrayList<>(); + private static final ArrayList boardSpellAndTrapActions = new ArrayList<>(); private static ArrayList thisActions = new ArrayList<>(); private static Pane gamePane; private static Pane actionPane; - private static int place = 6; + private static final int place = 6; private static GameController gameController; private static double lastMousePositionX = 0; private static double lastMousePositionY = 0; private static Cell toBeSummonedCell; - private static Image setImageH = new Image(new File("src\\resources\\yugioh\\PNG\\icon\\SetH.png") + private static final Image setImageH = new Image(new File("src\\resources\\yugioh\\PNG\\icon\\SetH.png") .toURI().toString()); - private static Image setImageV = new Image(new File("src\\resources\\yugioh\\PNG\\icon\\SetV.png"). + private static final Image setImageV = new Image(new File("src\\resources\\yugioh\\PNG\\icon\\SetV.png"). toURI().toString()); - private static Image summonImage = new Image(new File("src\\resources\\yugioh\\PNG\\icon\\NormalSummon.png"). + private static final Image summonImage = new Image(new File("src\\resources\\yugioh\\PNG\\icon\\NormalSummon.png"). toURI().toString()); - private static Image attackImage = new Image(new File("src\\resources\\yugioh\\PNG\\icon\\Attack.png"). + private static final Image attackImage = new Image(new File("src\\resources\\yugioh\\PNG\\icon\\Attack.png"). toURI().toString()); - private static Image activateImage = new Image(new File("src\\resources\\yugioh\\PNG\\icon\\Activate.png").toURI().toString()); - private static Image flipSummonImage = new Image(new File("src\\resources\\yugioh\\PNG\\icon\\Flip summon.png").toURI().toString()); - private static Image changePositionImage = new Image(new File("src\\resources\\yugioh\\PNG\\icon\\ChangePosition.png").toURI().toString()); + private static final Image activateImage = new Image(new File("src\\resources\\yugioh\\PNG\\icon\\Activate.png").toURI().toString()); + private static final Image flipSummonImage = new Image(new File("src\\resources\\yugioh\\PNG\\icon\\Flip summon.png").toURI().toString()); + private static final Image changePositionImage = new Image(new File("src\\resources\\yugioh\\PNG\\icon\\ChangePosition.png").toURI().toString()); private static ImageView activeSword; private static Rectangle activeRectangle; private static int counter = 0; diff --git a/src/main/java/yugioh/view/gamephases/CardSelectionMenu.java b/src/main/java/yugioh/view/gamephases/CardSelectionMenu.java index 8b149fb2..e4341c53 100644 --- a/src/main/java/yugioh/view/gamephases/CardSelectionMenu.java +++ b/src/main/java/yugioh/view/gamephases/CardSelectionMenu.java @@ -10,13 +10,15 @@ import java.net.URL; public class CardSelectionMenu extends WelcomeMenu { - public static Stage cardSelectionStage=new Stage(); + public static Stage cardSelectionStage = new Stage(); + static { cardSelectionStage.initOwner(WelcomeMenu.stage); cardSelectionStage.initStyle(StageStyle.UNDECORATED); cardSelectionStage.setX(500); cardSelectionStage.setY(250); } + @Override public void start(Stage stage) throws Exception { URL url = getClass().getResource("/yugioh/fxml/CardSelectionMenu.fxml"); diff --git a/src/main/java/yugioh/view/gamephases/Duel.java b/src/main/java/yugioh/view/gamephases/Duel.java index 91f5f996..16651b1f 100644 --- a/src/main/java/yugioh/view/gamephases/Duel.java +++ b/src/main/java/yugioh/view/gamephases/Duel.java @@ -2,7 +2,6 @@ import javafx.animation.KeyFrame; import javafx.animation.Timeline; -import javafx.scene.image.Image; import javafx.util.Duration; import yugioh.controller.CheatController; import yugioh.controller.gamephasescontrollers.GameController; @@ -202,7 +201,6 @@ private static void assignTurn() { else { - // String playerName = gameController.getGame().getLosers().get(gameController.getGame().getLosers().size() - 1).getUser().getNickname(); // ViewInterface.showResult(playerName + " do you want to be the first player? yes/no"); // String input = ViewInterface.getInput(); diff --git a/src/main/java/yugioh/view/gamephases/Graveyard.java b/src/main/java/yugioh/view/gamephases/Graveyard.java index 5dfe1433..2602ef6f 100644 --- a/src/main/java/yugioh/view/gamephases/Graveyard.java +++ b/src/main/java/yugioh/view/gamephases/Graveyard.java @@ -7,7 +7,6 @@ import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.paint.Color; -import javafx.stage.Modality; import javafx.stage.Stage; import javafx.stage.StageStyle; import javafx.util.Duration; diff --git a/src/main/java/yugioh/view/gamephases/MainPhase1.java b/src/main/java/yugioh/view/gamephases/MainPhase1.java index 35dd4a5c..a36309b6 100644 --- a/src/main/java/yugioh/view/gamephases/MainPhase1.java +++ b/src/main/java/yugioh/view/gamephases/MainPhase1.java @@ -109,7 +109,7 @@ else if (gameController.checkCommandIsNotInCurrentPhase(command)) { } else if (command.matches(GameRegexes.CHEAT_ADD_OPTIONAL_CARD.regex)) { Matcher matcher = ViewInterface.getCommandMatcher(command, GameRegexes.CHEAT_ADD_OPTIONAL_CARD.regex); try { - response = cheatController.addOptionalCardAndSelect(matcher.group(1), gameController,false); + response = cheatController.addOptionalCardAndSelect(matcher.group(1), gameController, false); } catch (GameException e) { response = e.toString(); } diff --git a/src/main/java/yugioh/view/gamephases/MainPhase2.java b/src/main/java/yugioh/view/gamephases/MainPhase2.java index c604795e..30ea62f8 100644 --- a/src/main/java/yugioh/view/gamephases/MainPhase2.java +++ b/src/main/java/yugioh/view/gamephases/MainPhase2.java @@ -99,8 +99,7 @@ protected String processCommand(String command) { } catch (GameException e) { response = e.toString(); } - } - else if (command.matches(GameRegexes.SURRENDER.regex)) { + } else if (command.matches(GameRegexes.SURRENDER.regex)) { gameController.surrender(); } else if (command.matches(GameRegexes.INCREASE_LP.regex)) { Matcher matcher = ViewInterface.getCommandMatcher(command, GameRegexes.INCREASE_LP.regex); @@ -119,7 +118,7 @@ else if (command.matches(GameRegexes.SURRENDER.regex)) { } else if (command.matches(GameRegexes.CHEAT_ADD_OPTIONAL_CARD.regex)) { Matcher matcher = ViewInterface.getCommandMatcher(command, GameRegexes.CHEAT_ADD_OPTIONAL_CARD.regex); try { - response = cheatController.addOptionalCardAndSelect(matcher.group(1), gameController,false); + response = cheatController.addOptionalCardAndSelect(matcher.group(1), gameController, false); } catch (GameException e) { response = e.toString(); } diff --git a/src/main/java/yugioh/view/menus/CardGeneratorMenu.java b/src/main/java/yugioh/view/menus/CardGeneratorMenu.java index 9d440fe0..3b260cbf 100644 --- a/src/main/java/yugioh/view/menus/CardGeneratorMenu.java +++ b/src/main/java/yugioh/view/menus/CardGeneratorMenu.java @@ -1,15 +1,11 @@ package yugioh.view.menus; -import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; -import yugioh.model.User; -import yugioh.model.cards.Card; import java.net.URL; -import java.util.ArrayList; public class CardGeneratorMenu extends WelcomeMenu { @Override diff --git a/src/main/java/yugioh/view/menus/DetermineStarterMenu.java b/src/main/java/yugioh/view/menus/DetermineStarterMenu.java index 917f1f3d..9b9696f7 100644 --- a/src/main/java/yugioh/view/menus/DetermineStarterMenu.java +++ b/src/main/java/yugioh/view/menus/DetermineStarterMenu.java @@ -6,7 +6,6 @@ import javafx.stage.Modality; import javafx.stage.Stage; import javafx.stage.StageStyle; -import yugioh.model.Player; import java.net.URL; diff --git a/src/main/java/yugioh/view/menus/EndOfGameMenu.java b/src/main/java/yugioh/view/menus/EndOfGameMenu.java index 0972214f..49d81e46 100644 --- a/src/main/java/yugioh/view/menus/EndOfGameMenu.java +++ b/src/main/java/yugioh/view/menus/EndOfGameMenu.java @@ -1,9 +1,7 @@ package yugioh.view.menus; import javafx.event.EventHandler; -import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; -import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; @@ -14,8 +12,6 @@ import javafx.stage.Stage; import javafx.stage.StageStyle; import yugioh.controller.gamephasescontrollers.GameController; -import yugioh.controller.menucontroller.DeckMenuController; -import yugioh.model.User; import yugioh.view.gamephases.Duel; import java.net.URL; @@ -26,10 +22,18 @@ public class EndOfGameMenu extends WelcomeMenu { private static Stage stage; private boolean isEndOfTheGame; - public void execute(String resultString,boolean isEndOfTheGame) throws Exception { - Toast.isGameEnded=true; - this.resultString = resultString; - this.isEndOfTheGame=isEndOfTheGame; + public static void closeStage() { + stage.close(); + } + + public static String getResultString() { + return resultString; + } + + public void execute(String resultString, boolean isEndOfTheGame) throws Exception { + Toast.isGameEnded = true; + EndOfGameMenu.resultString = resultString; + this.isEndOfTheGame = isEndOfTheGame; start(stage); } @@ -37,22 +41,22 @@ public void execute(String resultString,boolean isEndOfTheGame) throws Exception public void start(Stage primaryStage) throws Exception { URL url = getClass().getResource("/yugioh/fxml/EndOfGameMenu.fxml"); Pane pane = FXMLLoader.load(url); - if(!isEndOfTheGame){ - ((VBox)pane.getChildren().get(3)).getChildren().remove(1); - Button yesButton=new Button(); + if (!isEndOfTheGame) { + ((VBox) pane.getChildren().get(3)).getChildren().remove(1); + Button yesButton = new Button(); yesButton.setText("yes"); - Button noButton=new Button(); - GameController gameController=Duel.getGameController(); + Button noButton = new Button(); + GameController gameController = Duel.getGameController(); yesButton.setOnMouseClicked(new EventHandler() { @Override public void handle(MouseEvent mouseEvent) { gameController.setCurrentTurnPlayer(gameController.getGame().getLosers().get(gameController.getGame().getLosers().size() - 1)); - gameController.setCurrentTurnOpponentPlayer(gameController.getGame().getWinners().get(gameController.getGame().getWinners().size() - 1)); - Duel.runGame(gameController); + gameController.setCurrentTurnOpponentPlayer(gameController.getGame().getWinners().get(gameController.getGame().getWinners().size() - 1)); + Duel.runGame(gameController); - stage.close(); - Toast.isGameEnded=false; + stage.close(); + Toast.isGameEnded = false; } }); noButton.setText("no"); @@ -74,14 +78,14 @@ public void handle(MouseEvent mouseEvent) { @Override public void handle(MouseEvent mouseEvent) { gameController.setCurrentTurnPlayer(gameController.getGame().getWinners().get(gameController.getGame().getWinners().size() - 1)); - gameController.setCurrentTurnOpponentPlayer(gameController.getGame().getLosers().get(gameController.getGame().getLosers().size() - 1)); - Duel.runGame(gameController); - stage.close(); - Toast.isGameEnded=false; + gameController.setCurrentTurnOpponentPlayer(gameController.getGame().getLosers().get(gameController.getGame().getLosers().size() - 1)); + Duel.runGame(gameController); + stage.close(); + Toast.isGameEnded = false; } }); String playerName = gameController.getGame().getLosers().get(gameController.getGame().getLosers().size() - 1).getUser().getNickname(); - Label label=new Label( playerName + " do you want to be the first player?"); + Label label = new Label(playerName + " do you want to be the first player?"); label.setLayoutX(400); label.setLayoutY(400); label.getStyleClass().add("buttonText"); @@ -98,13 +102,4 @@ public void handle(MouseEvent mouseEvent) { stage.show(); } - - public static void closeStage() { - stage.close(); - } - - public static String getResultString() { - return resultString; - } - } diff --git a/src/main/java/yugioh/view/menus/Toast.java b/src/main/java/yugioh/view/menus/Toast.java index 547db518..de088bbc 100644 --- a/src/main/java/yugioh/view/menus/Toast.java +++ b/src/main/java/yugioh/view/menus/Toast.java @@ -16,7 +16,8 @@ import yugioh.controller.menucontroller.GameMenuController; public final class Toast { - public static boolean isGameEnded=false; + public static boolean isGameEnded = false; + public static void makeText(Stage ownerStage, String toastMsg) { int toastDelay = 2500; int fadeInDelay = 250; @@ -40,7 +41,7 @@ public static void makeText(Stage ownerStage, String toastMsg) { Scene scene = WelcomeMenu.createScene(root); scene.setFill(Color.TRANSPARENT); toastStage.setScene(scene); - if(!(GameMenuController.pauseStage!=null&&GameMenuController.pauseStage.isShowing())&&!isGameEnded){ + if (!(GameMenuController.pauseStage != null && GameMenuController.pauseStage.isShowing()) && !isGameEnded) { toastStage.show(); } try {