Skip to content

Commit

Permalink
Updated in game menu
Browse files Browse the repository at this point in the history
Updated in game menu
  • Loading branch information
JohnTYH authored Oct 30, 2019
2 parents 6900694 + f044f84 commit d45a49f
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 144 deletions.
38 changes: 19 additions & 19 deletions src/main/java/commands/CommandMenu.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package commands;

import exceptions.FarmioFatalException;
import farmio.Farmio;
import farmio.Menu;

public class CommandMenu extends Command {

/**
* Shows the menu.
* @param farmio the game which stage is set as MENU.
* @throws FarmioFatalException if simulation file is missing.
*/
@Override
public void execute(Farmio farmio) throws FarmioFatalException {
Menu.show(farmio, true);
farmio.setStage(Farmio.Stage.MENU);
}
}
//package commands;
//
//import exceptions.FarmioFatalException;
//import farmio.Farmio;
//import farmio.Menu;
//
//public class CommandBack extends Command {
// private String input;
// public CommandBack(String userInput) {
// input = userInput;
// }
//
//
// @Override
// public void execute(Farmio farmio) throws FarmioFatalException {
// Menu.show(farmio, true);
// // farmio.setStage(Farmio.Stage.MENU);
// }
//}
69 changes: 2 additions & 67 deletions src/main/java/commands/CommandMenuInGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,8 @@
import exceptions.FarmioFatalException;
import farmio.Farmio;
import farmio.Menu;
import frontend.Ui;

public class CommandMenuInGame extends Command {
private String input;

public CommandMenuInGame(String userInput) {
this.input = userInput;
}


/**
* Shows the menu.
Expand All @@ -20,64 +13,6 @@ public CommandMenuInGame(String userInput) {
*/
@Override
public void execute(Farmio farmio) throws FarmioFatalException {
double level = farmio.getFarmer().getLevel();
Ui ui = farmio.getUi();

if (input.equals("actions")) {
if (level == 1.1) {
farmio.getSimulation().simulate("ActionList", 11,true);
}
if (level == 1.2) {
farmio.getSimulation().simulate("ActionList", 12,true);
}
if (level == 1.3) {
farmio.getSimulation().simulate("ActionList", 13,true);
}
if (level == 1.4) {
farmio.getSimulation().simulate("ActionList", 14,true);
}
if (level == 1.5) {
farmio.getSimulation().simulate("ActionList", 15,true);
}
if (level == 1.6) {
farmio.getSimulation().simulate("ActionList", 15,true);
}
}
if (input.equals("conditions")) {
if (level == 1.1) {
farmio.getSimulation().simulate("ConditionList", 11,true);
}
if (level == 1.2) {
farmio.getSimulation().simulate("ConditionList", 11,true);
}
if (level == 1.3) {
farmio.getSimulation().simulate("ConditionList", 11,true);
}
if (level == 1.4) {
farmio.getSimulation().simulate("ConditionList", 14,true);
}
if (level == 1.5) {
farmio.getSimulation().simulate("ConditionList", 16,true);
}
if (level == 1.6) {
farmio.getSimulation().simulate("ConditionList", 16,true);
}
}

if (input.equals("market")) {
if (level < 1.5) {
farmio.getSimulation().simulate("MarketList", 4,true);
} else if (level < 2) {
farmio.getSimulation().simulate("MarketList", 1, true);
} else if (level < 3) {
farmio.getSimulation().simulate("MarketList", 2,true);
} else if (level < 4) {
farmio.getSimulation().simulate("MarketList", 3,true);
}
}
if (input.equals("")) {
Menu.show(farmio, true);
}
farmio.setStage(Farmio.Stage.MENU);
Menu.show(farmio, true);
}
}
}
62 changes: 59 additions & 3 deletions src/main/java/commands/CommandShowList.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

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

public class CommandShowList extends Command {
private String filePath;

public CommandShowList(String listPath) {
filePath = listPath;
}
Expand All @@ -19,7 +19,63 @@ public CommandShowList(String listPath) {
@Override
public void execute(Farmio farmio) throws FarmioFatalException {
Ui ui = farmio.getUi();
farmio.getSimulation().simulate(filePath, (int)farmio.getFarmer().getLevel());
ui.show("Press [Enter] to go back");
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);
}
}

ui.show("Press [Enter] to go back to game");
}

}
16 changes: 12 additions & 4 deletions src/main/java/farmio/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,31 @@
public class Menu {
private static final String ART_NAME = "menu";
private static final String BULLET = "\t\u2022 ";

public static void show(Farmio farmio, boolean resume) throws FarmioFatalException {
Storage storage = farmio.getStorage();
Ui ui = farmio.getUi();
Simulation simulation =farmio.getSimulation();
if(resume && storage.getSaveExist()) { //resume, save and load
simulation.simulate("Menu", 2, true);
simulation.simulate("Menu", 2, false);
ui.typeWriter("Enter the option of your choice\nPress [Enter] to resume game", false);
}
else if(resume){ //resume and save
simulation.simulate("Menu", 4, true);
simulation.simulate("Menu", 4, false);
ui.typeWriter("Enter the option of your choice\nPress [Enter] to resume game", false);

}
else if(storage.getSaveExist()){ //load
simulation.simulate("Menu", 3, true);
ui.typeWriter("Enter the option of your choice\nFor example, if you want to create a new game," +
" Enter [New Game]", false);
}
else {
simulation.simulate("Menu", 0, true); //only new and quit
ui.typeWriter("Enter the option of your choice\nFor example, if you want to create a new game," +
" Enter [New Game]", false);
}
ui.typeWriter("Enter the option of your choice\nFor example, if you want to create a new game," +
" Enter [New Game]", false);

}

}
24 changes: 12 additions & 12 deletions src/main/java/farmio/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public static Command parse(String userInput, Farmio.Stage stage) throws FarmioE
return new CommandMenuStart();
case LEVEL_START:
return new CommandLevelStart();
case MENU:
return parseMenu(userInput);
// case MENU:
// return parseMenu(userInput);
case RUNNING_DAY:
return new CommandTasksRun();
case CHECK_OBJECTIVES:
Expand Down Expand Up @@ -75,15 +75,15 @@ public static Command parse(String userInput, Farmio.Stage stage) throws FarmioE
* @return Command that corresponds to the user's actions
* @throws FarmioException if user input is invalid
*/
private static Command parseMenu(String userInput) throws FarmioException {
if (userInput.equals("resume game")) {
return new CommandLevelStart();
} else if (userInput.equals("actions") || userInput.equals("conditions") || userInput.equals("market") || userInput.equals("")) {
return new CommandMenuInGame(userInput);
} else {
throw new FarmioException("Invalid command!");
}
}
// private static Command parseMenu(String userInput) throws FarmioException {
// if (userInput.equals("resume game")) {
// return new CommandLevelStart();
// } else if (userInput.equals("actions") || userInput.equals("conditions") || userInput.equals("market") || userInput.equals("")) {
// return new CommandMenuInGame(userInput);
// } else {
// throw new FarmioException("Invalid command!");
// }
// }

/**
* Used to parse the user input during the DAY_END stage. User can choose to either reset the level,
Expand Down Expand Up @@ -113,7 +113,7 @@ private static Command parseDayEnd(String userInput) throws FarmioException {
*/
private static Command parseTaskAdd(String userInput) throws FarmioException {
if (userInput.equals("menu")) {
return new CommandMenu();
return new CommandMenuInGame();
}
if (userInput.equals("deleteall") || userInput.equals("delete all")) {
return new CommandTaskDeleteAll();
Expand Down
6 changes: 0 additions & 6 deletions src/main/resources/asciiArt/ActionList/frame1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,3 @@ ___________________|________________|_________________








[PRESS 'ENTER' TO GO BACK]
2 changes: 0 additions & 2 deletions src/main/resources/asciiArt/ActionList/frame11.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ Transport Market WheatFarm
______________________________________________________
gotoMarket | |
___________________|________________|_________________

[PRESS 'ENTER' TO GO BACK TO MENU]
2 changes: 0 additions & 2 deletions src/main/resources/asciiArt/ActionList/frame12.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ Transport Market WheatFarm
______________________________________________________
gotoMarket | buySeeds |
___________________|________________|_________________

[PRESS 'ENTER' TO GO BACK TO MENU]
2 changes: 0 additions & 2 deletions src/main/resources/asciiArt/ActionList/frame13.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ ______________________________________________________
gotoMarket | buySeeds | plantSeeds
gotoWheatFarm | |
___________________|________________|_________________

[PRESS 'ENTER' TO GO BACK TO MENU]
2 changes: 0 additions & 2 deletions src/main/resources/asciiArt/ActionList/frame14.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ ______________________________________________________
gotoMarket | buySeeds | plantSeeds
gotoWheatFarm | | harvestWheat
___________________|________________|_________________

[PRESS 'ENTER' TO GO BACK TO MENU]
2 changes: 0 additions & 2 deletions src/main/resources/asciiArt/ActionList/frame15.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ ______________________________________________________
gotoMarket | buySeeds | plantSeeds
gotoWheatFarm | sellGrain | harvestWheat
___________________|________________|_________________

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

Eg: [If gold greaterThanOrEquals 10 do buySeeds]







[PRESS 'ENTER' TO GO BACK]
2 changes: 0 additions & 2 deletions src/main/resources/asciiArt/ConditionList/frame11.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,3 @@ ______________________________________________________
_____________________|________________________________

Eg: [If gold greaterThanOrEquals 10 do buySeeds]

[PRESS 'ENTER' TO GO BACK TO MENU]
2 changes: 0 additions & 2 deletions src/main/resources/asciiArt/ConditionList/frame14.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,3 @@ ______________________________________________________
_____________________|________________________________

Eg: [If gold greaterThanOrEquals 10 do buySeeds]

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

Eg: [If gold greaterThanOrEquals 10 do buySeeds]

[PRESS 'ENTER' TO GO BACK TO MENU]
7 changes: 0 additions & 7 deletions src/main/resources/asciiArt/MarketList/frame1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,3 @@
|__________________|___________________________|'








[PRESS 'ENTER' TO GO BACK]
2 changes: 0 additions & 2 deletions src/main/resources/asciiArt/MarketList/frame4.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@
|------------------|---------------------------|
| Seeds | 10 gold |
|__________________|___________________________|

[PRESS 'ENTER' TO GO BACK TO MENU]
4 changes: 2 additions & 2 deletions src/main/resources/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

0 comments on commit d45a49f

Please sign in to comment.