Skip to content

Commit

Permalink
Merge pull request #61 from aaravrawal52/master
Browse files Browse the repository at this point in the history
exit shop command
  • Loading branch information
aaravrawal52 committed Apr 3, 2024
2 parents bb38a77 + 4a58f13 commit cfa721f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
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

0 comments on commit cfa721f

Please sign in to comment.