Skip to content

Commit

Permalink
refactored checkIncompleteObjectives
Browse files Browse the repository at this point in the history
  • Loading branch information
notahotdog committed Oct 24, 2019
2 parents e12c6a7 + a18dab6 commit a454700
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/main/java/Commands/CommandDayEnd.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void execute(Farmio farmio) throws FarmioException, FarmioFatalException
Farmer farmer = farmio.getFarmer();
farmio.getSimulation().animate("DayEnd", 0, true);
farmio.getUi().show("Press ENTER to start your next day!");
farmer.nextDay(farmio);
farmer.nextDay();
farmio.setStage(Farmio.Stage.DAY_START);
}
}
7 changes: 4 additions & 3 deletions src/main/java/Farmio/Farmer.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public class Farmer {
private ArrayList<Double> levelList = new ArrayList<Double>(Arrays.asList(1.1,1.2,1.3,1.4,1.5,1.6,2.1,2.2));

public Farmer() {
this.money = 10;
this.level = 1.1;
this.money = 95;
this.level = 1.6;
this.day = 1;
this.location = "WheatFarm";
this.wheatFarm = new WheatFarm();
Expand Down Expand Up @@ -177,8 +177,9 @@ public void startDay(Farmio farmio) throws FarmioException, FarmioFatalException
}
}

public void nextDay(Farmio farmio) throws FarmioException, FarmioFatalException {
public void nextDay() throws FarmioException, FarmioFatalException {
wheatFarm.growSeedlings();
day += 1;
}


Expand Down
2 changes: 1 addition & 1 deletion src/main/java/Farmio/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ else if (currentLevelState == objectiveResult.FAILED){

public Map<String, Integer> getGoals() {
Map<String, Integer> goals = new HashMap< String,Integer>();
goals.put("Gold", endMoney);
goals.put("Gold", gold);
goals.put("Seeds", endWheatSeed);
goals.put("Wheat", endWheatGreen);
goals.put("Grain", endWheatRipe);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/Places/WheatFarm.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public boolean hasSeeds() {
}

public boolean hasWheat() {
return grain > 0;
return wheat > 0;
}

public boolean hasRipened() {
return wheat > 0;
public boolean hasGrain() {
return grain > 0;
}

public WheatFarm() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/UserCode/Actions/HarvestWheatAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void execute(Ui ui, Storage storage, Farmer farmer, Simulation simulation
farmer.setTaskFailed();
simulation.animate("ErrorInExecution", 0);
if (!farmer.getWheatFarm().hasWheat()) {
ui.typeWriter("Error! you have attempted to harvest wheat despite not having any seedlings/\n");
ui.typeWriter("Error! you have attempted to harvest wheat despite not having any wheat/\n");
} else {
ui.typeWriter("Error! you have attempted to harvest wheat despite not being at the Wheatfarm/\n");
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/UserCode/Actions/SellWheatAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ public SellWheatAction() {

@Override
public void execute(Ui ui, Storage storage, Farmer farmer, Simulation simulation) throws FarmioFatalException, FarmioException {
if (!farmer.getWheatFarm().hasRipened() || !farmer.getLocation().equals("Market")) {
if (!farmer.getWheatFarm().hasGrain() || !farmer.getLocation().equals("Market")) {
farmer.setTaskFailed();
simulation.animate("ErrorInExecution", 0);
if (!farmer.getWheatFarm().hasWheat()) {
ui.typeWriter("Error! you have attempted to sell wheat despite not having any wheat/\n");
if (!farmer.getWheatFarm().hasGrain()) {
ui.typeWriter("Error! you have attempted to sell grain despite not having any grain/\n");
} else {
ui.typeWriter("Error! you have attempted to sell wheat despite not being at the market/\n");
ui.typeWriter("Error! you have attempted to sell grain despite not being at the market/\n");
}
throw new FarmioException("Task Error!");
}
try {
simulation.animate("SellWheatSimulation", 0, 6);
ui.show("Selling wheat!");
ui.show("Selling grain!");
farmer.earnMoney(farmer.getWheatFarm().sell());
simulation.animate(1000, "SellWheatSimulation", 7);
} catch (Exception e) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/UserCode/Conditions/BooleanConditionType.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

public enum BooleanConditionType {
hasSeeds,
hasWheat,
hasGrain,
wheatRipened,
wheatHarvested,
TRUE
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/UserCode/Conditions/ConditionChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ 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() ;
}
if (condition == BooleanConditionType.hasGrain)
{
return farmio.getFarmer().getWheatFarm().hasGrain();
}
if (condition == BooleanConditionType.TRUE) {
return true;
}
Expand Down

0 comments on commit a454700

Please sign in to comment.