diff --git a/src/com/company/Models/Battle/Battle.java b/src/com/company/Models/Battle/Battle.java index 487f3b1..0584ffa 100644 --- a/src/com/company/Models/Battle/Battle.java +++ b/src/com/company/Models/Battle/Battle.java @@ -59,7 +59,7 @@ public Battle(int storyLevel, int flags) { beginTimer(); this.turnToPlay = players[0]; players[0] = new Player(Account.getLoggedInAccount()); - players[1] = getBotPlayer(); + players[1] = getBotPlayer(mode); players[0].getDeck().getDeckController().initializeHand(); players[1].getDeck().getDeckController().initializeHand(); this.turnToPlay = players[0]; @@ -73,6 +73,27 @@ public Battle(int storyLevel, int flags) { System.out.println(map.toString()); } + public Battle(Mode mode, int flags) { + this.map = new Map(); + initFlagMode(); + botIsActive = true; + beginTimer(); + this.turnToPlay = players[0]; + players[0] = new Player(Account.getLoggedInAccount()); + players[1] = getBotPlayer(mode); + players[0].getDeck().getDeckController().initializeHand(); + players[1].getDeck().getDeckController().initializeHand(); + this.turnToPlay = players[0]; + this.battleType = BattleType.STORY; + mode.setBattle(this); + this.winningPrize = 1500; + playingBattle = this; +// initPlayersHand(players[1]); + initHeroes(); + initCardsHealth(); + System.out.println(map.toString()); + } + private void setModeByStoryLevel(int storyLevel, int flagsNum) { switch (storyLevel) { case 1: @@ -219,7 +240,7 @@ public int getTimePassedInSeconds() { return timePassedInSeconds; } - public Player getBotPlayer() { + public static Player getBotPlayer(Mode mode) { Player player = new Player(); player.setName("BOT"); switch (mode) { diff --git a/src/com/company/Views/ConsoleInput.java b/src/com/company/Views/ConsoleInput.java index 41e3eb7..4ed1379 100644 --- a/src/com/company/Views/ConsoleInput.java +++ b/src/com/company/Views/ConsoleInput.java @@ -24,6 +24,7 @@ public class ConsoleInput { public static final String SELL_CARD_REGEX = "sell (?\\d+)"; + public static final String CREATE_ACCOUNT_REGEX = "create account \\w+"; private static Scanner scanner = new Scanner(System.in); public enum Menu {MAIN, ACCOUNT, COLLECTION, SHOP, NEW_BATTLE, BATTLE, GRAVEYARD, EXIT} @@ -171,7 +172,7 @@ public static void collectionMenuCommandsChecker(String command) { } public static void accountMenuCommandsChecker(String command) { - if (command.matches("create account \\w+")) { + if (command.matches(CREATE_ACCOUNT_REGEX)) { Matcher usernameMatcher = Pattern.compile("create account (?\\w+)").matcher(command); if (usernameMatcher.find()) { command = scanner.nextLine(); @@ -295,8 +296,10 @@ public static void battleMenuCommandsChecker(String command) { setMenu(Menu.GRAVEYARD); } else if (command.matches("help")) { BattleView.printBattleCommandsToHelp(); - }else if (command.matches("show map")) { + } else if (command.matches("show map")) { ConsoleOutput.printMessage(Battle.getPlayingBattle().getMap().toString()); + } else if (command.matches("exit")) { + setMenu(Menu.NEW_BATTLE); } } @@ -347,17 +350,27 @@ private static void newBattleMenuCommandsChecker(String command) { Integer.valueOf(multiPlayerMatcher.group("flags")) ); setMenu(Menu.BATTLE); - } else if (command.matches("start game \\w+ \\S+")) { - Matcher multiPlayerMatcher = Pattern.compile("start game (?\\w+) (?\\S+) (?\\S+)").matcher(command); + } else if (command.matches("start custom game \\w+ \\S+")) { + Matcher multiPlayerMatcher = Pattern.compile("start game (?\\w+) (?\\S+)").matcher(command); multiPlayerMatcher.find(); Account.getLoggedInAccount().setMainDeck(Collection.getDeckByName(multiPlayerMatcher.group("deckName"))); + Mode mode = Enum.valueOf(Mode.class, multiPlayerMatcher.group("mode")); new Battle( - Enum.valueOf(Mode.class, multiPlayerMatcher.group("mode")), - Account.getAccountByUsername(multiPlayerMatcher.group("opponent")), + mode, 0 ); setMenu(Menu.BATTLE); - } else if (command.matches("exit")) { + } else if (command.matches("start custom game \\w+ \\S+ \\d+")) { + Matcher multiPlayerMatcher = Pattern.compile("start game (?\\w+) (?\\S+) (?\\d+)").matcher(command); + multiPlayerMatcher.find(); + Account.getLoggedInAccount().setMainDeck(Collection.getDeckByName(multiPlayerMatcher.group("deckName"))); + Mode mode = Enum.valueOf(Mode.class, multiPlayerMatcher.group("mode")); + new Battle( + mode, + Integer.valueOf(multiPlayerMatcher.group("flags")) + ); + setMenu(Menu.BATTLE); + } else if (command.matches("exit")) { setMenu(Menu.MAIN); } }