Skip to content

Commit

Permalink
Updated in game menu
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnTYH committed Oct 30, 2019
2 parents ae54400 + 6900694 commit f044f84
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 110 deletions.
6 changes: 2 additions & 4 deletions src/main/java/commands/CommandAddName.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/commands/CommandCheckObjectives.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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);
}
}
Expand Down
177 changes: 107 additions & 70 deletions src/main/java/farmio/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<>();
Expand Down Expand Up @@ -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<String> getNarratives(){
public ArrayList<String> getNarratives() {
return narratives;
}

/**
/** .
* Get hint for completing the level
* @return the hint
*/
Expand All @@ -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");
}
Expand All @@ -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 {
Expand All @@ -155,31 +170,39 @@ private String checkIncompleteObjectives(Farmer farmer){
return output;
}

//need to rename this lol
public List<String> convertStringToList(String modelAnswer){
/**
* summary.
* @param modelAnswer something
* @return
*/
public List<String> convertStringToList(String modelAnswer) {

//todo build a much more comprehensive parser for level
String[] taskItems = modelAnswer.split("|");
List<String> modelTaskList =new ArrayList<String>(Arrays.asList(taskItems));
List<String> modelTaskList = new ArrayList<String>(Arrays.asList(taskItems));
return modelTaskList;
}

//todo- logical error correction
public List<String> convertTaskListFormat(List<String> TaskList){
/**
* Summary.
* @param taskList something
* @return
*/
public List<String> convertTaskListFormat(List<String> taskList) {

List<String> splitTaskList = new ArrayList<String>();
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("(?<!\\G\\w)\\s"); //splits on every second space
//String[] splitString = taskListItems.split("\\s+");
String[] splitString = taskListItems.split("(?<!\\G\\w)\\s"); //splits on every second space
//should be after every 3 spacesh

splitTaskList.add(splitString[0]);
if(splitString[1] != null && !splitString[1].isEmpty()){
if (splitString[1] != null && !splitString[1].isEmpty()) {
splitTaskList.add(splitString[1]);
}

Expand All @@ -200,14 +223,21 @@ public String levelParser(List<String> 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<String> userTaskList = farmio.getFarmer().tasks.toStringArray();
List<String> modelTaskList = convertStringToList(modelAnswer);
List<String> 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+");
Expand All @@ -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<String>
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;
Expand All @@ -242,65 +276,68 @@ public String getDetailedFeedback( Farmio farmio){
return output;
}

public List<String> getSuccessfulFeedback(){
/**
* Summary.
* @return something
*/
public List<String> getSuccessfulFeedback() {
List<String> output = new ArrayList<String>();
//String output = "";
for(String x: successfulFeedback){
for (String x: successfulFeedback) {
output.add(x);
}
return output;
}

/**
* Summary.
* @param farmio something
* @return
*/

public List<String> getFeedback(Farmio farmio){
public List<String> getFeedback(Farmio farmio) {
Farmer farmer = farmio.getFarmer();
objectiveResult currentLevelState = farmio.getLevel().getLevelState();
ObjectiveResult currentLevelState = farmio.getLevel().getLevelState();

List<String> output = new ArrayList<String>();
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<String, Integer> getGoals() {
Map<String, Integer> goals = new HashMap< String,Integer>();
public Map<String,Integer> getGoals() {
Map<String,Integer> goals = new HashMap<String,Integer>();
goals.put("Gold", endGold);
goals.put("Seeds", endSeeds);
goals.put("Seedlings", endSeedlings);
Expand All @@ -310,7 +347,7 @@ public Map<String, Integer> getGoals() {
}

/**
* Get the main objective of the level
* Get the main objective of the level.
* @return the objective of the level
*/
public String getObjective() {
Expand Down
Loading

0 comments on commit f044f84

Please sign in to comment.