diff --git a/src/main/java/commands/CommandAddName.java b/src/main/java/commands/CommandAddName.java index 91c5c1e815..37ca7e05fb 100644 --- a/src/main/java/commands/CommandAddName.java +++ b/src/main/java/commands/CommandAddName.java @@ -20,8 +20,7 @@ public void execute(Farmio farmio) throws FarmioException, FarmioFatalException if (name.equals("MENU")) { ui.typeWriter("Keywords cannot be used as a character name.", false); ui.typeWriter("Enter your name:", false); - } - else if (name.length() <= 15 && name.length() > 0 && (name.matches("[a-zA-Z0-9]+") || name.contains("_"))) { + } else if (name.length() <= 15 && name.length() > 0 && (name.matches("[a-zA-Z0-9]+") || name.contains("_"))) { farmio.getFarmer().inputName(name); ui.typeWriter("Welcome Farmer " + name @@ -34,8 +33,7 @@ else if (name.length() <= 15 && name.length() > 0 && (name.matches("[a-zA-Z0-9]+ } else if (name.length() > 15) { ui.typeWriter("Your name can have a maximum of 15 characters.", false); ui.typeWriter("Enter your name:", false); - } - else { + } else { ui.typeWriter("Special Characters are not allowed", false); ui.typeWriter("Enter your name:", false); } diff --git a/src/main/java/commands/CommandCheckObjectives.java b/src/main/java/commands/CommandCheckObjectives.java index 3a450d94ec..c8eb406e92 100644 --- a/src/main/java/commands/CommandCheckObjectives.java +++ b/src/main/java/commands/CommandCheckObjectives.java @@ -14,22 +14,22 @@ public class CommandCheckObjectives extends Command { */ @Override public void execute(Farmio farmio) throws FarmioFatalException { - Level.objectiveResult answer = farmio.getLevel().checkAnswer(farmio); + Level.ObjectiveResult answer = farmio.getLevel().checkAnswer(farmio); farmio.getSimulation().simulate(); //farmio.getUi().typeWriter(farmio.getLevel().getFeedback(farmio), false); // feedbacks List feedback = farmio.getLevel().getFeedback(farmio); - for(String i : feedback){ + for (String i : feedback) { farmio.getUi().typeWriter(i,false); } - if (answer == Level.objectiveResult.NOT_DONE) { + if (answer == Level.ObjectiveResult.NOT_DONE) { farmio.setStage(Farmio.Stage.DAY_END); - } else if (answer == Level.objectiveResult.DONE) { + } else if (answer == Level.ObjectiveResult.DONE) { farmio.setStage(Farmio.Stage.LEVEL_END); - } else if (answer == Level.objectiveResult.FAILED) { + } else if (answer == Level.ObjectiveResult.FAILED) { farmio.setStage(Farmio.Stage.LEVEL_FAILED); - } else if (answer == Level.objectiveResult.INVALID) { + } else if (answer == Level.ObjectiveResult.INVALID) { farmio.setStage(Farmio.Stage.LEVEL_FAILED); } } diff --git a/src/main/java/farmio/Level.java b/src/main/java/farmio/Level.java index a11e71d9ae..293402e240 100644 --- a/src/main/java/farmio/Level.java +++ b/src/main/java/farmio/Level.java @@ -22,8 +22,13 @@ public class Level { private boolean detailedFeedbackProvided = false; - private objectiveResult levelState; + private ObjectiveResult levelState; + /** + * Level Constructor . + * @param object something + * @param name something + */ public Level(JSONObject object, String name) { JSONArray array = (JSONArray) object.get("narratives"); narratives = new ArrayList<>(); @@ -53,14 +58,14 @@ public Level(JSONObject object, String name) { } /** - * Get the narrative of the level + * Get the narrative of the level . * @return the list of narrative */ - public ArrayList getNarratives(){ + public ArrayList getNarratives() { return narratives; } - /** + /** . * Get hint for completing the level * @return the hint */ @@ -69,25 +74,25 @@ public String getHint() { } /** - * Get path for simulation of the level's narrative + * Get path for simulation of the level's narrative. * @return the file path */ - public String getPath(){ + public String getPath() { return filePath; } - public enum objectiveResult { + public enum ObjectiveResult { NOT_DONE, DONE, FAILED, INVALID } - private boolean checkDeadlineExceeded(int currentDay){ + private boolean checkDeadlineExceeded(int currentDay) { return deadline < currentDay; } - private boolean allDone(Farmer farmer){ + private boolean allDone(Farmer farmer) { if (farmer.getLevel() == 1.1) { return farmer.getLocation().equals("Market"); } @@ -100,52 +105,62 @@ private boolean allDone(Farmer farmer){ && (gold >= endGold); } - public objectiveResult checkAnswer(Farmio farmio){ + /** + * Summary . + * @param farmio something + * @return + */ + public ObjectiveResult checkAnswer(Farmio farmio) { if (farmio.getFarmer().isHasfailedCurrentTask()) { farmio.getFarmer().resetTaskFailed(); - return objectiveResult.INVALID; + return ObjectiveResult.INVALID; } Farmer farmer = farmio.getFarmer(); + ObjectiveResult levelState; int day = farmer.getDay(); - if(checkDeadlineExceeded(day)){ - levelState = objectiveResult.FAILED; - } - else { + if (checkDeadlineExceeded(day)) { + levelState = ObjectiveResult.FAILED; + } else { if (allDone(farmer)) { - levelState = objectiveResult.DONE; - } else if (checkDeadlineExceeded(day + 1)){ - levelState = objectiveResult.FAILED; - } - else{ - levelState = objectiveResult.NOT_DONE; + levelState = ObjectiveResult.DONE; + } else if (checkDeadlineExceeded(day + 1)) { + levelState = ObjectiveResult.FAILED; + } else { + levelState = ObjectiveResult.NOT_DONE; } } return levelState; } //need to convert into a listString format - private String checkIncompleteObjectives(Farmer farmer){ + + /** + * Summary. + * @param farmer something + * @return + */ + private String checkIncompleteObjectives(Farmer farmer) { //todo -Level-dependant objective checker String output = ""; int seeds = farmer.wheatFarm.getSeeds(); int wheat = farmer.wheatFarm.getWheat(); int grain = farmer.wheatFarm.getGrain(); - if(seeds != endSeeds){ + if (seeds != endSeeds) { int balancedWheatSeed = endSeeds - seeds; output += " Seeds left :" + balancedWheatSeed; - } - else { + } else { output += " Seeds Completed"; } - if(wheat != endWheat){ + + if (wheat != endWheat) { int balancedWheatGreen = endWheat - wheat; output += " | Wheat left :" + balancedWheatGreen; - } - else { + } else { output += " | Wheat Completed"; } - if(grain != endGrain){ + + if (grain != endGrain) { int balancedWheatRipe = endGrain - grain; output += " | Grain left :" + balancedWheatRipe; } else { @@ -155,31 +170,39 @@ private String checkIncompleteObjectives(Farmer farmer){ return output; } - //need to rename this lol - public List convertStringToList(String modelAnswer){ + /** + * summary. + * @param modelAnswer something + * @return + */ + public List convertStringToList(String modelAnswer) { + //todo build a much more comprehensive parser for level String[] taskItems = modelAnswer.split("|"); - List modelTaskList =new ArrayList(Arrays.asList(taskItems)); + List modelTaskList = new ArrayList(Arrays.asList(taskItems)); return modelTaskList; } //todo- logical error correction - public List convertTaskListFormat(List TaskList){ + /** + * Summary. + * @param taskList something + * @return + */ + public List convertTaskListFormat(List taskList) { List splitTaskList = new ArrayList(); - for(String TaskListItems: TaskList) - { - //removed numbering - String removedNumbering = TaskListItems.substring(TaskListItems.indexOf(".")+1); + for (String taskListItems: taskList) { + String removedNumbering = taskListItems.substring(taskListItems.indexOf(".") + 1); removedNumbering.trim();// removed the numbering //separate based on actions - todo check how its divided - //String[] splitString = TaskListItems.split("\\s+"); - String[] splitString = TaskListItems.split("(? userTaskList, String modelAnswer){ */ //todo complete getPermutation Feedback Implementation - public String getPermutationFeedback(Farmio farmio,double levelNumber){ + + /** + * Something. + * @param farmio something + * @param levelNumber something + * @return + */ + public String getPermutationFeedback(Farmio farmio,double levelNumber) { //todo convert to some sort of metric for future iterations List userTaskList = farmio.getFarmer().tasks.toStringArray(); List modelTaskList = convertStringToList(modelAnswer); List modifieduserTaskList = convertTaskListFormat(userTaskList); - if(levelNumber == 1.4){ - for(int i = 0 ; i < userTaskList.size(); i++){ + if (levelNumber == 1.4) { + for (int i = 0; i < userTaskList.size(); i++) { //action checker String[] userTaskString = userTaskList.get(i).split("\\s+"); String[] modelTaskString = modelTaskList.get(i).split("\\s+"); @@ -218,15 +248,19 @@ public String getPermutationFeedback(Farmio farmio,double levelNumber){ } } - - //return levelParser(userTaskList, modelAnswer); return "getPermutation Feedback"; -} + } //only applicable if level fails //todo convert detailed feedback to List - public String getDetailedFeedback( Farmio farmio){ + + /** + * Summary. + * @param farmio something + * @return + */ + public String getDetailedFeedback(Farmio farmio) { double levelNumber = farmio.getFarmer().getLevel(); // unsure if this is needed rn String output = ""; output += " The objective of this level was to " + objective; @@ -242,65 +276,68 @@ public String getDetailedFeedback( Farmio farmio){ return output; } - public List getSuccessfulFeedback(){ + /** + * Summary. + * @return something + */ + public List getSuccessfulFeedback() { List output = new ArrayList(); //String output = ""; - for(String x: successfulFeedback){ + for (String x: successfulFeedback) { output.add(x); } return output; } + /** + * Summary. + * @param farmio something + * @return + */ - public List getFeedback(Farmio farmio){ + public List getFeedback(Farmio farmio) { Farmer farmer = farmio.getFarmer(); - objectiveResult currentLevelState = farmio.getLevel().getLevelState(); + ObjectiveResult currentLevelState = farmio.getLevel().getLevelState(); List output = new ArrayList(); - if(currentLevelState == objectiveResult.DONE){ + if (currentLevelState == ObjectiveResult.DONE) { output.addAll(getSuccessfulFeedback()); output.add("well done you have completed the level - all tasks has been completed succesfully"); return output; - } - - else if(currentLevelState == objectiveResult.NOT_DONE){ //day completed but tasks not achieved succesfult + } else if (currentLevelState == ObjectiveResult.NOT_DONE) { //day completed but tasks not achieved succesfult String feedback = "tasks have yet to be completed"; output.add(feedback); - if(detailedFeedbackProvided){ + if (detailedFeedbackProvided) { //add enter and day end feedback += "detailed feedback : -- \n"; feedback += checkIncompleteObjectives(farmer); } output.add("\n Press [ENTER] to continue the game or [RESET] to restart the level"); return output; - } - - else if (currentLevelState == objectiveResult.FAILED){ + } else if (currentLevelState == ObjectiveResult.FAILED) { String feedback = "Oh no! The objectives were not met by the deadline! Level failed ! \n"; output.add(feedback); - if(detailedFeedbackProvided){ - //todo -redo this code - feedback += getDetailedFeedback(farmio); // only applicable for failed levels + if (detailedFeedbackProvided) { //todo -redo this code + // feedback += getDetailedFeedback(farmio); // only applicable for failed levels } return output; - } - else if (currentLevelState == objectiveResult.INVALID){ - output.add("Oh no! There has been an error during code execution!") ; + } else if (currentLevelState == ObjectiveResult.INVALID) { + output.add("Oh no! There has been an error during code execution!"); return output; } return output; } - public objectiveResult getLevelState(){ + public ObjectiveResult getLevelState() { return levelState; } /** - * Get the list of goals to be completed + * Get the list of goals to be completed. * @return the list of goals */ - public Map getGoals() { - Map goals = new HashMap< String,Integer>(); + public Map getGoals() { + Map goals = new HashMap(); goals.put("Gold", endGold); goals.put("Seeds", endSeeds); goals.put("Seedlings", endSeedlings); @@ -310,7 +347,7 @@ public Map getGoals() { } /** - * Get the main objective of the level + * Get the main objective of the level. * @return the objective of the level */ public String getObjective() { diff --git a/src/main/java/usercode/conditions/BooleanCondition.java b/src/main/java/usercode/conditions/BooleanCondition.java index 4df68f4e99..51b6d088f3 100644 --- a/src/main/java/usercode/conditions/BooleanCondition.java +++ b/src/main/java/usercode/conditions/BooleanCondition.java @@ -10,7 +10,7 @@ public class BooleanCondition extends Condition { private BooleanConditionType type; - public BooleanCondition (BooleanConditionType conditionType) { + public BooleanCondition(BooleanConditionType conditionType) { super(Type.BOOLEAN); this.type = conditionType; } @@ -27,7 +27,7 @@ public JSONObject toJson() { return object; } - public String toString () { + public String toString() { return type.name(); } diff --git a/src/main/java/usercode/conditions/ConditionChecker.java b/src/main/java/usercode/conditions/ConditionChecker.java index 522bdbe40a..f70392cccb 100644 --- a/src/main/java/usercode/conditions/ConditionChecker.java +++ b/src/main/java/usercode/conditions/ConditionChecker.java @@ -8,19 +8,23 @@ public class ConditionChecker { public ConditionChecker() { } + /** + * Checks the condition. + * @param condition something + * @param farmio something + * @return + */ public static boolean check(BooleanConditionType condition, Farmio farmio) { if (condition == BooleanConditionType.hasSeeds) { return farmio.getFarmer().getWheatFarm().hasSeeds(); } if (condition == BooleanConditionType.hasWheat) { - return farmio.getFarmer().getWheatFarm().hasWheat() ; + return farmio.getFarmer().getWheatFarm().hasWheat(); } - if (condition == BooleanConditionType.hasGrain) - { + if (condition == BooleanConditionType.hasGrain) { return farmio.getFarmer().getWheatFarm().hasGrain(); } - if (condition == BooleanConditionType.hasGold) - { + if (condition == BooleanConditionType.hasGold) { return farmio.getFarmer().hasGold(); } if (condition == BooleanConditionType.TRUE) { @@ -29,24 +33,37 @@ public static boolean check(BooleanConditionType condition, Farmio farmio) { return false; } - public static boolean check(ValueConditionType valueConditionType, Comparator comparator, int val, Farmio farmio) throws FarmioException { + /** + * Something. + * @param valueConditionType something + * @param comparator something + * @param val something + * @param farmio something + * @return + * @throws FarmioException something + */ + public static boolean check(ValueConditionType valueConditionType, Comparator comparator, int val, Farmio farmio) { + //throws FarmioException { int assetValue = 0; switch (valueConditionType) { - case gold: - assetValue = farmio.getFarmer().getGold(); - break; + case gold: + assetValue = farmio.getFarmer().getGold(); + break; + default: } switch (comparator) { - case lessThan: - return assetValue < val; - case lessThanOrEquals: - return assetValue <= val; - case greaterThan: - return assetValue > val; - case greaterThanOrEquals: - return assetValue >= val; + case lessThan: + return assetValue < val; + case lessThanOrEquals: + return assetValue <= val; + case greaterThan: + return assetValue > val; + case greaterThanOrEquals: + return assetValue >= val; + default: + return false; //not sure what the default should be } - throw new FarmioException("Error validating condition!"); + //throw new FarmioException("Error validating condition!"); } } diff --git a/src/main/java/usercode/conditions/ValueCondition.java b/src/main/java/usercode/conditions/ValueCondition.java index b5fd1178db..7708318524 100644 --- a/src/main/java/usercode/conditions/ValueCondition.java +++ b/src/main/java/usercode/conditions/ValueCondition.java @@ -15,6 +15,12 @@ public class ValueCondition extends Condition { private Comparator comparator; private int value; + /** + * ValueCondition Summary. + * @param type something + * @param comparator something + * @param value something + */ public ValueCondition(ValueConditionType type, Comparator comparator, int value) { super(Type.VALUE); this.type = type; @@ -36,21 +42,22 @@ public JSONObject toJson() { return object; } - public String toString () { + public String toString() { return type.name() + " " + comparatorToString() + " " + Integer.toString(value); } private String comparatorToString() { switch (comparator) { - case greaterThanOrEquals: - return ">="; - case greaterThan: - return ">"; - case lessThan: - return "<"; - case lessThanOrEquals: - return "<="; + case greaterThanOrEquals: + return ">="; + case greaterThan: + return ">"; + case lessThan: + return "<"; + case lessThanOrEquals: + return "<="; + default: + return ""; } - return ""; } }