Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exit shop command #61

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/command/CommandType.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public enum CommandType {
INTERACT("(?i)\\h*(e)\\h*"),
QUIT("(?i)\\h*(q|quit)\\h*"),
HELP("(?i)\\h*(h|help)\\h*"),
EXIT("(?i)\\h*(exit)\\h*"), // New command: EXIT

ERROR("");
final String regExpression;

Expand Down
24 changes: 24 additions & 0 deletions src/main/java/command/mapmove/ExitShop.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package command.mapmove;

import command.Command;
import map.BaseMap;
import map.BattleInterface.BattleInterface;
import map.ShopMap;

import static map.BaseMap.storedMaps;
import static map.MapGenerator.FIRST_MAP_IDENTITY;
import static map.BaseMap.mapIndex;

public class ExitShop extends Command {
public ExitShop() {
commandDescription = "RUN!";
}
@Override
public void execute(){
if(currentMap instanceof ShopMap) {
textBox.setNextNarration("You exited the shop!!");
BaseMap.currentMap = mapIndex.get(FIRST_MAP_IDENTITY);
currentMap = storedMaps.get(BaseMap.currentMap);
}
}
}
10 changes: 5 additions & 5 deletions src/main/java/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
import command.CommandType;
import command.fight.FightingCommand;
import command.fight.RunningCommand;
import command.mapmove.InteractingCommand;
import command.mapmove.MovingDownwardCommand;
import command.mapmove.MovingForwardCommand;
import command.mapmove.MovingLeftCommand;
import command.mapmove.MovingRightCommand;
import command.mapmove.*;
import command.ErrorCommand;
import command.HelpCommand;
import command.QuitCommand;
Expand All @@ -20,6 +16,7 @@
import static map.BaseMap.currentMap;
import static map.BaseMap.mapIndex;
import static map.MapGenerator.FIRST_MAP_IDENTITY;
import static map.MapGenerator.SHOP;

public class Parser {

Expand All @@ -46,6 +43,9 @@ public Command parseCommand(String userCommand) {
case FIGHT:
command = (currentMap != mapIndex.get(FIRST_MAP_IDENTITY)) ? new FightingCommand() : new ErrorCommand();
break;
case EXIT:
command = (currentMap == mapIndex.get(SHOP)) ? new ExitShop() : new ErrorCommand();
break;
case RUN:
command = (currentMap != mapIndex.get(FIRST_MAP_IDENTITY)) ? new RunningCommand() : new ErrorCommand();
break;
Expand Down
Loading