Skip to content

Commit

Permalink
console input updated
Browse files Browse the repository at this point in the history
  • Loading branch information
hamidrezash2000 committed May 7, 2019
1 parent 380f30a commit ba9d3c5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
25 changes: 23 additions & 2 deletions src/com/company/Models/Battle/Battle.java
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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:
Expand Down Expand Up @@ -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) {
Expand Down
27 changes: 20 additions & 7 deletions src/com/company/Views/ConsoleInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

public class ConsoleInput {
public static final String SELL_CARD_REGEX = "sell (?<cardId>\\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}
Expand Down Expand Up @@ -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 (?<username>\\w+)").matcher(command);
if (usernameMatcher.find()) {
command = scanner.nextLine();
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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 (?<deckName>\\w+) (?<mode>\\S+) (?<opponent>\\S+)").matcher(command);
} else if (command.matches("start custom game \\w+ \\S+")) {
Matcher multiPlayerMatcher = Pattern.compile("start game (?<deckName>\\w+) (?<mode>\\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 (?<deckName>\\w+) (?<mode>\\S+) (?<flags>\\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);
}
}
Expand Down

0 comments on commit ba9d3c5

Please sign in to comment.