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

add local static variable stored map #25

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
3 changes: 2 additions & 1 deletion src/main/java/command/fight/FightingCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package command.fight;
import command.Command;

import static main.CalculaChroniclesOfTheAlgorithmicKingdom.*;
import java.util.Scanner;


Expand All @@ -16,5 +16,6 @@ public void execute() {
@Override
public void execute(Scanner in) {
currentMap.fightLoop(in);
currentOn = 0;
}
}
4 changes: 3 additions & 1 deletion src/main/java/command/mapmove/InteractingCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import InteractableEntity.*;
import map.*;
import map.BattleInterface.BattleInterface;
import static main.CalculaChroniclesOfTheAlgorithmicKingdom.*;

public class InteractingCommand extends MapMoveCommand {

Expand All @@ -21,7 +22,8 @@ public void execute() {
InteractableEntity monster = new Enemy(10, 10, 10);
battleMap = new BattleInterface(playerStatus, textBox, monster);
battleMap.initMap(30, 10);
currentMap = battleMap;
storedMaps.add(battleMap);
currentOn = 1;
break;
default:
battleMap = new BattleInterface(null, null, null);
Expand Down
23 changes: 14 additions & 9 deletions src/main/java/main/CalculaChroniclesOfTheAlgorithmicKingdom.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@
import ui.Ui;
import Math.*;

import java.util.ArrayList;
import java.util.Map;
import java.util.Scanner;


public class CalculaChroniclesOfTheAlgorithmicKingdom {
public static int currentOn;
public static ArrayList<AMap> storedMaps = new ArrayList<>();
public static void main(String[] args) {
new CalculaChroniclesOfTheAlgorithmicKingdom().startGame();
}

public void startGame() {
Scanner in = new Scanner(System.in);

PlayerStatus playerStatus = new PlayerStatus(100, 0, 0);
TextBox textBox = new TextBox();
Parser parser = new Parser();
Expand All @@ -31,32 +35,33 @@ public void startGame() {
map.initPlayerLocation(0, 0);
map.placeMonsterInTheMap(2, 3);
textBox.initTextBox();
map.addMaps(map);
currentOn = 0;
storedMaps.add(map);
assert storedMaps.size() == 1;

ui.printPlayerStatus(playerStatus);
ui.printMap(map);
ui.printTextBox(textBox);
ui.printMap(storedMaps.get(currentOn));
System.out.println("Type 'h' to get the help menu.");

Command userCommand;
while (true) {
String userCommandText = in.nextLine();

userCommand = parser.parseCommand(userCommandText);
setUserCommand(userCommand, map, playerStatus, textBox);
setUserCommand(userCommand, storedMaps.get(currentOn), playerStatus, textBox);

if (!(storedMaps.get(currentOn) instanceof FirstMap) && userCommand instanceof MapMoveCommand) {
System.out.println("Invalid Command");

if (!(map instanceof FirstMap) && userCommand instanceof MapMoveCommand) {
textBox.setNextError("Invalid Command");
} else if (userCommand.getCommandDescription().equals("FIGHT!")){
userCommand.execute(in);
} else {
userCommand.execute();
}
map.storeMaps(0, map);
map = userCommand.getCurrentMap();

if (!userCommand.getCommandDescription().equals("HelpMe!!")) {
ui.printPlayerStatus(playerStatus);
ui.printMap(map);
ui.printMap(storedMaps.get(currentOn));
ui.printTextBox(textBox);
}

Expand Down
9 changes: 2 additions & 7 deletions src/main/java/map/AMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.Scanner;

public abstract class AMap {
protected static ArrayList<AMap> storedMaps = new ArrayList<>();

protected int width;
protected int height;
protected ArrayList<ArrayList<Character>> currentMap;
Expand Down Expand Up @@ -129,11 +129,6 @@ public int getPlayerX() {
public int getPlayerY() {
return playerY;
}
public void storeMaps(int index, AMap map){
storedMaps.set(index, map);
}
public void addMaps(AMap map){
storedMaps.add(map);
}


}
Loading