Skip to content

Commit

Permalink
Merge pull request #219 from tzw0/FarmLogic
Browse files Browse the repository at this point in the history
ascii art and minor changes
  • Loading branch information
tzw0 authored Oct 30, 2019
2 parents d45a49f + 28afb3d commit a403c7c
Show file tree
Hide file tree
Showing 76 changed files with 738 additions and 101 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion build/resources/main/asciiArt/DayEnd/frame0.txt
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
Day ends

* * _ .
_ . ( _ )_ *
( _ )_ (_ _(_ ,)
(_ _(_ ,) *

* *
, . .--.
__|__ |____|
/ \ |____|
/ [] |____|
|__________| |
| ____ | |
| |\ /| | | _[_]_
| | \/ | | | ( " )
| | /\ | | | ,(-)'
|__|/__\|__|__| -"-
_______________________________________________________

4 changes: 0 additions & 4 deletions build/resources/main/asciiArt/ErrorInExecution/frame0.txt

This file was deleted.

17 changes: 16 additions & 1 deletion build/resources/main/asciiArt/Level1.3/frame0.txt
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
0
.______.__________________._________________.
|-Task-|----CONDITION-----|------ACTION-----|
|do | |gotoMarket |
| | |buySeeds |
| | |gotoWheatFarm |
| | |plantSeeds |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
|______|__________________|_________________|
4 changes: 2 additions & 2 deletions build/resources/main/asciiArt/Menu/frame2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ _______________________________________________________
__________
_.-"` `"-._
.'_ _ _ _ _ _ _'.
/ |_ |_||_|| | | | | | \ MENU:
/ | | || \| | | |_| \ Resume Game
/ |_ |_||_|| | | | | | \
/ | | || \| | | |_| \ MENU:
; \ Save Game
| | Load Game
| _. | Quit Game
Expand Down
5 changes: 0 additions & 5 deletions build/resources/main/asciiArt/TaskCreate/frame0.txt

This file was deleted.

29 changes: 16 additions & 13 deletions build/resources/main/asciiArt/Welcome/frame1.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
\ \ / /__| | ___ ___ _ __ ___ ___
\ \ /\ / / _ \ |/ __/ _ \| '_ ` _ \ / _ \
\ V V / __/ | (_| (_) | | | | | | __/
\_/\_/ \___|_|\___\___/|_| |_| |_|\___|
_____
|_ _|__
| |/ _ \
| | (_) |
_____ |_|\___/ _
| ___|_ _ _ __ _ __ ___ (_) ___
| |_ / _` | '__| '_ ` _ \| |/ _ \
| _| (_| | | | | | | | | | (_) |
|_| \__,_|_| |_| |_| |_|_|\___/



\ \ / /__| | ___ ___ _ __ ___ ___
\ \ /\ / / _ \ |/ __/ _ \| '_ ` _ \ / _ \
\ V V / __/ | (_| (_) | | | | | | __/
\_/\_/ \___|_|\___\___/|_| |_| |_|\___|
_____
|_ _|__
| |/ _ \
| | (_) |
_____ |_|\___/ _
| ___|_ _ _ __ _ __ ___ (_) ___
| |_ / _` | '__| '_ ` _ \| |/ _ \
| _| (_| | | | | | | | | | (_) |
|_| \__,_|_| |_| |_| |_|_|\___/
2 changes: 1 addition & 1 deletion src/main/java/commands/CommandAddName.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void execute(Farmio farmio) throws FarmioException, FarmioFatalException
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
12 changes: 12 additions & 0 deletions src/main/java/commands/CommandChangeTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package commands;

import farmio.Farmio;
import farmio.Storage;

public abstract class CommandChangeTask extends Command {

protected void saveTask(Farmio farmio) {
Storage storage = farmio.getStorage();
storage.storeFarmer(farmio.getFarmer());
}
}
2 changes: 1 addition & 1 deletion src/main/java/commands/CommandCheckObjectives.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import exceptions.FarmioFatalException;
import farmio.Farmio;
import farmio.Level;
import frontend.AsciiColours;

import java.util.List;

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

List<String> feedback = farmio.getLevel().getFeedback(farmio);
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/commands/CommandDayEnd.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import farmio.Farmio;
import farmio.Farmer;
import farmio.Storage;
import frontend.AsciiColours;
import frontend.Ui;

public class CommandDayEnd extends Command {
Expand All @@ -17,9 +18,12 @@ public void execute(Farmio farmio) throws FarmioFatalException {
Ui ui = farmio.getUi();
Storage storage = farmio.getStorage();
Farmer farmer = farmio.getFarmer();
farmio.getSimulation().simulate("DayEnd", 0);
farmio.getSimulation().simulate("DayEnd", 0,4);
farmio.getUi().show(AsciiColours.MAGENTA + AsciiColours.UNDERLINE + "Day Ended" + AsciiColours.SANE);
farmio.getUi().sleep(700);
farmer.nextDay();
farmio.getSimulation().simulate(1000,"DayStart", 1);
farmio.getSimulation().simulate();
farmio.getUi().sleep(700);
farmio.setStage(Farmio.Stage.DAY_START);
}
}
6 changes: 3 additions & 3 deletions src/main/java/commands/CommandDayStart.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public class CommandDayStart extends Command {
@Override
public void execute(Farmio farmio) throws FarmioFatalException {
Ui ui = farmio.getUi();
Storage storage = farmio.getStorage();
storage.storeFarmer(farmio.getFarmer());
// Storage storage = farmio.getStorage();
// storage.storeFarmer(farmio.getFarmer());
farmio.getSimulation().simulate("DayStart", 1, 5);
ui.show(AsciiColours.MAGENTA + AsciiColours.UNDERLINE + "Day Started!" + AsciiColours.SANE);
ui.sleep(400);
ui.sleep(300);
farmio.setStage(Farmio.Stage.RUNNING_DAY);
}
}
5 changes: 3 additions & 2 deletions src/main/java/commands/CommandGameLoad.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public void execute(Farmio farmio) throws FarmioFatalException {
farmio.setFarmer(farmer);
Level level = new Level(storage.getLevel(farmer.getLevel()), farmer.getName());
farmio.setLevel(level);
farmio.getSimulation().simulate("GameLoad", 0);
ui.typeWriter("Load Game Success!", true);
farmio.getSimulation().simulate("GameLoad", 0, 8, true);
farmio.getSimulation().simulate("GameLoad", 9);
ui.typeWriter("Load Game Successful!, press [ENTER] to continue or enter [SKIP] to skip the story..", false);
} catch (FarmioException e) {
if (farmio.getStage() == Farmio.Stage.MENU_START) {
farmio.getSimulation().simulate("GameNew", 0, true);
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/commands/CommandLevelEnd.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import farmio.Level;
import farmio.Farmer;
import farmio.Storage;
import frontend.AsciiColours;

public class CommandLevelEnd extends Command {
/**
Expand All @@ -14,8 +15,12 @@ public class CommandLevelEnd extends Command {
*/
@Override
public void execute(Farmio farmio) throws FarmioFatalException {
farmio.getUi().typeWriter("",true);
farmio.getUi().getInput();
farmio.getSimulation().simulate("LevelEnd", 0,4);
farmio.getUi().show(AsciiColours.GREEN + AsciiColours.UNDERLINE + "Level Ended" + AsciiColours.SANE);
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);
+ "\nPress [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
5 changes: 3 additions & 2 deletions src/main/java/commands/CommandLevelStart.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ public void execute(Farmio farmio) throws FarmioFatalException {
Level level = new Level(storage.getLevel(farmer.getLevel()),farmer.getName());
farmio.setLevel(level);
int frameId = 0;
int lastFrameId = level.getNarratives().size() - 1;
for (String narrative: level.getNarratives()) {
String userInput = ui.getInput();
if (userInput.equals("skip")) {
farmio.getSimulation().simulate(level.getPath(), level.getNarratives().size() - 1);
ui.showPointers(level.getHint());
farmio.getSimulation().simulate(level.getPath(), lastFrameId);
ui.typeWriter(level.getNarratives().get(lastFrameId), false);
break;
}
farmio.getSimulation().simulate(level.getPath(), frameId++);
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/commands/CommandTaskAddReset.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package commands;

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

public class CommandTaskAddReset extends Command {

/**
* Print hint or instructions for current level.
* @param farmio the game which level is used to determine hint.
* @throws FarmioFatalException if simulation file is not found.
*/
@Override
public void execute(Farmio farmio) throws FarmioFatalException {
Ui ui = farmio.getUi();
Level level = farmio.getLevel();
farmio.getSimulation().simulate(level.getPath() ,level.getNarratives().size() - 1);
ui.show("Enter [Start] if you are ready to complete the objective or Enter [HINT] if you get stuck!");
}
}
3 changes: 2 additions & 1 deletion src/main/java/commands/CommandTaskCreate.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import frontend.Ui;
import usercode.tasks.Task;

public class CommandTaskCreate extends Command {
public class CommandTaskCreate extends CommandChangeTask {
private Task task;

public CommandTaskCreate(Task task) {
Expand All @@ -29,5 +29,6 @@ public void execute(Farmio farmio) throws FarmioException, FarmioFatalException
farmer.getTasks().addTask(task);
farmio.getSimulation().simulate(farmio.getLevel().getPath(), farmio.getLevel().getNarratives().size() - 1);
ui.showInfo("Task [" + task.toString() + "] added! \nYou now have " + farmer.getTasks().size() + " tasks!");
super.saveTask(farmio);
}
}
3 changes: 2 additions & 1 deletion src/main/java/commands/CommandTaskDelete.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import exceptions.FarmioFatalException;
import farmio.Farmio;

public class CommandTaskDelete extends Command {
public class CommandTaskDelete extends CommandChangeTask {
int taskID;

public CommandTaskDelete(int taskID) {
Expand All @@ -26,6 +26,7 @@ public void execute(Farmio farmio) throws FarmioException, FarmioFatalException
String taskToString = farmio.getFarmer().getTasks().removeTask(taskID);
farmio.getSimulation().simulate();
farmio.getUi().showInfo("You have deleted task: " + taskToString);
super.saveTask(farmio);
} catch (Exception e) {
throw new FarmioException("Error deleting task!");
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/commands/CommandTaskDeleteAll.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import exceptions.FarmioFatalException;
import farmio.Farmio;

public class CommandTaskDeleteAll extends Command {
public class CommandTaskDeleteAll extends CommandChangeTask {

/**
* Delete all tasks in the tasklist.
Expand All @@ -15,5 +15,6 @@ public void execute(Farmio farmio) throws FarmioFatalException {
farmio.getFarmer().getTasks().clear();
farmio.getSimulation().simulate();
farmio.getUi().showInfo("You have deleted all tasks!");
super.saveTask(farmio);
}
}
3 changes: 2 additions & 1 deletion src/main/java/commands/CommandTaskEdit.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import farmio.Storage;
import farmio.Farmer;

public class CommandTaskEdit extends Command {
public class CommandTaskEdit extends CommandChangeTask {
private Task task;
private int taskID;

Expand All @@ -35,5 +35,6 @@ public void execute(Farmio farmio) throws FarmioException, FarmioFatalException
farmio.getLevel().getNarratives().size() - 1);
Ui ui = farmio.getUi();
ui.showInfo("Successfully edited task!");
super.saveTask(farmio);
}
}
3 changes: 2 additions & 1 deletion src/main/java/commands/CommandTaskInsert.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import farmio.Farmio;
import usercode.tasks.Task;

public class CommandTaskInsert extends Command {
public class CommandTaskInsert extends CommandChangeTask {
private Task task;
private int taskID;

Expand All @@ -26,5 +26,6 @@ public void execute(Farmio farmio) throws FarmioException, FarmioFatalException
farmio.getFarmer().getTasks().insertTask(taskID, task);
farmio.getSimulation().simulate();
farmio.getUi().showInfo("You have added a new task: " + task.toString() + " at position " + taskID);
super.saveTask(farmio);
}
}
2 changes: 1 addition & 1 deletion src/main/java/commands/CommandTasksHint.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public void execute(Farmio farmio) throws FarmioFatalException {
Ui ui = farmio.getUi();
Level level = farmio.getLevel();
farmio.getSimulation().simulate(level.getPath() ,level.getNarratives().size() - 1);
ui.showPointers(farmio.getLevel().getHint());
ui.showHint(farmio.getLevel().getHint());
}
}
4 changes: 2 additions & 2 deletions src/main/java/commands/CommandTasksRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class CommandTasksRun extends Command {
@Override
public void execute(Farmio farmio) throws FarmioFatalException {
farmio.getFarmer().startDay(farmio);
farmio.getUi().show(AsciiColours.MAGENTA + AsciiColours.UNDERLINE + "Day Ended" + AsciiColours.SANE);
farmio.getUi().sleep(1000);
farmio.getUi().sleep(300);
farmio.getSimulation().simulate("DayStart", 1);
farmio.setStage(Farmio.Stage.CHECK_OBJECTIVES);
}
}
2 changes: 1 addition & 1 deletion src/main/java/farmio/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public List<String> getFeedback(Farmio farmio) {
feedback += "detailed feedback : -- \n";
feedback += checkIncompleteObjectives(farmer);
}
output.add("\n Press [ENTER] to continue the game or [RESET] to restart the level");
output.add("Press [ENTER] to continue the game or [RESET] to restart the level");
return output;
} else if (currentLevelState == ObjectiveResult.FAILED) {
String feedback = "Oh no! The objectives were not met by the deadline! Level failed ! \n";
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/farmio/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ private static Command parseTaskAdd(String userInput) throws FarmioException {
if (userInput.startsWith("do") || userInput.startsWith("if")
|| userInput.startsWith("for") || userInput.startsWith("while")) {
return new CommandTaskCreate(parseTask(userInput));
} else if (userInput.equals("hint") || userInput.equals("")) {
} else if (userInput.equals("hint")) {
return new CommandTasksHint();
} else if (userInput.equals("")) {
return new CommandTaskAddReset();
}
throw new FarmioException("Invalid command!");
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/farmio/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public Storage() {
* @return True is save.json exist and false if save.json does not exist.
*/
public boolean getSaveExist() {
System.out.println(new File(appDir.concat(jsonName)).toString());
// System.out.println(new File(appDir.concat(jsonName)).toString());
return new File(appDir.concat(jsonName)).exists();
}

Expand Down
Loading

0 comments on commit a403c7c

Please sign in to comment.