Skip to content

Commit

Permalink
Created Logic component
Browse files Browse the repository at this point in the history
  • Loading branch information
jing-xuan committed Nov 7, 2019
1 parent c126810 commit d5c1ebc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
12 changes: 1 addition & 11 deletions src/main/java/farmio/Farmio.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,7 @@ private void run() {
ui.showWarning(e.getMessage());
}
while (!isExit) {
try {
if (Stage.noInput.contains(stage)) {
command = Parser.parse(" ", stage);
} else {
command = Parser.parse(ui.getInput(), stage);
}
command.execute(this);
} catch (FarmioException e) {
simulation.simulate();
ui.showWarning(e.getMessage());
}
Logic.execute(stage, this);
}
} catch (FarmioFatalException e) {
ui.showError(e.getMessage());
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/farmio/Logic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package farmio;

import frontend.Simulation;
import frontend.Ui;
import frontend.UiManager;
import exceptions.FarmioException;
import exceptions.FarmioFatalException;

public class Logic {

public static void execute(Farmio.Stage stage, Farmio farmio) throws FarmioFatalException {
try {
String userInput = "";
if (Farmio.Stage.reqInput.contains(stage)) {
userInput = farmio.getUi().getInput();
}
Parser.parse(userInput, stage).execute(farmio);
} catch (FarmioException | FarmioFatalException e) {
farmio.getSimulation().simulate();
farmio.getUi().showWarning(e.getMessage());
}
}
}

0 comments on commit d5c1ebc

Please sign in to comment.