Skip to content

Commit

Permalink
Merge pull request #220 from tzw0/FarmLogic
Browse files Browse the repository at this point in the history
fix feedback and organised showmenulist
  • Loading branch information
tzw0 authored Oct 31, 2019
2 parents a403c7c + 2b1dde2 commit 1b07529
Show file tree
Hide file tree
Showing 23 changed files with 117 additions and 88 deletions.
4 changes: 3 additions & 1 deletion src/main/java/commands/CommandChangeTask.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package commands;

import exceptions.FarmioFatalException;
import farmio.Farmio;
import farmio.Storage;

public abstract class CommandChangeTask extends Command {

protected void saveTask(Farmio farmio) {
protected void saveTaskandResetScreen(Farmio farmio) throws FarmioFatalException {
Storage storage = farmio.getStorage();
storage.storeFarmer(farmio.getFarmer());
farmio.getSimulation().simulate(farmio.getLevel().getPath(), farmio.getLevel().getNarratives().size() - 1);
}
}
2 changes: 1 addition & 1 deletion src/main/java/commands/CommandCheckObjectives.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void execute(Farmio farmio) throws FarmioFatalException {
Level.ObjectiveResult answer = farmio.getLevel().checkAnswer(farmio);
//farmio.getUi().typeWriter(farmio.getLevel().getFeedback(farmio), false); // feedbacks

List<String> feedback = farmio.getLevel().getFeedback(farmio);
List<String> feedback = farmio.getLevel().getFeedback(farmio, answer);
for (String i : feedback) {
farmio.getUi().typeWriter(i,false);
}
Expand Down
19 changes: 0 additions & 19 deletions src/main/java/commands/CommandMenu.java

This file was deleted.

55 changes: 1 addition & 54 deletions src/main/java/commands/CommandShowList.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,60 +20,7 @@ public CommandShowList(String listPath) {
public void execute(Farmio farmio) throws FarmioFatalException {
Ui ui = farmio.getUi();
double level = farmio.getFarmer().getLevel();

if(filePath.equals("ActionList")) {
if(level == 1.1) {
farmio.getSimulation().simulate(filePath, 11,false);
}
if(level == 1.2) {
farmio.getSimulation().simulate(filePath, 12,false);
}
if(level == 1.3) {
farmio.getSimulation().simulate(filePath, 13,false);
}
if(level == 1.4) {
farmio.getSimulation().simulate(filePath, 14,false);
}
if(level == 1.5) {
farmio.getSimulation().simulate(filePath, 15,false);
}
if(level == 1.6) {
farmio.getSimulation().simulate(filePath, 15,false);
}
}

if(filePath.equals("ConditionList")) {
if(level == 1.1) {
farmio.getSimulation().simulate(filePath, 11,false);
}
if(level == 1.2) {
farmio.getSimulation().simulate(filePath, 11,false);
}
if(level == 1.3) {
farmio.getSimulation().simulate(filePath, 11,false);
}
if(level == 1.4) {
farmio.getSimulation().simulate(filePath, 14,false);
}
if(level == 1.5) {
farmio.getSimulation().simulate(filePath, 16,false);
}
if(level == 1.6) {
farmio.getSimulation().simulate(filePath, 16,false);
}
}

if(filePath.equals("MarketList")) {
if(level < 1.5) {
farmio.getSimulation().simulate(filePath, 4,false);
} else if(level < 2) {
farmio.getSimulation().simulate(filePath, 1, false);
} else if(level < 3) {
farmio.getSimulation().simulate(filePath, 2,false);
} else if(level < 4) {
farmio.getSimulation().simulate(filePath, 3,false);
}
}
farmio.getSimulation().simulate(filePath, (int)(level * 10),false);

ui.show("Press [Enter] to go back to game");
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/commands/CommandTaskCreate.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public void execute(Farmio farmio) throws FarmioException, FarmioFatalException
Storage storage = farmio.getStorage();
Farmer farmer = farmio.getFarmer();
farmer.getTasks().addTask(task);
farmio.getSimulation().simulate(farmio.getLevel().getPath(), farmio.getLevel().getNarratives().size() - 1);
super.saveTaskandResetScreen(farmio);
ui.showInfo("Task [" + task.toString() + "] added! \nYou now have " + farmer.getTasks().size() + " tasks!");
super.saveTask(farmio);
}
}
3 changes: 1 addition & 2 deletions src/main/java/commands/CommandTaskDelete.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ public void execute(Farmio farmio) throws FarmioException, FarmioFatalException
}
try {
String taskToString = farmio.getFarmer().getTasks().removeTask(taskID);
farmio.getSimulation().simulate();
super.saveTaskandResetScreen(farmio);
farmio.getUi().showInfo("You have deleted task: " + taskToString);
super.saveTask(farmio);
} catch (Exception e) {
throw new FarmioException("Error deleting task!");
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/commands/CommandTaskDeleteAll.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public class CommandTaskDeleteAll extends CommandChangeTask {
@Override
public void execute(Farmio farmio) throws FarmioFatalException {
farmio.getFarmer().getTasks().clear();
farmio.getSimulation().simulate();
super.saveTaskandResetScreen(farmio);
farmio.getUi().showInfo("You have deleted all tasks!");
super.saveTask(farmio);
}
}
4 changes: 1 addition & 3 deletions src/main/java/commands/CommandTaskEdit.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ public void execute(Farmio farmio) throws FarmioException, FarmioFatalException
throw new FarmioException("Invalid Task ID!");
}
farmer.getTasks().editTask(taskID, task);
farmio.getSimulation().simulate(farmio.getLevel().getPath(),
farmio.getLevel().getNarratives().size() - 1);
super.saveTaskandResetScreen(farmio);
Ui ui = farmio.getUi();
ui.showInfo("Successfully edited task!");
super.saveTask(farmio);
}
}
3 changes: 1 addition & 2 deletions src/main/java/commands/CommandTaskInsert.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public CommandTaskInsert(int taskID, Task task) {
@Override
public void execute(Farmio farmio) throws FarmioException, FarmioFatalException {
farmio.getFarmer().getTasks().insertTask(taskID, task);
farmio.getSimulation().simulate();
super.saveTaskandResetScreen(farmio);
farmio.getUi().showInfo("You have added a new task: " + task.toString() + " at position " + taskID);
super.saveTask(farmio);
}
}
3 changes: 1 addition & 2 deletions src/main/java/farmio/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,8 @@ public List<String> getSuccessfulFeedback() {
* @return
*/

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

List<String> output = new ArrayList<String>();
if (currentLevelState == ObjectiveResult.DONE) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/asciiArt/ActionList/frame16.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Transport Market WheatFarm
______________________________________________________
gotoMarket | buySeeds | plantSeeds
gotoWheatFarm | sellGrain | harvestWheat
___________________|________________|_________________
5 changes: 5 additions & 0 deletions src/main/resources/asciiArt/ActionList/frame21.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Transport Market WheatFarm
______________________________________________________
gotoMarket | buySeeds | plantSeeds
gotoWheatFarm | sellGrain | harvestWheat
___________________|________________|_________________
9 changes: 9 additions & 0 deletions src/main/resources/asciiArt/ConditionList/frame12.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
GOLD BOOLEAN
______________________________________________________
greaterThanOrEquals |
greaterThan |
lessThan |
lessThanOrEquals |
_____________________|________________________________

Eg: [If gold greaterThanOrEquals 10 do buySeeds]
9 changes: 9 additions & 0 deletions src/main/resources/asciiArt/ConditionList/frame13.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
GOLD BOOLEAN
______________________________________________________
greaterThanOrEquals |
greaterThan |
lessThan |
lessThanOrEquals |
_____________________|________________________________

Eg: [If gold greaterThanOrEquals 10 do buySeeds]
10 changes: 10 additions & 0 deletions src/main/resources/asciiArt/ConditionList/frame15.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
GOLD BOOLEAN
______________________________________________________
greaterThanOrEquals | hasSeeds
greaterThan | hasWheat
lessThan | hasGrain
lessThanOrEquals |
_____________________|________________________________

Eg: [If gold greaterThanOrEquals 10 do buySeeds]

10 changes: 10 additions & 0 deletions src/main/resources/asciiArt/ConditionList/frame21.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
GOLD BOOLEAN
______________________________________________________
greaterThanOrEquals | hasSeeds
greaterThan | hasWheat
lessThan | hasGrain
lessThanOrEquals |
_____________________|________________________________

Eg: [If gold greaterThanOrEquals 10 do buySeeds]

7 changes: 7 additions & 0 deletions src/main/resources/asciiArt/MarketList/frame11.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.______________________________________________.
| Market Rates |
|----------------------------------------------|
| Item | Selling or Buying Price |
|------------------|---------------------------|
| Seeds | 10 gold |
|__________________|___________________________|
7 changes: 7 additions & 0 deletions src/main/resources/asciiArt/MarketList/frame12.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.______________________________________________.
| Market Rates |
|----------------------------------------------|
| Item | Selling or Buying Price |
|------------------|---------------------------|
| Seeds | 10 gold |
|__________________|___________________________|
7 changes: 7 additions & 0 deletions src/main/resources/asciiArt/MarketList/frame13.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.______________________________________________.
| Market Rates |
|----------------------------------------------|
| Item | Selling or Buying Price |
|------------------|---------------------------|
| Seeds | 10 gold |
|__________________|___________________________|
7 changes: 7 additions & 0 deletions src/main/resources/asciiArt/MarketList/frame14.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.______________________________________________.
| Market Rates |
|----------------------------------------------|
| Item | Selling or Buying Price |
|------------------|---------------------------|
| Seeds | 10 gold |
|__________________|___________________________|
10 changes: 10 additions & 0 deletions src/main/resources/asciiArt/MarketList/frame15.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.______________________________________________.
| Market Rates |
|----------------------------------------------|
| Item | Selling or Buying Price |
|------------------|---------------------------|
| Seeds | 10 gold |
| Grain | 15 gold |
|__________________|___________________________|


10 changes: 10 additions & 0 deletions src/main/resources/asciiArt/MarketList/frame16.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.______________________________________________.
| Market Rates |
|----------------------------------------------|
| Item | Selling or Buying Price |
|------------------|---------------------------|
| Seeds | 10 gold |
| Grain | 15 gold |
|__________________|___________________________|


10 changes: 10 additions & 0 deletions src/main/resources/asciiArt/MarketList/frame21.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.______________________________________________.
| Market Rates |
|----------------------------------------------|
| Item | Selling or Buying Price |
|------------------|---------------------------|
| Seeds | 10 gold |
| Grain | 15 gold |
| Chicken | 25 gold |
| Eggs | 10 gold |
|__________________|___________________________|

0 comments on commit 1b07529

Please sign in to comment.