diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 7b7dad7..e49a93d 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,12 +1,13 @@ import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; -import controller.User; import controller.ApplicationManger; +import controller.User; import model.UserData; import model.cards.data.ReadMonsterCardsData; import model.cards.data.ReadSpellTrapCardsData; -import java.io.*; +import java.io.File; +import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; @@ -16,7 +17,7 @@ public static void main(String[] args) { ApplicationManger applicationManger = new ApplicationManger(); try { firstSetup(); - }catch (IOException e){ + } catch (IOException e) { System.out.println("ERROR: Couldn't load game!"); System.exit(-1); } diff --git a/src/main/java/controller/ApplicationManger.java b/src/main/java/controller/ApplicationManger.java index 1bb50b8..f768899 100644 --- a/src/main/java/controller/ApplicationManger.java +++ b/src/main/java/controller/ApplicationManger.java @@ -2,9 +2,6 @@ import view.menus.*; -import java.io.*; -import java.util.Locale; - public class ApplicationManger { private static Scene currentScene; private static User loggedInUser; diff --git a/src/main/java/controller/DataManager.java b/src/main/java/controller/DataManager.java index 946df59..398a4b4 100644 --- a/src/main/java/controller/DataManager.java +++ b/src/main/java/controller/DataManager.java @@ -4,16 +4,17 @@ import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import model.UserData; import model.cards.data.CardData; import model.cards.data.MonsterCardData; import model.cards.data.SpellCardData; import model.cards.data.TrapCardData; -import java.io.*; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; -import java.util.ArrayList; public class DataManager { @@ -28,7 +29,7 @@ public static void exportCard(CardData cardData) { fileWriter.write(new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().toJson(cardData)); fileWriter.close(); System.out.println("card exported successfully."); - }catch (IOException e) { + } catch (IOException e) { System.out.println("the file isn't saved yet."); } } @@ -44,7 +45,7 @@ public static void importCard(String cardName) { JsonObject jsonObject = JsonParser.parseReader(fileReader).getAsJsonObject(); CardData cardData; switch (jsonObject.get("cardType").toString().replaceAll("\"", "")) { - case "MONSTER" : + case "MONSTER": cardData = new Gson().fromJson(fileData, MonsterCardData.class); break; case "SPELL": diff --git a/src/main/java/controller/GamePlaySceneController.java b/src/main/java/controller/GamePlaySceneController.java index d0f284f..fd281f1 100644 --- a/src/main/java/controller/GamePlaySceneController.java +++ b/src/main/java/controller/GamePlaySceneController.java @@ -1,6 +1,5 @@ package controller; -import controller.gameplay.AI_Player; import controller.gameplay.GameManager; import model.Command; import model.Deck; diff --git a/src/main/java/controller/ProfileController.java b/src/main/java/controller/ProfileController.java index c5a8c34..15a4a91 100644 --- a/src/main/java/controller/ProfileController.java +++ b/src/main/java/controller/ProfileController.java @@ -2,13 +2,11 @@ import model.Command; import model.enums.CommandFieldType; +import model.enums.ProfileMessages; import model.exceptions.ParseCommandException; import view.menus.ProfileScene; import java.util.HashMap; -import java.util.regex.Matcher; - -import model.enums.ProfileMessages; public class ProfileController { diff --git a/src/main/java/controller/RegisterController.java b/src/main/java/controller/RegisterController.java index d47c979..75e0b91 100644 --- a/src/main/java/controller/RegisterController.java +++ b/src/main/java/controller/RegisterController.java @@ -23,7 +23,7 @@ public static int registerUser(String userInput) { if (User.doesUsernameExists(registerCommand.getField("username"))) System.out.println("user with username " + registerCommand.getField("username") + " already exists"); else if (User.doesNicknameExists(registerCommand.getField("nickname"))) - System.out.println("user with nickname "+ registerCommand.getField("nickname") +" already exists"); + System.out.println("user with nickname " + registerCommand.getField("nickname") + " already exists"); else { User user = new User(registerCommand.getField("username"), registerCommand.getField("nickname"), registerCommand.getField("password")); System.out.println("user created successfully!"); diff --git a/src/main/java/controller/ShopController.java b/src/main/java/controller/ShopController.java index 5254f7f..c26ff55 100644 --- a/src/main/java/controller/ShopController.java +++ b/src/main/java/controller/ShopController.java @@ -17,12 +17,10 @@ public void buyCard(String cardName) { CardData cardData = CardData.getCardByName(cardName); if (cardData == null) { shopScene.printMessage("there is no card with this name"); - } - else if (activeUser.getUserData().getMoney() < cardData.getPrice()) { + } else if (activeUser.getUserData().getMoney() < cardData.getPrice()) { shopScene.printMessage("you have not enough money"); shopScene.printMessage("your money is " + activeUser.getUserData().getMoney() + " card Price is " + cardData.getPrice()); - } - else { + } else { activeUser.getUserData().decreaseMoney(cardData.getPrice()); activeUser.getUserData().addCard(cardData.getCardId()); shopScene.printMessage("you bought " + cardName + " successfully."); diff --git a/src/main/java/controller/User.java b/src/main/java/controller/User.java index 34e7956..f70d7e4 100644 --- a/src/main/java/controller/User.java +++ b/src/main/java/controller/User.java @@ -19,7 +19,7 @@ public User(String username, String nickname, String password) { allUser.add(this); } - public User(UserData data){ + public User(UserData data) { userData = data; allUser.add(this); } @@ -82,7 +82,7 @@ public void addDeck(Deck deck) { userData.addDeck(deck); } - public Deck getActiveDeck(){ + public Deck getActiveDeck() { return userData.getActiveDeck(); } @@ -94,7 +94,7 @@ public String getUsername() { return userData.getUsername(); } - public boolean haveThisCardFree(String cardName){ + public boolean haveThisCardFree(String cardName) { try { return getCardsThatThereIsNotInAnyDeck().contains(Card.getCardIdByName(cardName)); } catch (Exception e) { @@ -104,7 +104,7 @@ public boolean haveThisCardFree(String cardName){ public ArrayList getCardsThatThereIsNotInAnyDeck() { ArrayList result = new ArrayList<>(userData.getMyCardsIds()); - for (Deck deck : getDecks()){ + for (Deck deck : getDecks()) { deck.getMainDeckIds().forEach(result::remove); deck.getSideDeckIds().forEach(result::remove); } diff --git a/src/main/java/controller/gameplay/AI_Player.java b/src/main/java/controller/gameplay/AI_Player.java index 68aa42b..7db6a1a 100644 --- a/src/main/java/controller/gameplay/AI_Player.java +++ b/src/main/java/controller/gameplay/AI_Player.java @@ -78,12 +78,12 @@ private void setTraps() { } } - private void activateSpells(){ + private void activateSpells() { if (board.isSpellTrapZoneFull()) return; ArrayList spellCards = new ArrayList<>(); spellCards.addAll(board.getHand().getAllCards().stream().filter(c -> c.getCardType() == CardType.SPELL).collect(Collectors.toList())); ArrayList fieldCards = new ArrayList<>(); - fieldCards.addAll(spellCards.stream().filter(c -> ((SpellCard)c).getData().getSpellProperty() == SpellTrapProperty.FIELD).collect(Collectors.toList())); + fieldCards.addAll(spellCards.stream().filter(c -> ((SpellCard) c).getData().getSpellProperty() == SpellTrapProperty.FIELD).collect(Collectors.toList())); spellCards.removeAll(fieldCards); while (!board.isSpellTrapZoneFull() && spellCards.size() > 0) { @@ -101,7 +101,7 @@ private void activateSpells(){ } } - if(fieldCards.size() > 0){ + if (fieldCards.size() > 0) { try { gameManager.selectCard("--hand " + (board.getHand().getAllCards().indexOf(fieldCards.get(0)) + 1)); gameManager.activateCard(); @@ -139,12 +139,12 @@ private void summonMonster() { } } - private ArrayList chooseTribute(int n){ + private ArrayList chooseTribute(int n) { ArrayList myMonsters = new ArrayList<>(board.getMonsterZone().stream().filter(c -> !c.isEmpty()).collect(Collectors.toList())); - myMonsters.sort(Comparator.comparing(c -> ((MonsterCard)c.getCard()).getData().getLevel())); + myMonsters.sort(Comparator.comparing(c -> ((MonsterCard) c.getCard()).getData().getLevel())); ArrayList result = new ArrayList<>(); - for(int i=0; i getDecks() { return decks; } - public void removeDeck(Deck deck){ + public void removeDeck(Deck deck) { decks.remove(deck); save(); } diff --git a/src/main/java/model/cards/Card.java b/src/main/java/model/cards/Card.java index 610e415..da4acb0 100644 --- a/src/main/java/model/cards/Card.java +++ b/src/main/java/model/cards/Card.java @@ -7,14 +7,10 @@ import model.effectSystem.Effect; import model.enums.CardStatus; import model.enums.CardType; -import model.enums.ZoneType; -import model.event.Event; import model.event.EventNoParam; import model.gameplay.CardSlot; import model.gameplay.Player; -import java.util.ArrayList; - public abstract class Card { protected CardType cardType; protected CardData cardData; @@ -28,7 +24,7 @@ public abstract class Card { protected EventNoParam onDestroy = new EventNoParam(); - public static Card getCardByCardData(CardData data){ + public static Card getCardByCardData(CardData data) { Card card = null; switch (data.getCardType()) { @@ -107,9 +103,9 @@ public CardType getCardType() { return cardType; } - public void setup(Player owner){ + public void setup(Player owner) { cardOwner = owner; - for (Effect effect: cardData.getEffects()){ + for (Effect effect : cardData.getEffects()) { effect.setup(); } } diff --git a/src/main/java/model/cards/MonsterCard.java b/src/main/java/model/cards/MonsterCard.java index 1ddebcf..b705c50 100644 --- a/src/main/java/model/cards/MonsterCard.java +++ b/src/main/java/model/cards/MonsterCard.java @@ -1,9 +1,9 @@ package model.cards; -import model.event.Event; import model.cards.data.MonsterCardData; import model.enums.CardStatus; import model.enums.CardType; +import model.event.Event; import model.gameplay.AttackResult; import model.gameplay.Player; @@ -60,7 +60,8 @@ public void onSummon() { isAttackPosition = true; } - public Event getFaceUp() { + + public Event getFaceUp() { return faceUp; } diff --git a/src/main/java/model/cards/SpellCard.java b/src/main/java/model/cards/SpellCard.java index 5412667..63d8fbd 100644 --- a/src/main/java/model/cards/SpellCard.java +++ b/src/main/java/model/cards/SpellCard.java @@ -21,8 +21,8 @@ public SpellCardData getData() { return (SpellCardData) cardData; } - public void activateEffect(){ - for(Effect effect: cardData.getEffects()){ + public void activateEffect() { + for (Effect effect : cardData.getEffects()) { effect.activate(); } activated = true; diff --git a/src/main/java/model/cards/TrapCard.java b/src/main/java/model/cards/TrapCard.java index dd8fbe6..38ca326 100644 --- a/src/main/java/model/cards/TrapCard.java +++ b/src/main/java/model/cards/TrapCard.java @@ -17,8 +17,8 @@ public TrapCardData getData() { return (TrapCardData) cardData; } - public void activateEffect(){ - for(Effect effect: cardData.getEffects()){ + public void activateEffect() { + for (Effect effect : cardData.getEffects()) { effect.activate(); } activated = true; diff --git a/src/main/java/model/cards/data/CardData.java b/src/main/java/model/cards/data/CardData.java index 5d600ed..035d4d1 100644 --- a/src/main/java/model/cards/data/CardData.java +++ b/src/main/java/model/cards/data/CardData.java @@ -14,12 +14,18 @@ import java.util.regex.Pattern; public abstract class CardData { - @Expose protected CardType cardType; - @Expose protected String cardName; - @Expose protected int cardId; - @Expose protected int price; - @Expose protected String cardDescription; - @Expose private String effectString; + @Expose + protected CardType cardType; + @Expose + protected String cardName; + @Expose + protected int cardId; + @Expose + protected int price; + @Expose + protected String cardDescription; + @Expose + private String effectString; protected ArrayList effects = new ArrayList<>(); private static ArrayList allCardData = new ArrayList<>(); @@ -38,11 +44,11 @@ public static CardData getCardByName(String cardName) { return null; } - public int getPrice(){ - return price; + public int getPrice() { + return price; } - public int getCardId(){ + public int getCardId() { return cardId; } @@ -58,7 +64,7 @@ public static ArrayList getAllCardData() { return allCardData; } - public String getName() { + public String getName() { return cardName; } @@ -82,13 +88,13 @@ public void setId(int id) { this.cardId = id; } - public void setEffect(String effectsJson){ + public void setEffect(String effectsJson) { effectString = effectsJson; Matcher matcher = Pattern.compile("\\{[^\\n]+?\\}").matcher(effectsJson); - while (matcher.find()){ + while (matcher.find()) { Gson gson = new Gson(); JsonObject jsonObject = JsonParser.parseString(matcher.group()).getAsJsonObject(); - for (String effectName : jsonObject.keySet()){ + for (String effectName : jsonObject.keySet()) { try { ArrayList args = new ArrayList<>(Arrays.asList(gson.fromJson(jsonObject.get(effectName), String[].class))); effects.add(Effect.getEffectClass(effectName).getConstructor(ArrayList.class).newInstance(args)); @@ -99,7 +105,7 @@ public void setEffect(String effectsJson){ } } - public void readEffectFromEffectString(){ + public void readEffectFromEffectString() { setEffect(effectString); } } diff --git a/src/main/java/model/cards/data/MonsterCardData.java b/src/main/java/model/cards/data/MonsterCardData.java index 2f1d220..d2b111d 100644 --- a/src/main/java/model/cards/data/MonsterCardData.java +++ b/src/main/java/model/cards/data/MonsterCardData.java @@ -9,13 +9,18 @@ public class MonsterCardData extends CardData { - @Expose private int level; - - @Expose private MonsterAttribute attribute; - @Expose private String type; - @Expose private String monsterType; - - @Expose private int attackPoints, defencePoints; + @Expose + private int level; + + @Expose + private MonsterAttribute attribute; + @Expose + private String type; + @Expose + private String monsterType; + + @Expose + private int attackPoints, defencePoints; private int changedAttack = 0; private int changedDefence = 0; @@ -71,7 +76,7 @@ public MonsterAttribute getAttribute() { } public int getAttackPoints() { - if(calculatedAttackPoint){ + if (calculatedAttackPoint) { return calculateAttackMethod.get(); } return attackPoints + changedAttack; diff --git a/src/main/java/model/cards/data/ReadMonsterCardsData.java b/src/main/java/model/cards/data/ReadMonsterCardsData.java index 7452c48..8fcc6ed 100644 --- a/src/main/java/model/cards/data/ReadMonsterCardsData.java +++ b/src/main/java/model/cards/data/ReadMonsterCardsData.java @@ -1,7 +1,6 @@ package model.cards.data; import model.enums.MonsterAttribute; -import model.enums.SpellTrapProperty; import java.io.BufferedReader; import java.io.FileReader; @@ -16,7 +15,7 @@ public void readCardsData() { csvReader.readLine(); while ((row = csvReader.readLine()) != null) { String[] data = row.split(","); - if (data.length == 10|| data.length == 11) { + if (data.length == 10 || data.length == 11) { readACardData(data); } else System.out.println("couldn't parse a row from monster.csv file"); } @@ -38,7 +37,7 @@ private void readACardData(String[] rowData) { setMonsterDescription(rowData[7].trim().replaceAll(" comma", ",").replaceAll("\\(nextline\\)", "\n"), monsterCardData); setMonsterPrice(rowData[8].trim(), monsterCardData); setMonsterId(rowData[9].trim(), monsterCardData); - if(rowData.length == 11) monsterCardData.setEffect(rowData[7].replace(" comma", ",").trim()); + if (rowData.length == 11) monsterCardData.setEffect(rowData[7].replace(" comma", ",").trim()); } private void setMonsterName(String name, MonsterCardData monsterCardData) { @@ -117,7 +116,7 @@ private void setMonsterPrice(String price, MonsterCardData monsterCardData) { private void setMonsterId(String id, MonsterCardData monsterCardData) { try { monsterCardData.setId(Integer.parseInt(id)); - }catch (Exception e) { + } catch (Exception e) { System.out.println("setting id failed"); } } diff --git a/src/main/java/model/cards/data/ReadSpellTrapCardsData.java b/src/main/java/model/cards/data/ReadSpellTrapCardsData.java index d529a34..cd20994 100644 --- a/src/main/java/model/cards/data/ReadSpellTrapCardsData.java +++ b/src/main/java/model/cards/data/ReadSpellTrapCardsData.java @@ -33,13 +33,13 @@ public void readACardData(String[] data) { TrapCardData trapCardData = new TrapCardData(); trapCardData = (TrapCardData) setSpellTrapData(data, trapCardData); trapCardData.setLimited(data[4].trim().equals("Limited")); - trapCardData.setTrapProperty(SpellTrapProperty.valueOf(data[2].trim().toUpperCase(Locale.ROOT).replace("-","_"))); - }else if (data[1].equals("Spell")) { + trapCardData.setTrapProperty(SpellTrapProperty.valueOf(data[2].trim().toUpperCase(Locale.ROOT).replace("-", "_"))); + } else if (data[1].equals("Spell")) { SpellCardData spellCardData = new SpellCardData(); spellCardData = (SpellCardData) setSpellTrapData(data, spellCardData); spellCardData.setLimited(data[4].trim().equals("Limited")); - spellCardData.setTrapProperty(SpellTrapProperty.valueOf(data[2].trim().toUpperCase(Locale.ROOT).replace("-","_"))); - }else { + spellCardData.setTrapProperty(SpellTrapProperty.valueOf(data[2].trim().toUpperCase(Locale.ROOT).replace("-", "_"))); + } else { System.out.println("the card type is wrong"); } } @@ -50,8 +50,8 @@ public CardData setSpellTrapData(String[] data, CardData cardData) { cardData.setCardDescription(data[3].replace(" comma", ",").trim()); cardData.setPrice(Integer.parseInt(data[5].trim())); cardData.setId(Integer.parseInt(data[6].trim())); - if(data.length == 8) cardData.setEffect(data[7].replace(" comma", ",").trim()); - }catch (Exception e) { + if (data.length == 8) cardData.setEffect(data[7].replace(" comma", ",").trim()); + } catch (Exception e) { System.out.println(e.getMessage()); } return cardData; diff --git a/src/main/java/model/cards/data/SpellCardData.java b/src/main/java/model/cards/data/SpellCardData.java index 4ab2eed..55dd225 100644 --- a/src/main/java/model/cards/data/SpellCardData.java +++ b/src/main/java/model/cards/data/SpellCardData.java @@ -6,10 +6,12 @@ import java.util.ArrayList; -public class SpellCardData extends CardData{ +public class SpellCardData extends CardData { private static ArrayList allSpellCard = new ArrayList<>(); - @Expose private SpellTrapProperty spellProperty; - @Expose private boolean isLimited; + @Expose + private SpellTrapProperty spellProperty; + @Expose + private boolean isLimited; public SpellCardData() { CardData.addCardData(this); diff --git a/src/main/java/model/cards/data/TrapCardData.java b/src/main/java/model/cards/data/TrapCardData.java index a7b37de..2fdc71e 100644 --- a/src/main/java/model/cards/data/TrapCardData.java +++ b/src/main/java/model/cards/data/TrapCardData.java @@ -6,10 +6,12 @@ import java.util.ArrayList; -public class TrapCardData extends CardData{ +public class TrapCardData extends CardData { private static ArrayList allTraps = new ArrayList<>(); - @Expose private SpellTrapProperty trapProperty; - @Expose private boolean isLimited; + @Expose + private SpellTrapProperty trapProperty; + @Expose + private boolean isLimited; public TrapCardData() { CardData.addCardData(this); diff --git a/src/main/java/model/effectSystem/ContinuousEffect.java b/src/main/java/model/effectSystem/ContinuousEffect.java index 33e0ca5..52e2fde 100644 --- a/src/main/java/model/effectSystem/ContinuousEffect.java +++ b/src/main/java/model/effectSystem/ContinuousEffect.java @@ -4,6 +4,7 @@ public abstract class ContinuousEffect extends Effect { protected boolean isActive = false; + public ContinuousEffect(ArrayList args) { super(args); } diff --git a/src/main/java/model/effectSystem/Effect.java b/src/main/java/model/effectSystem/Effect.java index 35caa7b..51d0123 100644 --- a/src/main/java/model/effectSystem/Effect.java +++ b/src/main/java/model/effectSystem/Effect.java @@ -3,7 +3,6 @@ import controller.gameplay.GameManager; import model.cards.Card; import model.cards.TrapCard; -import model.gameplay.Player; import org.reflections.Reflections; import java.util.ArrayList; @@ -13,12 +12,13 @@ public abstract class Effect { protected static GameManager gameManager; protected Card card; private static Set> allEffects; + static { Reflections r = new Reflections("model.effectSystem.effects"); allEffects = r.getSubTypesOf(Effect.class); } - public static Class getEffectClass(String className){ + public static Class getEffectClass(String className) { return allEffects.stream().filter(c -> c.getSimpleName().equals(className)).findFirst().orElse(null); } @@ -30,11 +30,11 @@ public void setCard(Card card) { this.card = card; } - public void setup(){ + public void setup() { } - protected void trapActivateQuestion(){ + protected void trapActivateQuestion() { if (card.getCardOwner().getTrapBanned() > 0) return; gameManager.temporaryChangeTurn(); gameManager.getScene().log("now it will be " + card.getCardOwner().getUserData().getUsername() + "'s turn"); diff --git a/src/main/java/model/effectSystem/EquipEffect.java b/src/main/java/model/effectSystem/EquipEffect.java index 1b1caf6..6fed36a 100644 --- a/src/main/java/model/effectSystem/EquipEffect.java +++ b/src/main/java/model/effectSystem/EquipEffect.java @@ -1,6 +1,5 @@ package model.effectSystem; -import model.cards.Card; import model.cards.MonsterCard; import model.cards.data.MonsterCardData; diff --git a/src/main/java/model/effectSystem/FieldEffect.java b/src/main/java/model/effectSystem/FieldEffect.java index 4c1864b..2c685c8 100644 --- a/src/main/java/model/effectSystem/FieldEffect.java +++ b/src/main/java/model/effectSystem/FieldEffect.java @@ -1,10 +1,8 @@ package model.effectSystem; -import model.cards.MonsterCard; - import java.util.ArrayList; -public abstract class FieldEffect extends Effect{ +public abstract class FieldEffect extends Effect { public FieldEffect(ArrayList args) { diff --git a/src/main/java/model/effectSystem/effects/BanOpponentFromGetCard.java b/src/main/java/model/effectSystem/effects/BanOpponentFromGetCard.java index 1bcc6d2..cb55db0 100644 --- a/src/main/java/model/effectSystem/effects/BanOpponentFromGetCard.java +++ b/src/main/java/model/effectSystem/effects/BanOpponentFromGetCard.java @@ -1,7 +1,5 @@ package model.effectSystem.effects; -import controller.User; -import model.cards.TrapCard; import model.effectSystem.Effect; import model.gameplay.Player; @@ -10,11 +8,12 @@ public class BanOpponentFromGetCard extends Effect { int bannedTurn; + public BanOpponentFromGetCard(ArrayList args) { super(args); try { bannedTurn = Integer.parseInt(args.get(0).trim()); - }catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); } } @@ -30,12 +29,11 @@ public void setup() { } - - @Override public void activate() { Player player; - if (gameManager.getCurrentTurnPlayer().equals(card.getCardOwner())) player = gameManager.getCurrentTurnOpponentPlayer(); + if (gameManager.getCurrentTurnPlayer().equals(card.getCardOwner())) + player = gameManager.getCurrentTurnOpponentPlayer(); else player = gameManager.getCurrentTurnPlayer(); player.setBannedCardTurn(bannedTurn); } diff --git a/src/main/java/model/effectSystem/effects/BanOpponentTrapUse.java b/src/main/java/model/effectSystem/effects/BanOpponentTrapUse.java index ff64fc3..7c386ec 100644 --- a/src/main/java/model/effectSystem/effects/BanOpponentTrapUse.java +++ b/src/main/java/model/effectSystem/effects/BanOpponentTrapUse.java @@ -13,7 +13,7 @@ public BanOpponentTrapUse(ArrayList args) { @Override public void setup() { super.setup(); - card.getOnDestroyEvent().addListener(()->{ + card.getOnDestroyEvent().addListener(() -> { Player opponentPlayer = getOpponentPlayer(); opponentPlayer.setTrapBanned(opponentPlayer.getTrapBanned() - 1); }); @@ -26,7 +26,8 @@ public void activate() { } private Player getOpponentPlayer() { - if (card.getCardOwner().equals(gameManager.getCurrentTurnPlayer())) return gameManager.getCurrentTurnOpponentPlayer(); + if (card.getCardOwner().equals(gameManager.getCurrentTurnPlayer())) + return gameManager.getCurrentTurnOpponentPlayer(); return gameManager.getCurrentTurnPlayer(); } } diff --git a/src/main/java/model/effectSystem/effects/CancelAttackAndCounterAttack.java b/src/main/java/model/effectSystem/effects/CancelAttackAndCounterAttack.java index 32020b8..e0c5bdf 100644 --- a/src/main/java/model/effectSystem/effects/CancelAttackAndCounterAttack.java +++ b/src/main/java/model/effectSystem/effects/CancelAttackAndCounterAttack.java @@ -1,11 +1,8 @@ package model.effectSystem.effects; -import model.cards.Card; -import model.cards.TrapCard; import model.cards.data.MonsterCardData; import model.effectSystem.Effect; import model.gameplay.AttackResult; -import model.gameplay.Player; import java.util.ArrayList; diff --git a/src/main/java/model/effectSystem/effects/ChangeAllAttackDefenceMonsters.java b/src/main/java/model/effectSystem/effects/ChangeAllAttackDefenceMonsters.java index 55118a1..e821d5a 100644 --- a/src/main/java/model/effectSystem/effects/ChangeAllAttackDefenceMonsters.java +++ b/src/main/java/model/effectSystem/effects/ChangeAllAttackDefenceMonsters.java @@ -8,21 +8,22 @@ import java.util.ArrayList; -public class ChangeAllAttackDefenceMonsters extends FieldEffect{ +public class ChangeAllAttackDefenceMonsters extends FieldEffect { private int changedAttack; private int changedDefence; private ArrayList monsterTypes = new ArrayList<>(); + public ChangeAllAttackDefenceMonsters(ArrayList args) { super(args); try { changedAttack = Integer.parseInt(args.get(0).trim()); changedDefence = Integer.parseInt(args.get(1).trim()); - for(int i=2;i { - if (summonerCard.getCardType().equals(CardType.MONSTER) && summonerCard.getCardOwner().equals(card.getCardOwner())) { + if (summonerCard.getCardType().equals(CardType.MONSTER) && summonerCard.getCardOwner().equals(card.getCardOwner())) { MonsterCardData monsterCardData = (MonsterCardData) summonerCard.getCardData(); changeCardAttackDefence(monsterCardData, 1); } @@ -65,7 +65,7 @@ private void setAllOwnCardsChangedAttackDefence(boolean set) { try { cardSlot = gameManager.getGameBoard().getCardSlot(forOpponent, ZoneType.MONSTER, i); if (!cardSlot.isEmpty()) { - MonsterCardData monsterCardData = (MonsterCardData)cardSlot.getCard().getCardData(); + MonsterCardData monsterCardData = (MonsterCardData) cardSlot.getCard().getCardData(); changeCardAttackDefence(monsterCardData, sign); } } catch (Exception e) { diff --git a/src/main/java/model/effectSystem/effects/ControlAMonster.java b/src/main/java/model/effectSystem/effects/ControlAMonster.java index bc35d83..f25aadf 100644 --- a/src/main/java/model/effectSystem/effects/ControlAMonster.java +++ b/src/main/java/model/effectSystem/effects/ControlAMonster.java @@ -28,7 +28,7 @@ public void activate() { getControlledCard = originalPosition.getCard(); card.getCardOwner().getPlayerBoard().addMonsterCardToZone(getControlledCard); originalPosition.removeCard(); - gameManager.getOnChangeTurn().addListener(()->{ + gameManager.getOnChangeTurn().addListener(() -> { try { card.getCardSlot().removeCard(); originalPosition.setCard(card); diff --git a/src/main/java/model/effectSystem/effects/DecreaseOwnerLPOnAttackAnOpponentMonster.java b/src/main/java/model/effectSystem/effects/DecreaseOwnerLPOnAttackAnOpponentMonster.java index e55185d..233cb13 100644 --- a/src/main/java/model/effectSystem/effects/DecreaseOwnerLPOnAttackAnOpponentMonster.java +++ b/src/main/java/model/effectSystem/effects/DecreaseOwnerLPOnAttackAnOpponentMonster.java @@ -3,9 +3,7 @@ import model.cards.MonsterCard; import model.effectSystem.Effect; import model.enums.CardStatus; -import model.enums.ZoneType; import model.gameplay.AttackResult; -import model.gameplay.CardSlot; import java.util.ArrayList; @@ -17,14 +15,16 @@ public DecreaseOwnerLPOnAttackAnOpponentMonster(ArrayList args) { super(args); amount = Integer.parseInt(args.get(0)); } + @Override - public void setup(){ + public void setup() { super.setup(); ((MonsterCard) card).getOnAttacked().addListener((attackResult) -> { this.attackResult = attackResult; activate(); }); } + @Override public void activate() { if (attackResult.isDestroyCard2()) { diff --git a/src/main/java/model/effectSystem/effects/DestroyAllMonstersOnSummonAMonster.java b/src/main/java/model/effectSystem/effects/DestroyAllMonstersOnSummonAMonster.java index 096432c..e6df63a 100644 --- a/src/main/java/model/effectSystem/effects/DestroyAllMonstersOnSummonAMonster.java +++ b/src/main/java/model/effectSystem/effects/DestroyAllMonstersOnSummonAMonster.java @@ -13,9 +13,9 @@ public DestroyAllMonstersOnSummonAMonster(ArrayList args) { } @Override - public void setup(){ + public void setup() { super.setup(); - gameManager.getOnSummonACard().addListener((summonCard)->{ + gameManager.getOnSummonACard().addListener((summonCard) -> { if (gameManager.getScene().getActivateTrapCommand()) { ((TrapCard) card).onActivate(); } diff --git a/src/main/java/model/effectSystem/effects/DestroyAllOpponentAttackPositionMonster.java b/src/main/java/model/effectSystem/effects/DestroyAllOpponentAttackPositionMonster.java index 6c08f21..da3ea44 100644 --- a/src/main/java/model/effectSystem/effects/DestroyAllOpponentAttackPositionMonster.java +++ b/src/main/java/model/effectSystem/effects/DestroyAllOpponentAttackPositionMonster.java @@ -15,17 +15,16 @@ public DestroyAllOpponentAttackPositionMonster(ArrayList args) { @Override public void activate() { CardSlot cardSlot; - for (int i=1;i<=5;i++){ + for (int i = 1; i <= 5; i++) { try { cardSlot = gameManager.getGameBoard().getCardSlot(true, ZoneType.MONSTER, i); - if(!cardSlot.isEmpty()){ + if (!cardSlot.isEmpty()) { MonsterCard monsterCard = (MonsterCard) cardSlot.getCard(); if (monsterCard.isAttackPosition()) { monsterCard.moveToGraveyard(); } } - } - catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); } } diff --git a/src/main/java/model/effectSystem/effects/DestroyAnOpponentMonsterOnFaceUp.java b/src/main/java/model/effectSystem/effects/DestroyAnOpponentMonsterOnFaceUp.java index 550b0fb..6b5afa0 100644 --- a/src/main/java/model/effectSystem/effects/DestroyAnOpponentMonsterOnFaceUp.java +++ b/src/main/java/model/effectSystem/effects/DestroyAnOpponentMonsterOnFaceUp.java @@ -1,7 +1,5 @@ package model.effectSystem.effects; -import model.cards.MonsterCard; -import model.cards.TrapCard; import model.effectSystem.Effect; import model.enums.ZoneType; import model.gameplay.CardSlot; @@ -10,15 +8,16 @@ public class DestroyAnOpponentMonsterOnFaceUp extends Effect { public int placeOfMonster; + public DestroyAnOpponentMonsterOnFaceUp(ArrayList args) { super(args); } @Override - public void setup(){ + public void setup() { super.setup(); - gameManager.getRotate().addListener((rotateCard)->{ - if(gameManager.getScene().getDestroyingAMonsterCommand()) { + gameManager.getRotate().addListener((rotateCard) -> { + if (gameManager.getScene().getDestroyingAMonsterCommand()) { placeOfMonster = gameManager.getScene().getPlaceOfMonster(); activate(); } @@ -33,8 +32,7 @@ public void activate() { CardSlot graveyard = cardSlot.getCard().getCardOwner().getPlayerBoard().getGraveyard(); graveyard.appendCard(cardSlot.getCard()); cardSlot.removeCard(); - } - catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); } } diff --git a/src/main/java/model/effectSystem/effects/DestroyCardOnFlip.java b/src/main/java/model/effectSystem/effects/DestroyCardOnFlip.java index 44027d1..535a711 100644 --- a/src/main/java/model/effectSystem/effects/DestroyCardOnFlip.java +++ b/src/main/java/model/effectSystem/effects/DestroyCardOnFlip.java @@ -1,7 +1,6 @@ package model.effectSystem.effects; import model.cards.MonsterCard; -import model.cards.TrapCard; import model.cards.data.MonsterCardData; import model.effectSystem.Effect; @@ -27,7 +26,7 @@ public void setup() { gameManager.getOnFlipSummon().addListener((summonCard) -> { if (card.getCardOwner().getTrapBanned() > 0) return; this.summonCard = (MonsterCard) summonCard; - if (((MonsterCardData)summonCard.getCardData()).getAttackPoints() >= minAttack) { + if (((MonsterCardData) summonCard.getCardData()).getAttackPoints() >= minAttack) { trapActivateQuestion(); gameManager.getScene().log("now it will be " + gameManager.getCurrentTurnPlayer().getUserData().getUsername() + "'s turn"); gameManager.getScene().showBoard(gameManager.getGameBoardString()); diff --git a/src/main/java/model/effectSystem/effects/DetermineTheAttackPower.java b/src/main/java/model/effectSystem/effects/DetermineTheAttackPower.java index 0aab06c..21e7a39 100644 --- a/src/main/java/model/effectSystem/effects/DetermineTheAttackPower.java +++ b/src/main/java/model/effectSystem/effects/DetermineTheAttackPower.java @@ -1,15 +1,12 @@ package model.effectSystem.effects; -import model.cards.Card; import model.cards.MonsterCard; import model.cards.data.MonsterCardData; import model.effectSystem.Effect; import model.enums.CardStatus; import model.enums.ZoneType; import model.gameplay.CardSlot; -import model.gameplay.Player; -import java.lang.reflect.Method; import java.util.ArrayList; public class DetermineTheAttackPower extends Effect { diff --git a/src/main/java/model/effectSystem/effects/DrawACardFromDeckOnDestroyAtLeastOneMonster.java b/src/main/java/model/effectSystem/effects/DrawACardFromDeckOnDestroyAtLeastOneMonster.java index 10b03d3..905f708 100644 --- a/src/main/java/model/effectSystem/effects/DrawACardFromDeckOnDestroyAtLeastOneMonster.java +++ b/src/main/java/model/effectSystem/effects/DrawACardFromDeckOnDestroyAtLeastOneMonster.java @@ -9,42 +9,42 @@ public class DrawACardFromDeckOnDestroyAtLeastOneMonster extends ContinuousEffect { AttackResult attackResult; - private boolean isDrawACardPlayer1=false; - private boolean isDrawACardPlayer2=false; + private boolean isDrawACardPlayer1 = false; + private boolean isDrawACardPlayer2 = false; + public DrawACardFromDeckOnDestroyAtLeastOneMonster(ArrayList args) { super(args); } @Override - public void setup(){ + public void setup() { super.setup(); - gameManager.getDestroyAMonster().addListener((attackResult)->{ - this.attackResult=attackResult; - if (this.attackResult.getDestroyMonsterCard1()==1) isDrawACardPlayer1=true; - if (this.attackResult.getDestroyMonsterCard2()==1) isDrawACardPlayer2=true; + gameManager.getDestroyAMonster().addListener((attackResult) -> { + this.attackResult = attackResult; + if (this.attackResult.getDestroyMonsterCard1() == 1) isDrawACardPlayer1 = true; + if (this.attackResult.getDestroyMonsterCard2() == 1) isDrawACardPlayer2 = true; activate(); }); } + @Override public void activate() { - if (isDrawACardPlayer1){ - try { - Card card = gameManager.getGameBoard().getCardSlot(false, ZoneType.DECK, 1).drawTopCard(); - card.getCardOwner().addCardToHand(card); - } - catch (Exception e){ - e.printStackTrace(); - } + if (isDrawACardPlayer1) { + try { + Card card = gameManager.getGameBoard().getCardSlot(false, ZoneType.DECK, 1).drawTopCard(); + card.getCardOwner().addCardToHand(card); + } catch (Exception e) { + e.printStackTrace(); } - if (isDrawACardPlayer2){ - try { - Card card = gameManager.getGameBoard().getCardSlot(true, ZoneType.DECK, 1).drawTopCard(); - card.getCardOwner().addCardToHand(card); - } - catch (Exception e){ - e.printStackTrace(); - } + } + if (isDrawACardPlayer2) { + try { + Card card = gameManager.getGameBoard().getCardSlot(true, ZoneType.DECK, 1).drawTopCard(); + card.getCardOwner().addCardToHand(card); + } catch (Exception e) { + e.printStackTrace(); } + } } } diff --git a/src/main/java/model/effectSystem/effects/DrawSpellTrapCardFromDeck.java b/src/main/java/model/effectSystem/effects/DrawSpellTrapCardFromDeck.java index 715c481..43bad88 100644 --- a/src/main/java/model/effectSystem/effects/DrawSpellTrapCardFromDeck.java +++ b/src/main/java/model/effectSystem/effects/DrawSpellTrapCardFromDeck.java @@ -20,13 +20,13 @@ public DrawSpellTrapCardFromDeck(ArrayList args) { number = Integer.parseInt(args.get(0)); try { cardType = CardType.valueOf(args.get(1)); - }catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); cardType = null; } try { spellProperty = SpellTrapProperty.valueOf(args.get(2)); - }catch (Exception e) { + } catch (Exception e) { spellProperty = null; } } diff --git a/src/main/java/model/effectSystem/effects/EquipAMonsterAttackDefence.java b/src/main/java/model/effectSystem/effects/EquipAMonsterAttackDefence.java index 7f36848..ec016c2 100644 --- a/src/main/java/model/effectSystem/effects/EquipAMonsterAttackDefence.java +++ b/src/main/java/model/effectSystem/effects/EquipAMonsterAttackDefence.java @@ -1,10 +1,7 @@ package model.effectSystem.effects; -import model.cards.Card; -import model.cards.MonsterCard; import model.cards.data.MonsterCardData; import model.effectSystem.EquipEffect; -import model.gameplay.Player; import java.util.ArrayList; @@ -12,11 +9,12 @@ public class EquipAMonsterAttackDefence extends EquipEffect { private int changeAttack; private int changeDefence; ArrayList monsterTypes = new ArrayList<>(); + public EquipAMonsterAttackDefence(ArrayList args) { super(args); changeAttack = Integer.parseInt(args.get(0)); changeDefence = Integer.parseInt(args.get(1)); - for (int i=2; i { - setChangeAttackDefence(-1); + setChangeAttackDefence(-1); }); selectedMonster.getOnDestroyEvent().addListener(() -> { card.moveToGraveyard(); @@ -61,7 +59,7 @@ private boolean hasMonsterWithTheType(MonsterCardData monsterCardData) { } private void setChangeAttackDefence(int sign) { - ((MonsterCardData)selectedMonster.getCardData()).setChangedAttack(sign * changeAttack); - ((MonsterCardData)selectedMonster.getCardData()).setChangedDefence(sign * changeDefence); + ((MonsterCardData) selectedMonster.getCardData()).setChangedAttack(sign * changeAttack); + ((MonsterCardData) selectedMonster.getCardData()).setChangedDefence(sign * changeDefence); } } diff --git a/src/main/java/model/effectSystem/effects/GetCardFromDeck.java b/src/main/java/model/effectSystem/effects/GetCardFromDeck.java index ff8ddcf..005c910 100644 --- a/src/main/java/model/effectSystem/effects/GetCardFromDeck.java +++ b/src/main/java/model/effectSystem/effects/GetCardFromDeck.java @@ -15,7 +15,7 @@ public GetCardFromDeck(ArrayList args) { @Override public void activate() { - for (int i=0; i args) { super(args); } + @Override - public void setup(){ + public void setup() { super.setup(); - int size=card.getCardOwner().getPlayerBoard().getHand().getAllCards().size(); - gameManager.getOnAnSpellActivated().addListener((card1)->{ + int size = card.getCardOwner().getPlayerBoard().getHand().getAllCards().size(); + gameManager.getOnAnSpellActivated().addListener((card1) -> { card.getCardOwner().getPlayerBoard().getHand().getAParticularCard( gameManager.getScene().trowAwayACardFromHand(size)).moveToGraveyard(); - this.card1=card1; + this.card1 = card1; activate(); }); } @Override public void activate() { - SpellCard spellCard=(SpellCard) card1; + SpellCard spellCard = (SpellCard) card1; // not activate if (!spellCard.isActivated()) - card1.moveToGraveyard(); + card1.moveToGraveyard(); } diff --git a/src/main/java/model/effectSystem/effects/IncreaseLPOnSpellActivate.java b/src/main/java/model/effectSystem/effects/IncreaseLPOnSpellActivate.java index 5c9d69a..cfee9da 100644 --- a/src/main/java/model/effectSystem/effects/IncreaseLPOnSpellActivate.java +++ b/src/main/java/model/effectSystem/effects/IncreaseLPOnSpellActivate.java @@ -1,7 +1,6 @@ package model.effectSystem.effects; import model.effectSystem.ContinuousEffect; -import model.effectSystem.Effect; import java.util.ArrayList; @@ -16,8 +15,8 @@ public IncreaseLPOnSpellActivate(ArrayList args) { @Override public void setup() { super.setup(); - gameManager.getOnAnSpellActivated().addListener((card)->{ - if(isActive) card.getCardOwner().increaseLP(amount); + gameManager.getOnAnSpellActivated().addListener((card) -> { + if (isActive) card.getCardOwner().increaseLP(amount); }); } diff --git a/src/main/java/model/effectSystem/effects/OnAttackDestroyAll.java b/src/main/java/model/effectSystem/effects/OnAttackDestroyAll.java index 9071b41..342efe8 100644 --- a/src/main/java/model/effectSystem/effects/OnAttackDestroyAll.java +++ b/src/main/java/model/effectSystem/effects/OnAttackDestroyAll.java @@ -1,7 +1,6 @@ package model.effectSystem.effects; import model.cards.MonsterCard; -import model.cards.TrapCard; import model.effectSystem.Effect; import model.enums.ZoneType; import model.gameplay.CardSlot; diff --git a/src/main/java/model/effectSystem/effects/SummonACardFromGraveyard.java b/src/main/java/model/effectSystem/effects/SummonACardFromGraveyard.java index 424571d..76d5fde 100644 --- a/src/main/java/model/effectSystem/effects/SummonACardFromGraveyard.java +++ b/src/main/java/model/effectSystem/effects/SummonACardFromGraveyard.java @@ -3,7 +3,6 @@ import model.cards.Card; import model.cards.MonsterCard; import model.effectSystem.ContinuousEffect; -import model.gameplay.CardSlot; import java.util.ArrayList; @@ -14,8 +13,8 @@ public SummonACardFromGraveyard(ArrayList args) { @Override public void activate() { - Card card1=card.getCardOwner().getPlayerBoard().getGraveyard().drawParticularMonster(null); - MonsterCard monsterCard=(MonsterCard)card1; + Card card1 = card.getCardOwner().getPlayerBoard().getGraveyard().drawParticularMonster(null); + MonsterCard monsterCard = (MonsterCard) card1; card.getCardOwner().getPlayerBoard().addMonsterCardToZone(card1); monsterCard.onSummon(); } diff --git a/src/main/java/model/event/Event.java b/src/main/java/model/event/Event.java index 8acf4ed..3d8479d 100644 --- a/src/main/java/model/event/Event.java +++ b/src/main/java/model/event/Event.java @@ -5,17 +5,18 @@ public class Event { ArrayList> listeners = new ArrayList<>(); - public void invoke(T arg){ - for(Consumer listener: listeners){ + + public void invoke(T arg) { + for (Consumer listener : listeners) { listener.accept(arg); } } - public void addListener(Consumer listener){ + public void addListener(Consumer listener) { listeners.add(listener); } - public void removeListener(Consumer listener){ + public void removeListener(Consumer listener) { listeners.remove(listener); } } diff --git a/src/main/java/model/event/EventNoParam.java b/src/main/java/model/event/EventNoParam.java index fbc6fe3..b201588 100644 --- a/src/main/java/model/event/EventNoParam.java +++ b/src/main/java/model/event/EventNoParam.java @@ -4,22 +4,23 @@ public class EventNoParam { ArrayList listeners = new ArrayList<>(); - public void invoke(){ - for(func listener: listeners){ + + public void invoke() { + for (func listener : listeners) { listener.call(); } } - public void addListener(func listener){ + public void addListener(func listener) { listeners.add(listener); } - public void removeListener(func listener){ + public void removeListener(func listener) { listeners.remove(listener); } @FunctionalInterface - public interface func{ + public interface func { void call(); } } diff --git a/src/main/java/model/gameplay/AttackResult.java b/src/main/java/model/gameplay/AttackResult.java index 21f3a23..21b1004 100644 --- a/src/main/java/model/gameplay/AttackResult.java +++ b/src/main/java/model/gameplay/AttackResult.java @@ -4,7 +4,6 @@ import model.cards.MonsterCard; import model.enums.CardStatus; import model.enums.CardType; -import model.event.Event; public class AttackResult { //1 for attacker @@ -15,8 +14,8 @@ public class AttackResult { private int player2LPDecrease = 0; private boolean destroyCard1 = false; private boolean destroyCard2 = false; - private int destroyMonsterCard1=0; - private int destroyMonsterCard2=0; + private int destroyMonsterCard1 = 0; + private int destroyMonsterCard2 = 0; private String resultMessage = ""; private Card attacker; diff --git a/src/main/java/model/gameplay/CardSlot.java b/src/main/java/model/gameplay/CardSlot.java index 0ae1d27..b0c0345 100644 --- a/src/main/java/model/gameplay/CardSlot.java +++ b/src/main/java/model/gameplay/CardSlot.java @@ -65,8 +65,8 @@ public Card getCard() { return cards.get(0); } - public Card getAParticularCard(int number){ - return cards.get(number-1); + public Card getAParticularCard(int number) { + return cards.get(number - 1); } public void removeACard(Card card) { diff --git a/src/main/java/model/gameplay/GameBoard.java b/src/main/java/model/gameplay/GameBoard.java index 64b04ac..9f735d1 100644 --- a/src/main/java/model/gameplay/GameBoard.java +++ b/src/main/java/model/gameplay/GameBoard.java @@ -1,8 +1,8 @@ package model.gameplay; import controller.gameplay.GameManager; -import model.enums.ZoneType; import model.Deck; +import model.enums.ZoneType; public class GameBoard { PlayerBoard player1Board, player2Board; @@ -43,10 +43,10 @@ public CardSlot getCardSlot(boolean forOpponent, ZoneType zone, int number) thro case FIELD: return board.getFieldZone(); case MONSTER: - if(number < 1 || number > 5) throw new Exception("number out of bounds"); + if (number < 1 || number > 5) throw new Exception("number out of bounds"); return board.getMonsterZone().get(number - 1); case SPELL_AND_TRAP: - if(number < 1 || number > 5) throw new Exception("number out of bounds"); + if (number < 1 || number > 5) throw new Exception("number out of bounds"); return board.getSpellAndTrapZone().get(number - 1); } return null; diff --git a/src/main/java/model/gameplay/Player.java b/src/main/java/model/gameplay/Player.java index 41520eb..e5c968b 100644 --- a/src/main/java/model/gameplay/Player.java +++ b/src/main/java/model/gameplay/Player.java @@ -123,9 +123,9 @@ public void summonCard(Card card, Integer... args) throws Exception { } ArrayList tributes; - if(args.length < tributeNumber){ + if (args.length < tributeNumber) { tributes = gameManager.getTribute(tributeNumber); - }else { + } else { tributes = new ArrayList<>(Arrays.asList(args)); } for (int n : tributes) { @@ -194,7 +194,7 @@ public AttackResult attack(boolean direct, Card myCard, CardSlot attackTo) throw throw new Exception("action not allowed in this phase"); } MonsterCard monsterCard = (MonsterCard) myCard; - if(monsterCard.isAttackedThisTurn()){ + if (monsterCard.isAttackedThisTurn()) { throw new Exception("this card already attacked"); } @@ -239,7 +239,7 @@ public void activateSpellCard(Card myCard) throws Exception { if (spellCard.isActivated()) { throw new Exception("you have already activated this card"); } - for (Effect effect : myCard.getCardData().getEffects()){ + for (Effect effect : myCard.getCardData().getEffects()) { if (!effect.entryCondition()) throw new Exception("preparations of this spell are not done yet"); } if (spellCard.getData().getSpellProperty() == SpellTrapProperty.FIELD) { @@ -259,9 +259,9 @@ public void activateSpellCard(Card myCard) throws Exception { playerBoard.addSpellTrapCardToZone(myCard); } } - if (((SpellCardData)spellCard.getCardData()).getSpellProperty().equals(SpellTrapProperty.EQUIP)) { + if (((SpellCardData) spellCard.getCardData()).getSpellProperty().equals(SpellTrapProperty.EQUIP)) { Card card = gameManager.getScene().getSelectedMonsterCard((EquipEffect) spellCard.getCardData().getEffects().get(0), this); - for (Effect equipEffect : spellCard.getCardData().getEffects()) { + for (Effect equipEffect : spellCard.getCardData().getEffects()) { ((EquipEffect) equipEffect).setSelectedMonster((MonsterCard) card); } } diff --git a/src/main/java/model/gameplay/PlayerBoard.java b/src/main/java/model/gameplay/PlayerBoard.java index 9506547..caa051f 100644 --- a/src/main/java/model/gameplay/PlayerBoard.java +++ b/src/main/java/model/gameplay/PlayerBoard.java @@ -1,12 +1,12 @@ package model.gameplay; +import model.Deck; import model.cards.Card; import model.cards.data.CardData; import model.enums.CardType; import model.enums.MonsterAttribute; import model.enums.SpellTrapProperty; import model.enums.ZoneType; -import model.Deck; import java.util.ArrayList; import java.util.Collections; diff --git a/src/main/java/view/menus/DeckMenu.java b/src/main/java/view/menus/DeckMenu.java index 5766f2a..7d03dbb 100644 --- a/src/main/java/view/menus/DeckMenu.java +++ b/src/main/java/view/menus/DeckMenu.java @@ -1,8 +1,8 @@ package view.menus; +import controller.ApplicationManger; import controller.DeckController; import controller.User; -import controller.ApplicationManger; import model.cards.data.CardData; import model.exceptions.ParseCommandException; @@ -14,8 +14,8 @@ public class DeckMenu extends Scene { private User activeUser; private DeckController deckController; - public DeckMenu(){ - this.activeUser=ApplicationManger.getLoggedInUser(); + public DeckMenu() { + this.activeUser = ApplicationManger.getLoggedInUser(); deckController = new DeckController(this); } @@ -28,7 +28,7 @@ protected int getUserCommand() { System.out.println("menu navigation is not possible"); return 1; } - if(userInput.equals("menu show-current")){ + if (userInput.equals("menu show-current")) { System.out.println("Deck Menu"); return 1; } @@ -76,14 +76,14 @@ protected int getUserCommand() { return 1; } - matcher=Pattern.compile("deck show --cards").matcher(userInput); - if (matcher.matches()){ + matcher = Pattern.compile("deck show --cards").matcher(userInput); + if (matcher.matches()) { deckController.deckShowCards(); return 1; } matcher = Pattern.compile("deck show ([^\\n]+)").matcher(userInput); - if (matcher.matches()){ + if (matcher.matches()) { try { deckController.showDeck(matcher.group(1)); } catch (ParseCommandException e) { diff --git a/src/main/java/view/menus/GamePlayScene.java b/src/main/java/view/menus/GamePlayScene.java index ee78e06..535a5dc 100644 --- a/src/main/java/view/menus/GamePlayScene.java +++ b/src/main/java/view/menus/GamePlayScene.java @@ -272,13 +272,14 @@ public int getPlaceOfMonsterTransfer() { } return Integer.parseInt(input); } - public int trowAwayACardFromHand(int numberOfCardsInHand){ + + public int trowAwayACardFromHand(int numberOfCardsInHand) { System.out.println("insert number of card in your hand that you want to trow away."); String input = scanner.nextLine(); Matcher matcher; matcher = Pattern.compile("([\\d]+)").matcher(input); - while (!matcher.matches()||Integer.parseInt(matcher.group(1))>numberOfCardsInHand){ - System.out.println("you should insert a number from 1 to"+numberOfCardsInHand); + while (!matcher.matches() || Integer.parseInt(matcher.group(1)) > numberOfCardsInHand) { + System.out.println("you should insert a number from 1 to" + numberOfCardsInHand); input = scanner.nextLine(); matcher = Pattern.compile("([\\d]+)").matcher(input); } diff --git a/src/main/java/view/menus/ScoreboardMenu.java b/src/main/java/view/menus/ScoreboardMenu.java index e3f9837..943e137 100644 --- a/src/main/java/view/menus/ScoreboardMenu.java +++ b/src/main/java/view/menus/ScoreboardMenu.java @@ -4,11 +4,11 @@ import controller.User; import model.UserData; - -import java.util.*; +import java.util.Arrays; +import java.util.Comparator; import java.util.regex.Pattern; -public class ScoreboardMenu extends Scene{ +public class ScoreboardMenu extends Scene { @Override protected int getUserCommand() { @@ -19,15 +19,12 @@ protected int getUserCommand() { } if (Pattern.compile("^scoreboard show$").matcher(userInput).find()) { showScoreboard(); - } - else if (Pattern.compile("^menu show-current$").matcher(userInput).find()) { + } else if (Pattern.compile("^menu show-current$").matcher(userInput).find()) { System.out.println("ScoreBoard Menu"); - } - else if (Pattern.compile("^menu exit$").matcher(userInput).find()) { + } else if (Pattern.compile("^menu exit$").matcher(userInput).find()) { ApplicationManger.goToScene(SceneName.MAIN_MENU, false); return 0; - } - else { + } else { System.out.println("invalid command"); } return 1; diff --git a/src/main/java/view/menus/ShopScene.java b/src/main/java/view/menus/ShopScene.java index 181c9cd..e55ce3b 100644 --- a/src/main/java/view/menus/ShopScene.java +++ b/src/main/java/view/menus/ShopScene.java @@ -1,7 +1,6 @@ package view.menus; import controller.ApplicationManger; -import controller.MainMenuController; import controller.ShopController; import controller.User; import model.cards.data.CardData; @@ -32,8 +31,8 @@ protected int getUserCommand() { System.out.println("menu navigation is not possible"); return 1; } - if(userInput.equals("show my balance")){ - System.out.println("your balance is: "+ activeUser.getUserData().getMoney()); + if (userInput.equals("show my balance")) { + System.out.println("your balance is: " + activeUser.getUserData().getMoney()); return 1; } if ((matcher = Pattern.compile("^card show ([^\n]+)$").matcher(userInput)).find()) { diff --git a/src/test/java/EffectsTest.java b/src/test/java/EffectsTest.java index ddde324..0c83ad1 100644 --- a/src/test/java/EffectsTest.java +++ b/src/test/java/EffectsTest.java @@ -9,7 +9,9 @@ import model.cards.data.ReadSpellTrapCardsData; import model.enums.Phase; import model.gameplay.PlayerBoard; -import org.junit.jupiter.api.*; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import view.menus.GamePlayScene; import java.io.*; @@ -63,12 +65,12 @@ static void beforeAll() { @Test public void checkEffect() throws Exception { GameManager gameManager = sceneController.getGameManager(); - for(int i=0; i<2; i++){ + for (int i = 0; i < 2; i++) { Card card = Card.createCardByName("Fireyarou"); card.setup(gameManager.getCurrentTurnPlayer()); gameManager.getGameBoard().getPlayer1Board().addMonsterCardToZone(card); } - for(int i=0; i<2; i++){ + for (int i = 0; i < 2; i++) { Card card = Card.createCardByName("Fireyarou"); card.setup(gameManager.getCurrentTurnOpponentPlayer()); gameManager.getGameBoard().getPlayer2Board().addMonsterCardToZone(card); diff --git a/src/test/java/GamePlayTest.java b/src/test/java/GamePlayTest.java index 71a4e78..8c7877a 100644 --- a/src/test/java/GamePlayTest.java +++ b/src/test/java/GamePlayTest.java @@ -5,7 +5,9 @@ import model.Deck; import model.cards.data.ReadMonsterCardsData; import model.cards.data.ReadSpellTrapCardsData; -import org.junit.jupiter.api.*; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import view.menus.GamePlayScene; import java.io.*; @@ -45,7 +47,7 @@ static void beforeAll() { } @Test - public void newDuel(){ + public void newDuel() { Integer[] cards1 = {1, 1, 1}; Integer[] cards2 = {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}; diff --git a/src/test/java/controller/DeckControllerTest.java b/src/test/java/controller/DeckControllerTest.java index 022455f..9faea30 100644 --- a/src/test/java/controller/DeckControllerTest.java +++ b/src/test/java/controller/DeckControllerTest.java @@ -1,17 +1,14 @@ package controller; import model.Deck; -import model.cards.data.ReadMonsterCardsData; import model.cards.data.ReadSpellTrapCardsData; import model.exceptions.ParseCommandException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import view.menus.DeckMenu; -import view.menus.ImportScene; import view.menus.ShopScene; import java.io.ByteArrayOutputStream; -import java.io.File; import java.io.PrintStream; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/src/test/java/controller/ImportControllerTest.java b/src/test/java/controller/ImportControllerTest.java index 4b945e2..a866f53 100644 --- a/src/test/java/controller/ImportControllerTest.java +++ b/src/test/java/controller/ImportControllerTest.java @@ -1,7 +1,6 @@ package controller; import model.cards.data.ReadMonsterCardsData; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import view.menus.ImportScene; diff --git a/src/test/java/controller/ProfileControllerTest.java b/src/test/java/controller/ProfileControllerTest.java index c187528..84dd6b6 100644 --- a/src/test/java/controller/ProfileControllerTest.java +++ b/src/test/java/controller/ProfileControllerTest.java @@ -8,8 +8,6 @@ import view.menus.ProfileScene; import java.io.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/src/test/java/controller/RegisterControllerTest.java b/src/test/java/controller/RegisterControllerTest.java index e5d6c0c..b50167c 100644 --- a/src/test/java/controller/RegisterControllerTest.java +++ b/src/test/java/controller/RegisterControllerTest.java @@ -1,6 +1,5 @@ package controller; -import model.UserData; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -8,7 +7,7 @@ import java.io.ByteArrayOutputStream; import java.io.PrintStream; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; class RegisterControllerTest { private static final ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream(); @@ -20,7 +19,7 @@ static void setup() { } @BeforeEach - void setUp() { + void setUp() { outputStreamCaptor.reset(); } diff --git a/src/test/java/controller/ShopControllerTest.java b/src/test/java/controller/ShopControllerTest.java index f927113..a8bab86 100644 --- a/src/test/java/controller/ShopControllerTest.java +++ b/src/test/java/controller/ShopControllerTest.java @@ -14,11 +14,10 @@ public class ShopControllerTest { - private static final ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream(); + private static final ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream(); private static ShopController shopController; private static ShopScene shopScene; - private static User testUser; - + private static User testUser; @BeforeAll @@ -40,7 +39,7 @@ private static void setup() { } @BeforeEach - private void set() { + private void set() { outputStreamCaptor.reset(); } @@ -54,7 +53,7 @@ public void wrongNameBuyTest() { public void notEnoughMoney() { testUser.getUserData().changeMoneyWithoutSave(-100000); shopController.buyCard("Monster Reborn"); - String output = "you have not enough money" + System.lineSeparator() + "your money is " + testUser.getUserData().getMoney()+ " card Price is " + "2500" + System.lineSeparator(); + String output = "you have not enough money" + System.lineSeparator() + "your money is " + testUser.getUserData().getMoney() + " card Price is " + "2500" + System.lineSeparator(); testUser.getUserData().changeMoneyWithoutSave(100000); assertEquals(output, outputStreamCaptor.toString()); } diff --git a/src/test/java/model/CommandParserTest.java b/src/test/java/model/CommandParserTest.java index 106f796..ff05c4f 100644 --- a/src/test/java/model/CommandParserTest.java +++ b/src/test/java/model/CommandParserTest.java @@ -8,7 +8,8 @@ import java.util.HashMap; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; class CommandParserTest {