Skip to content

Commit

Permalink
Merge pull request #216 from tzw0/FarmLogic
Browse files Browse the repository at this point in the history
minor changes: commandshowlist
  • Loading branch information
tzw0 authored Oct 30, 2019
2 parents f0043bd + 3c35c1d commit 3c29509
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 18 deletions.
3 changes: 1 addition & 2 deletions src/main/java/commands/CommandAddName.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ else if (name.length() <= 15 && name.length() > 0 && (name.matches("[a-zA-Z0-9]+
ui.typeWriter("Welcome Farmer "
+ name
+ ", please press [ENTER] to begin the tutorial"
+
" or enter [skip] to skip the story", false);
+ " or enter [skip] to skip the story", false);
farmio.setStage(Farmio.Stage.LEVEL_START);
} else if (name.length() == 0) {
ui.typeWriter("Provide a name.", false);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/commands/CommandLevelEnd.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class CommandLevelEnd extends Command {
*/
@Override
public void execute(Farmio farmio) throws FarmioFatalException {
farmio.getUi().typeWriter("Farmer + is now ready for his next adventure! "
+ "Press [ENTER] for the narrative or enter [SKIP] to skip the story", false);
farmio.getUi().typeWriter("Farmer "+ farmio.getFarmer().getName()+" is now ready for his next adventure! "
+ "Press [ENTER] to continue or enter [SKIP] to skip the story", false);
Storage storage = farmio.getStorage();
Farmer farmer = farmio.getFarmer();
Level level = new Level(storage.getLevel(farmer.nextLevel()),farmer.getName());
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/commands/CommandLevelStart.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import exceptions.FarmioFatalException;
import farmio.Farmio;
import frontend.AsciiColours;
import frontend.Ui;
import farmio.Storage;
import farmio.Farmer;
Expand All @@ -26,6 +27,7 @@ public void execute(Farmio farmio) throws FarmioFatalException {
String userInput = ui.getInput();
if (userInput.equals("skip")) {
farmio.getSimulation().simulate(level.getPath(), level.getNarratives().size() - 1);
ui.showPointers(level.getHint());
break;
}
farmio.getSimulation().simulate(level.getPath(), frameId++);
Expand Down
12 changes: 4 additions & 8 deletions src/main/java/commands/CommandTasksHint.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

import exceptions.FarmioFatalException;
import farmio.Farmio;
import farmio.Level;
import frontend.Ui;

public class CommandTasksHint extends Command {
private String message;

public CommandTasksHint() {
message = "Enter [Start] when you are ready to complete the objective";
}

/**
* Print hint or instructions for current level.
Expand All @@ -19,8 +15,8 @@ public CommandTasksHint() {
@Override
public void execute(Farmio farmio) throws FarmioFatalException {
Ui ui = farmio.getUi();
farmio.getSimulation().simulate();
ui.typeWriter(farmio.getLevel().getHint(), false);
ui.typeWriter(message, false);
Level level = farmio.getLevel();
farmio.getSimulation().simulate(level.getPath() ,level.getNarratives().size() - 1);
ui.showPointers(farmio.getLevel().getHint());
}
}
2 changes: 1 addition & 1 deletion src/main/java/farmio/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Level(JSONObject object, String name) {
endGrain = Math.toIntExact((Long) object.get("grain"));
deadline = Math.toIntExact((Long) object.get("deadline"));
objective = (String) object.get("objective");
hint = (String) object.get("hint");
hint = ((String) object.get("hint")).replace("+", name);
modelAnswer = (String) object.get("modelAnswer");

}
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/frontend/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,19 @@ public void sleep(int delay) {
}
}

public void showPointers(String text) {
show(AsciiColours.YELLOW + "Pointers:" + AsciiColours.SANE);
show(text);
show("Enter [Start] when you are ready to complete the objective");
}

/**
* Prints text to the terminal type writer style.
* @param text to be printed.
* @param hasPressEnter if 'Press ENTER' should be added to the print.
*/
public void typeWriter(String text, boolean hasPressEnter) { //TODO clean this method up
final char LEVEL_BEGIN_PLACEHOLDER = '~';
final char NAME_PLACEHOLDER = '+';
boolean isNewline = false;
int lineLength = 0;
System.out.print(">>> ");
Expand All @@ -111,7 +116,7 @@ public void typeWriter(String text, boolean hasPressEnter) { //TODO clean this m
System.out.printf("%c", text.charAt(i));
}
if (isNewline) {
System.out.print(" ");
System.out.print("\n ");
isNewline = false;
}
sleep(10);
Expand Down
14 changes: 13 additions & 1 deletion src/main/resources/asciiArt/ActionList/frame1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,16 @@ Transport Market WheatFarm
______________________________________________________
gotoMarket | buySeeds | plantSeeds
gotoWheatFarm | sellGrain | harvestWheat
___________________|________________|_________________
___________________|________________|_________________











[PRESS 'ENTER' TO GO BACK]
8 changes: 7 additions & 1 deletion src/main/resources/asciiArt/ConditionList/frame1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ _____________________|________________________________

Eg: [If gold greaterThanOrEquals 10 do buySeeds]

[PRESS 'ENTER' TO GO BACK TO MENU]






[PRESS 'ENTER' TO GO BACK]
9 changes: 8 additions & 1 deletion src/main/resources/asciiArt/MarketList/frame1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,11 @@
| Grain | 15 gold |
|__________________|___________________________|'

[PRESS 'ENTER' TO GO BACK TO MENU]







[PRESS 'ENTER' TO GO BACK]

0 comments on commit 3c29509

Please sign in to comment.