diff --git a/src/main/java/InteractableEntity/InteractableEntity.java b/src/main/java/InteractableEntity/InteractableEntity.java index ec045e0740..a675bfef13 100644 --- a/src/main/java/InteractableEntity/InteractableEntity.java +++ b/src/main/java/InteractableEntity/InteractableEntity.java @@ -1,6 +1,12 @@ package InteractableEntity; public abstract class InteractableEntity { + protected String name; + public abstract int getHealth(); + + public abstract int getDefence(); + + public abstract int getDamage(); } diff --git a/src/main/java/Math/MathPool.java b/src/main/java/Math/MathPool.java index 569e083634..37e2859b08 100644 --- a/src/main/java/Math/MathPool.java +++ b/src/main/java/Math/MathPool.java @@ -1,4 +1,5 @@ package Math; + import java.util.Random; import java.util.ArrayList; @@ -7,16 +8,17 @@ public class MathPool { private final Random random; - public MathPool(){ + public MathPool() { + poolOfQuestions = new ArrayList(); random = new Random(); } - public void addMathQuestion(String wordProblem, int solution, int difficulty){ + public void addMathQuestion(String wordProblem, int solution, int difficulty) { MathQuestion problem = new MathQuestion(wordProblem, solution, difficulty); poolOfQuestions.add(problem); } - public MathQuestion getQuestionByDifficulty(int targetDifficulty){ + public MathQuestion getQuestionByDifficulty(int targetDifficulty) { ArrayList filteredQuestions = new ArrayList<>(); for (MathQuestion question : poolOfQuestions) { if (question.getDifficulty() == targetDifficulty) { @@ -31,4 +33,11 @@ public MathQuestion getQuestionByDifficulty(int targetDifficulty){ } } + public void init() { + addMathQuestion("1 + 1 = ", 2, 0); + addMathQuestion("1 + 2 = ", 3, 0); + addMathQuestion("3 + 1 = ", 4, 0); + addMathQuestion("2 + 5 = ", 7, 0); + addMathQuestion("10 + 23 = ", 33, 0); + } } diff --git a/src/main/java/Math/MathQuestion.java b/src/main/java/Math/MathQuestion.java index cbdd24a27f..f12249f7d6 100644 --- a/src/main/java/Math/MathQuestion.java +++ b/src/main/java/Math/MathQuestion.java @@ -1,9 +1,9 @@ package Math; public class MathQuestion { - private String question; - private int answer; - private int difficulty; + private final String question; + private final int answer; + private final int difficulty; public MathQuestion(String qn, int ans, int diff){ this.question = qn; diff --git a/src/main/java/command/Command.java b/src/main/java/command/Command.java index f40526bd6d..39c8def0f9 100644 --- a/src/main/java/command/Command.java +++ b/src/main/java/command/Command.java @@ -3,6 +3,8 @@ import textbox.*; import map.AMap; +import java.util.Scanner; + public abstract class Command { protected TextBox textBox; @@ -11,6 +13,9 @@ public abstract class Command { protected AMap currentMap; public abstract void execute(); + public void execute(Scanner in){ + + } public Command() { commandDescription = "Impossible"; diff --git a/src/main/java/command/fight/FightingCommand.java b/src/main/java/command/fight/FightingCommand.java index dcba32e646..ee38d66dcb 100644 --- a/src/main/java/command/fight/FightingCommand.java +++ b/src/main/java/command/fight/FightingCommand.java @@ -1,6 +1,8 @@ package command.fight; import command.Command; +import java.util.Scanner; + public class FightingCommand extends Command { public FightingCommand() { @@ -11,4 +13,9 @@ public FightingCommand() { public void execute() { } + + @Override + public void execute(Scanner in) { + currentMap.fightLoop(in); + } } diff --git a/src/main/java/command/fight/RunningCommand.java b/src/main/java/command/fight/RunningCommand.java index 83bcac6a87..6ad0134bbd 100644 --- a/src/main/java/command/fight/RunningCommand.java +++ b/src/main/java/command/fight/RunningCommand.java @@ -11,11 +11,7 @@ public RunningCommand() { @Override public void execute(){ if(currentMap instanceof BattleInterface) { - AMap initMap = new FirstMap(); - initMap.initMap(30, 10); - initMap.initPlayerLocation(0, 0); - initMap.placeMonsterInTheMap(2, 3); - currentMap = initMap; + } } } diff --git a/src/main/java/command/mapmove/MapMoveCommand.java b/src/main/java/command/mapmove/MapMoveCommand.java index 622325e850..99d80e77f2 100644 --- a/src/main/java/command/mapmove/MapMoveCommand.java +++ b/src/main/java/command/mapmove/MapMoveCommand.java @@ -4,14 +4,16 @@ public abstract class MapMoveCommand extends Command { protected int commandModifier; - public MapMoveCommand(){ + + public MapMoveCommand() { } + public MapMoveCommand(String userInput) { commandDescription = "MapMove"; userInput = userInput.trim(); String[] splitUserInput = userInput.split("\\h+"); - if(splitUserInput.length == 1){ + if (splitUserInput.length == 1) { commandModifier = 1; } else { commandModifier = Integer.parseInt(splitUserInput[1]); diff --git a/src/main/java/command/mapmove/MovingDownwardCommand.java b/src/main/java/command/mapmove/MovingDownwardCommand.java index a9cd67db7a..aa2dc900b2 100644 --- a/src/main/java/command/mapmove/MovingDownwardCommand.java +++ b/src/main/java/command/mapmove/MovingDownwardCommand.java @@ -1,6 +1,5 @@ package command.mapmove; - public class MovingDownwardCommand extends MapMoveCommand { public MovingDownwardCommand(String userInput) { super(userInput); diff --git a/src/main/java/command/mapmove/MovingRightCommand.java b/src/main/java/command/mapmove/MovingRightCommand.java index 2610a64404..b9f9322eff 100644 --- a/src/main/java/command/mapmove/MovingRightCommand.java +++ b/src/main/java/command/mapmove/MovingRightCommand.java @@ -2,10 +2,6 @@ public class MovingRightCommand extends MapMoveCommand { - public MovingRightCommand() { - super(); - } - public MovingRightCommand(String userInput) { super(userInput); } diff --git a/src/main/java/main/CalculaChroniclesOfTheAlgorithmicKingdom.java b/src/main/java/main/CalculaChroniclesOfTheAlgorithmicKingdom.java index 4804972df5..a82172d20c 100644 --- a/src/main/java/main/CalculaChroniclesOfTheAlgorithmicKingdom.java +++ b/src/main/java/main/CalculaChroniclesOfTheAlgorithmicKingdom.java @@ -1,14 +1,17 @@ package main; import command.Command; +import command.fight.FightingCommand; import command.mapmove.MapMoveCommand; import map.*; import parser.Parser; import textbox.PlayerStatus; import textbox.TextBox; import ui.Ui; +import Math.*; import java.util.Map; +import java.util.Scanner; public class CalculaChroniclesOfTheAlgorithmicKingdom { @@ -17,6 +20,7 @@ public static void main(String[] args) { } public void startGame() { + Scanner in = new Scanner(System.in); PlayerStatus playerStatus = new PlayerStatus(100, 0, 0); TextBox textBox = new TextBox(); Parser parser = new Parser(); @@ -27,6 +31,7 @@ public void startGame() { map.initPlayerLocation(0, 0); map.placeMonsterInTheMap(2, 3); textBox.initTextBox(); + map.addMaps(map); ui.printPlayerStatus(playerStatus); ui.printMap(map); @@ -34,21 +39,26 @@ public void startGame() { Command userCommand; while (true) { - String userCommandText = parser.readInCommand(); + String userCommandText = in.nextLine(); + userCommand = parser.parseCommand(userCommandText); setUserCommand(userCommand, map, playerStatus, textBox); if (!(map instanceof FirstMap) && userCommand instanceof MapMoveCommand) { System.out.println("Invalid Command"); + } else if (userCommand.getCommandDescription().equals("FIGHT!")){ + userCommand.execute(in); } else { userCommand.execute(); } - + map.storeMaps(0, map); map = userCommand.getCurrentMap(); + if (!userCommand.getCommandDescription().equals("HelpMe!!")) { ui.printPlayerStatus(playerStatus); ui.printMap(map); } + } } diff --git a/src/main/java/map/AMap.java b/src/main/java/map/AMap.java index cdf702d4c4..b04a53fe4e 100644 --- a/src/main/java/map/AMap.java +++ b/src/main/java/map/AMap.java @@ -1,16 +1,24 @@ package map; import java.util.ArrayList; +import java.util.Scanner; public abstract class AMap { - protected static ArrayList storedMap; + protected static ArrayList storedMaps = new ArrayList<>(); protected int width; protected int height; protected ArrayList> currentMap; protected int playerX; protected int playerY; protected String mapName; + public AMap(){ + } + + public abstract void fightLoop(); + public void fightLoop(Scanner in){ + + } public void initMap(int givenWidth, int givenHeight) { this.width = givenWidth; @@ -121,5 +129,11 @@ public int getPlayerX() { public int getPlayerY() { return playerY; } + public void storeMaps(int index, AMap map){ + storedMaps.set(index, map); + } + public void addMaps(AMap map){ + storedMaps.add(map); + } } diff --git a/src/main/java/map/BattleInterface/BattleInterface.java b/src/main/java/map/BattleInterface/BattleInterface.java index e9e473b570..37cc4035d3 100644 --- a/src/main/java/map/BattleInterface/BattleInterface.java +++ b/src/main/java/map/BattleInterface/BattleInterface.java @@ -8,9 +8,11 @@ import textbox.PlayerStatus; import textbox.TextBox; import ui.Ui; +import Math.*; import java.lang.management.PlatformLoggingMXBean; import java.util.ArrayList; +import java.util.Scanner; public class BattleInterface extends AMap { protected PlayerStatus currentPlayer; @@ -25,6 +27,31 @@ public BattleInterface(PlayerStatus player, TextBox text, InteractableEntity ent } + @Override + public void fightLoop() { + + } + + @Override + public void fightLoop(Scanner in) { + MathPool mathPool = new MathPool(); + mathPool.init(); + Ui ui = new Ui(); + + while (currentPlayer.getPlayerHealth() > 0 && currentEntity.getHealth() > 0) { + ui.printPlayerStatus(currentPlayer); + ui.printMap(currentMap); + MathQuestion mathQuestion = mathPool.getQuestionByDifficulty(0); + ui.printQuestion(mathQuestion); + int answer = Integer.parseInt(in.nextLine().trim()); + if (mathQuestion.checkAns(answer)) { + playerHitEnemy(); + } else { + enemyHitPlayer(); + } + } + } + public void initMap(int givenWidth, int givenHeight) { this.width = givenWidth; this.height = givenHeight; @@ -51,26 +78,26 @@ public void initMap(int givenWidth, int givenHeight) { } - public void playerHitEnemy(){ - if (currentEntity instanceof Enemy){ - int dmgDone = 10 - (10 * ((Enemy) currentEntity).getDefence()); + public void playerHitEnemy() { + if (currentEntity instanceof Enemy) { + int dmgDone = 10; ((Enemy) currentEntity).harmHealth(dmgDone); } } - public void enemyHitPlayer(){ - if (currentEntity instanceof Enemy){ + public void enemyHitPlayer() { + if (currentEntity instanceof Enemy) { int dmgDone = ((Enemy) currentEntity).getDamage(); currentPlayer.harmHealth(dmgDone); } } - public InteractableEntity getCurrentEntity(){ + public InteractableEntity getCurrentEntity() { return currentEntity; } - public PlayerStatus getCurrentPlayer(){ + public PlayerStatus getCurrentPlayer() { return currentPlayer; } diff --git a/src/main/java/map/FirstMap.java b/src/main/java/map/FirstMap.java index 9a3f37c4f8..42f5303c73 100644 --- a/src/main/java/map/FirstMap.java +++ b/src/main/java/map/FirstMap.java @@ -2,4 +2,9 @@ public class FirstMap extends AMap{ protected String DIFFICULTY_MODIFIER = "easy"; //can use to determine question difficulty + + @Override + public void fightLoop() { + System.out.println("lol"); + } } diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java index d4a1d04eaa..45f4ff1953 100644 --- a/src/main/java/parser/Parser.java +++ b/src/main/java/parser/Parser.java @@ -12,11 +12,6 @@ public class Parser { - public String readInCommand() { - Scanner in = new Scanner(System.in); - return in.nextLine(); - } - public CommandType analyseCommand(String userCommand) { Pattern pattern; Matcher matcher; diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index 02d0cd3795..94af52b0b1 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -4,7 +4,7 @@ import map.AMap; import textbox.PlayerStatus; import textbox.TextBox; - +import Math.*; import java.util.ArrayList; public class Ui { @@ -33,7 +33,16 @@ public void printTextBox(TextBox box) { } printDividingLine(); } - + public void printMap(ArrayList> map) { + printDividingLine(); + for (ArrayList row : map) { + for (char cell : row) { + System.out.print(cell + " "); + } + System.out.println(); + } + printDividingLine(); + } public void printMap(AMap map) { printDividingLine(); for (ArrayList row : map.getCurrentMap()) { @@ -53,4 +62,7 @@ public void printHelpMenu() { System.out.println("'run' to escape the battle interface"); printDividingLine(); } + public void printQuestion(MathQuestion mathQuestion){ + System.out.println(mathQuestion.getQuestion()); + } }