Skip to content

Commit a403c7c

Browse files
authored
Merge pull request #219 from tzw0/FarmLogic
ascii art and minor changes
2 parents d45a49f + 28afb3d commit a403c7c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+738
-101
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,19 @@
1-
Day ends
1+
2+
* * _ .
3+
_ . ( _ )_ *
4+
( _ )_ (_ _(_ ,)
5+
(_ _(_ ,) *
6+
7+
* *
8+
, . .--.
9+
__|__ |____|
10+
/ \ |____|
11+
/ [] |____|
12+
|__________| |
13+
| ____ | |
14+
| |\ /| | | _[_]_
15+
| | \/ | | | ( " )
16+
| | /\ | | | ,(-)'
17+
|__|/__\|__|__| -"-
18+
_______________________________________________________
19+

build/resources/main/asciiArt/ErrorInExecution/frame0.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1-
0
1+
.______.__________________._________________.
2+
|-Task-|----CONDITION-----|------ACTION-----|
3+
|do | |gotoMarket |
4+
| | |buySeeds |
5+
| | |gotoWheatFarm |
6+
| | |plantSeeds |
7+
| | | |
8+
| | | |
9+
| | | |
10+
| | | |
11+
| | | |
12+
| | | |
13+
| | | |
14+
| | | |
15+
| | | |
16+
|______|__________________|_________________|

build/resources/main/asciiArt/Menu/frame2.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ _______________________________________________________
22
__________
33
_.-"` `"-._
44
.'_ _ _ _ _ _ _'.
5-
/ |_ |_||_|| | | | | | \ MENU:
6-
/ | | || \| | | |_| \ Resume Game
5+
/ |_ |_||_|| | | | | | \
6+
/ | | || \| | | |_| \ MENU:
77
; \ Save Game
88
| | Load Game
99
| _. | Quit Game

build/resources/main/asciiArt/TaskCreate/frame0.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
\ \ / /__| | ___ ___ _ __ ___ ___
2-
\ \ /\ / / _ \ |/ __/ _ \| '_ ` _ \ / _ \
3-
\ V V / __/ | (_| (_) | | | | | | __/
4-
\_/\_/ \___|_|\___\___/|_| |_| |_|\___|
5-
_____
6-
|_ _|__
7-
| |/ _ \
8-
| | (_) |
9-
_____ |_|\___/ _
10-
| ___|_ _ _ __ _ __ ___ (_) ___
11-
| |_ / _` | '__| '_ ` _ \| |/ _ \
12-
| _| (_| | | | | | | | | | (_) |
13-
|_| \__,_|_| |_| |_| |_|_|\___/
1+
2+
3+
4+
\ \ / /__| | ___ ___ _ __ ___ ___
5+
\ \ /\ / / _ \ |/ __/ _ \| '_ ` _ \ / _ \
6+
\ V V / __/ | (_| (_) | | | | | | __/
7+
\_/\_/ \___|_|\___\___/|_| |_| |_|\___|
8+
_____
9+
|_ _|__
10+
| |/ _ \
11+
| | (_) |
12+
_____ |_|\___/ _
13+
| ___|_ _ _ __ _ __ ___ (_) ___
14+
| |_ / _` | '__| '_ ` _ \| |/ _ \
15+
| _| (_| | | | | | | | | | (_) |
16+
|_| \__,_|_| |_| |_| |_|_|\___/

src/main/java/commands/CommandAddName.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void execute(Farmio farmio) throws FarmioException, FarmioFatalException
2525
ui.typeWriter("Welcome Farmer "
2626
+ name
2727
+ ", please press [ENTER] to begin the tutorial"
28-
+ " or enter [skip] to skip the story", false);
28+
+ " or enter [SKIP] to skip the story", false);
2929
farmio.setStage(Farmio.Stage.LEVEL_START);
3030
} else if (name.length() == 0) {
3131
ui.typeWriter("Provide a name.", false);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package commands;
2+
3+
import farmio.Farmio;
4+
import farmio.Storage;
5+
6+
public abstract class CommandChangeTask extends Command {
7+
8+
protected void saveTask(Farmio farmio) {
9+
Storage storage = farmio.getStorage();
10+
storage.storeFarmer(farmio.getFarmer());
11+
}
12+
}

src/main/java/commands/CommandCheckObjectives.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import exceptions.FarmioFatalException;
44
import farmio.Farmio;
55
import farmio.Level;
6+
import frontend.AsciiColours;
67

78
import java.util.List;
89

@@ -15,7 +16,6 @@ public class CommandCheckObjectives extends Command {
1516
@Override
1617
public void execute(Farmio farmio) throws FarmioFatalException {
1718
Level.ObjectiveResult answer = farmio.getLevel().checkAnswer(farmio);
18-
farmio.getSimulation().simulate();
1919
//farmio.getUi().typeWriter(farmio.getLevel().getFeedback(farmio), false); // feedbacks
2020

2121
List<String> feedback = farmio.getLevel().getFeedback(farmio);

src/main/java/commands/CommandDayEnd.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import farmio.Farmio;
55
import farmio.Farmer;
66
import farmio.Storage;
7+
import frontend.AsciiColours;
78
import frontend.Ui;
89

910
public class CommandDayEnd extends Command {
@@ -17,9 +18,12 @@ public void execute(Farmio farmio) throws FarmioFatalException {
1718
Ui ui = farmio.getUi();
1819
Storage storage = farmio.getStorage();
1920
Farmer farmer = farmio.getFarmer();
20-
farmio.getSimulation().simulate("DayEnd", 0);
21+
farmio.getSimulation().simulate("DayEnd", 0,4);
22+
farmio.getUi().show(AsciiColours.MAGENTA + AsciiColours.UNDERLINE + "Day Ended" + AsciiColours.SANE);
23+
farmio.getUi().sleep(700);
2124
farmer.nextDay();
22-
farmio.getSimulation().simulate(1000,"DayStart", 1);
25+
farmio.getSimulation().simulate();
26+
farmio.getUi().sleep(700);
2327
farmio.setStage(Farmio.Stage.DAY_START);
2428
}
2529
}

src/main/java/commands/CommandDayStart.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ public class CommandDayStart extends Command {
1515
@Override
1616
public void execute(Farmio farmio) throws FarmioFatalException {
1717
Ui ui = farmio.getUi();
18-
Storage storage = farmio.getStorage();
19-
storage.storeFarmer(farmio.getFarmer());
18+
// Storage storage = farmio.getStorage();
19+
// storage.storeFarmer(farmio.getFarmer());
2020
farmio.getSimulation().simulate("DayStart", 1, 5);
2121
ui.show(AsciiColours.MAGENTA + AsciiColours.UNDERLINE + "Day Started!" + AsciiColours.SANE);
22-
ui.sleep(400);
22+
ui.sleep(300);
2323
farmio.setStage(Farmio.Stage.RUNNING_DAY);
2424
}
2525
}

src/main/java/commands/CommandGameLoad.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ public void execute(Farmio farmio) throws FarmioFatalException {
2323
farmio.setFarmer(farmer);
2424
Level level = new Level(storage.getLevel(farmer.getLevel()), farmer.getName());
2525
farmio.setLevel(level);
26-
farmio.getSimulation().simulate("GameLoad", 0);
27-
ui.typeWriter("Load Game Success!", true);
26+
farmio.getSimulation().simulate("GameLoad", 0, 8, true);
27+
farmio.getSimulation().simulate("GameLoad", 9);
28+
ui.typeWriter("Load Game Successful!, press [ENTER] to continue or enter [SKIP] to skip the story..", false);
2829
} catch (FarmioException e) {
2930
if (farmio.getStage() == Farmio.Stage.MENU_START) {
3031
farmio.getSimulation().simulate("GameNew", 0, true);

src/main/java/commands/CommandLevelEnd.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import farmio.Level;
66
import farmio.Farmer;
77
import farmio.Storage;
8+
import frontend.AsciiColours;
89

910
public class CommandLevelEnd extends Command {
1011
/**
@@ -14,8 +15,12 @@ public class CommandLevelEnd extends Command {
1415
*/
1516
@Override
1617
public void execute(Farmio farmio) throws FarmioFatalException {
18+
farmio.getUi().typeWriter("",true);
19+
farmio.getUi().getInput();
20+
farmio.getSimulation().simulate("LevelEnd", 0,4);
21+
farmio.getUi().show(AsciiColours.GREEN + AsciiColours.UNDERLINE + "Level Ended" + AsciiColours.SANE);
1722
farmio.getUi().typeWriter("Farmer "+ farmio.getFarmer().getName()+" is now ready for his next adventure! "
18-
+ "Press [ENTER] to continue or enter [SKIP] to skip the story", false);
23+
+ "\nPress [ENTER] to continue or enter [SKIP] to skip the story", false);
1924
Storage storage = farmio.getStorage();
2025
Farmer farmer = farmio.getFarmer();
2126
Level level = new Level(storage.getLevel(farmer.nextLevel()),farmer.getName());

src/main/java/commands/CommandLevelStart.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ public void execute(Farmio farmio) throws FarmioFatalException {
2323
Level level = new Level(storage.getLevel(farmer.getLevel()),farmer.getName());
2424
farmio.setLevel(level);
2525
int frameId = 0;
26+
int lastFrameId = level.getNarratives().size() - 1;
2627
for (String narrative: level.getNarratives()) {
2728
String userInput = ui.getInput();
2829
if (userInput.equals("skip")) {
29-
farmio.getSimulation().simulate(level.getPath(), level.getNarratives().size() - 1);
30-
ui.showPointers(level.getHint());
30+
farmio.getSimulation().simulate(level.getPath(), lastFrameId);
31+
ui.typeWriter(level.getNarratives().get(lastFrameId), false);
3132
break;
3233
}
3334
farmio.getSimulation().simulate(level.getPath(), frameId++);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package commands;
2+
3+
import exceptions.FarmioFatalException;
4+
import farmio.Farmio;
5+
import farmio.Level;
6+
import frontend.Ui;
7+
8+
public class CommandTaskAddReset extends Command {
9+
10+
/**
11+
* Print hint or instructions for current level.
12+
* @param farmio the game which level is used to determine hint.
13+
* @throws FarmioFatalException if simulation file is not found.
14+
*/
15+
@Override
16+
public void execute(Farmio farmio) throws FarmioFatalException {
17+
Ui ui = farmio.getUi();
18+
Level level = farmio.getLevel();
19+
farmio.getSimulation().simulate(level.getPath() ,level.getNarratives().size() - 1);
20+
ui.show("Enter [Start] if you are ready to complete the objective or Enter [HINT] if you get stuck!");
21+
}
22+
}

src/main/java/commands/CommandTaskCreate.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import frontend.Ui;
99
import usercode.tasks.Task;
1010

11-
public class CommandTaskCreate extends Command {
11+
public class CommandTaskCreate extends CommandChangeTask {
1212
private Task task;
1313

1414
public CommandTaskCreate(Task task) {
@@ -29,5 +29,6 @@ public void execute(Farmio farmio) throws FarmioException, FarmioFatalException
2929
farmer.getTasks().addTask(task);
3030
farmio.getSimulation().simulate(farmio.getLevel().getPath(), farmio.getLevel().getNarratives().size() - 1);
3131
ui.showInfo("Task [" + task.toString() + "] added! \nYou now have " + farmer.getTasks().size() + " tasks!");
32+
super.saveTask(farmio);
3233
}
3334
}

src/main/java/commands/CommandTaskDelete.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import exceptions.FarmioFatalException;
55
import farmio.Farmio;
66

7-
public class CommandTaskDelete extends Command {
7+
public class CommandTaskDelete extends CommandChangeTask {
88
int taskID;
99

1010
public CommandTaskDelete(int taskID) {
@@ -26,6 +26,7 @@ public void execute(Farmio farmio) throws FarmioException, FarmioFatalException
2626
String taskToString = farmio.getFarmer().getTasks().removeTask(taskID);
2727
farmio.getSimulation().simulate();
2828
farmio.getUi().showInfo("You have deleted task: " + taskToString);
29+
super.saveTask(farmio);
2930
} catch (Exception e) {
3031
throw new FarmioException("Error deleting task!");
3132
}

src/main/java/commands/CommandTaskDeleteAll.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import exceptions.FarmioFatalException;
44
import farmio.Farmio;
55

6-
public class CommandTaskDeleteAll extends Command {
6+
public class CommandTaskDeleteAll extends CommandChangeTask {
77

88
/**
99
* Delete all tasks in the tasklist.
@@ -15,5 +15,6 @@ public void execute(Farmio farmio) throws FarmioFatalException {
1515
farmio.getFarmer().getTasks().clear();
1616
farmio.getSimulation().simulate();
1717
farmio.getUi().showInfo("You have deleted all tasks!");
18+
super.saveTask(farmio);
1819
}
1920
}

src/main/java/commands/CommandTaskEdit.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import farmio.Storage;
99
import farmio.Farmer;
1010

11-
public class CommandTaskEdit extends Command {
11+
public class CommandTaskEdit extends CommandChangeTask {
1212
private Task task;
1313
private int taskID;
1414

@@ -35,5 +35,6 @@ public void execute(Farmio farmio) throws FarmioException, FarmioFatalException
3535
farmio.getLevel().getNarratives().size() - 1);
3636
Ui ui = farmio.getUi();
3737
ui.showInfo("Successfully edited task!");
38+
super.saveTask(farmio);
3839
}
3940
}

src/main/java/commands/CommandTaskInsert.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import farmio.Farmio;
66
import usercode.tasks.Task;
77

8-
public class CommandTaskInsert extends Command {
8+
public class CommandTaskInsert extends CommandChangeTask {
99
private Task task;
1010
private int taskID;
1111

@@ -26,5 +26,6 @@ public void execute(Farmio farmio) throws FarmioException, FarmioFatalException
2626
farmio.getFarmer().getTasks().insertTask(taskID, task);
2727
farmio.getSimulation().simulate();
2828
farmio.getUi().showInfo("You have added a new task: " + task.toString() + " at position " + taskID);
29+
super.saveTask(farmio);
2930
}
3031
}

src/main/java/commands/CommandTasksHint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ public void execute(Farmio farmio) throws FarmioFatalException {
1717
Ui ui = farmio.getUi();
1818
Level level = farmio.getLevel();
1919
farmio.getSimulation().simulate(level.getPath() ,level.getNarratives().size() - 1);
20-
ui.showPointers(farmio.getLevel().getHint());
20+
ui.showHint(farmio.getLevel().getHint());
2121
}
2222
}

src/main/java/commands/CommandTasksRun.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public class CommandTasksRun extends Command {
1313
@Override
1414
public void execute(Farmio farmio) throws FarmioFatalException {
1515
farmio.getFarmer().startDay(farmio);
16-
farmio.getUi().show(AsciiColours.MAGENTA + AsciiColours.UNDERLINE + "Day Ended" + AsciiColours.SANE);
17-
farmio.getUi().sleep(1000);
16+
farmio.getUi().sleep(300);
17+
farmio.getSimulation().simulate("DayStart", 1);
1818
farmio.setStage(Farmio.Stage.CHECK_OBJECTIVES);
1919
}
2020
}

src/main/java/farmio/Level.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public List<String> getFeedback(Farmio farmio) {
312312
feedback += "detailed feedback : -- \n";
313313
feedback += checkIncompleteObjectives(farmer);
314314
}
315-
output.add("\n Press [ENTER] to continue the game or [RESET] to restart the level");
315+
output.add("Press [ENTER] to continue the game or [RESET] to restart the level");
316316
return output;
317317
} else if (currentLevelState == ObjectiveResult.FAILED) {
318318
String feedback = "Oh no! The objectives were not met by the deadline! Level failed ! \n";

src/main/java/farmio/Parser.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,10 @@ private static Command parseTaskAdd(String userInput) throws FarmioException {
142142
if (userInput.startsWith("do") || userInput.startsWith("if")
143143
|| userInput.startsWith("for") || userInput.startsWith("while")) {
144144
return new CommandTaskCreate(parseTask(userInput));
145-
} else if (userInput.equals("hint") || userInput.equals("")) {
145+
} else if (userInput.equals("hint")) {
146146
return new CommandTasksHint();
147+
} else if (userInput.equals("")) {
148+
return new CommandTaskAddReset();
147149
}
148150
throw new FarmioException("Invalid command!");
149151
}

src/main/java/farmio/Storage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public Storage() {
3434
* @return True is save.json exist and false if save.json does not exist.
3535
*/
3636
public boolean getSaveExist() {
37-
System.out.println(new File(appDir.concat(jsonName)).toString());
37+
// System.out.println(new File(appDir.concat(jsonName)).toString());
3838
return new File(appDir.concat(jsonName)).exists();
3939
}
4040

0 commit comments

Comments
 (0)