Skip to content

Commit

Permalink
added Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
notahotdog committed Oct 24, 2019
1 parent 01fe759 commit e12c6a7
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 11 deletions.
72 changes: 64 additions & 8 deletions src/main/java/Farmio/Level.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package Farmio;

import Places.Farm;
import Places.WheatFarm;
import UserCode.Conditions.BooleanCondition;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
Expand All @@ -12,7 +13,6 @@
public class Level {
ArrayList<String> narratives;
String filePath;
int endMoney;
int endWheatSeed;
int endWheatGreen;
int endWheatRipe;
Expand All @@ -21,6 +21,8 @@ public class Level {
int endCow;
int endCowMilk;
int location;
int gold;
int deadline;

public Level(JSONObject object, Farmer farmer) {
JSONArray array = (JSONArray) object.get("narratives");
Expand All @@ -37,6 +39,7 @@ public Level(JSONObject object, Farmer farmer) {
endChickenEggs = 0;
endCow = 0;
endCowMilk = 0;
deadline = Math.toIntExact((Long) object.get("deadline"));


// location = Math.toIntExact((Long) object.get("location"));
Expand All @@ -62,38 +65,91 @@ public boolean checkDeadlineExceeded(int currentDay){
}

public boolean allDone(Farmer farmer){
int gold = farmer.getMoney();

//Wheat Farm
int WheatSeed = farmer.wheatFarm.getSeeds();
int WheatGreen = farmer.wheatFarm.getGreenWheat();
int WheatRipe = farmer.wheatFarm.getRipeWheat();
int WheatRipe = farmer.wheatFarm.getWheat();
return (WheatGreen == endWheatGreen) && (WheatRipe == endWheatRipe) && (endWheatSeed == WheatSeed);

return (gold == endMoney ) && (WheatGreen == endWheatGreen) && (WheatRipe == endWheatRipe) && (endWheatSeed == WheatSeed);

//Cow Farm
}

public objectiveResult checkAnswer(Farmio farmio){
if (farmio.getFarmer().isHasfailedCurrentTask()) {
return objectiveResult.INVALID;
}

Farmer farmer = farmio.getFarmer();
int day = farmer.getDay();
objectiveResult currentLevelState;
if(checkDeadlineExceeded(day)){
currentLevelState = levelState.FAILED;
currentLevelState = objectiveResult.FAILED;
getFeedback(farmer, currentLevelState);
}
else {
if (allDone(farmer)) {
currentLevelState = levelState.ALLDONE;
currentLevelState = objectiveResult.DONE;
}
else{
currentLevelState = levelState.NOTDONE;
currentLevelState = objectiveResult.NOT_DONE;
}
}
getFeedback(farmer, currentLevelState);
return currentLevelState;
}


public String checkIncompleteObjectives (Farmer farmer){
//compare the differences
//check the level types
String output = "";
int WheatSeed = farmer.wheatFarm.getSeeds();
int WheatGreen = farmer.wheatFarm.getGreenWheat();
int WheatRipe = farmer.wheatFarm.getWheat();

if(WheatSeed != endWheatSeed){
int balancedWheatSeed = endWheatSeed - WheatSeed;
output += "\nWheatSeed left :" + balancedWheatSeed;
}
else {
output += "\nWheatSeed Completed";
}
if(WheatGreen != endWheatGreen){
int balancedWheatGreen = endWheatGreen - WheatGreen;
output += "\n WheatGreen left :" + balancedWheatGreen;
}
else {
output += "\nWheatGreen Completed";
}
if(WheatRipe != endWheatRipe){
int balancedWheatRipe = endWheatRipe - WheatRipe;
output += "\nWheatRipe left :" + balancedWheatRipe;
}
else {
output += "\nWheatRipe Completed";
}

return output;
}


public String getFeedback( Farmer farmer, objectiveResult currentLevelState ){
//get Feedback on whats not completed
//need to complete.
if(currentLevelState == objectiveResult.DONE){
return "all tasks has been completed";
}

else if(currentLevelState == objectiveResult.NOT_DONE){
return checkIncompleteObjectives(farmer);
}

else if (currentLevelState == objectiveResult.FAILED){
return "level failed";
}
return "";
}



Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/levels/1.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"wheat_seed": 0,
"wheat_green": 0,
"wheat_ripe": 0,
"file_path": "Level1.1"
"file_path": "Level1.1",
"deadline" : 5;
}
3 changes: 2 additions & 1 deletion src/main/resources/levels/1.2.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"wheat_seed": 1,
"wheat_green": 0,
"wheat_ripe": 0,
"file_path": "Level1.2"
"file_path": "Level1.2",
"deadline" : 5,
}
3 changes: 2 additions & 1 deletion src/main/resources/levels/1.3.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"wheat_seed": 0,
"wheat_green": 1,
"wheat_ripe": 0,
"file_path": "Level1.3"
"deadline" : 5,
"file_path": "Level1.3",
}
1 change: 1 addition & 0 deletions src/main/resources/levels/1.4.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"wheat_seed": 0,
"wheat_green": 0,
"wheat_ripe": 1,
"deadline" : 5,
"file_path": "Level1.4"
}
1 change: 1 addition & 0 deletions src/main/resources/levels/1.5.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"wheat_seed": 0,
"wheat_green": 0,
"wheat_ripe": 0,
"deadline" : 5,
"file_path": "Level1.5"
}
1 change: 1 addition & 0 deletions src/main/resources/levels/1.6.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"wheat_seed": 0,
"wheat_green": 0,
"wheat_ripe": 0,
"deadline" : 5,
"file_path": "Level1.6"
}

0 comments on commit e12c6a7

Please sign in to comment.