forked from nus-cs2113-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from BestDownLoader365/version_1+fix_bug
Complete First Version
- Loading branch information
Showing
16 changed files
with
235 additions
and
135 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,39 @@ | ||
package command; | ||
|
||
import textbox.*; | ||
import map.AMap; | ||
|
||
public abstract class Command { | ||
|
||
public abstract class Command { | ||
protected TextBox textBox; | ||
protected PlayerStatus playerStatus; | ||
protected String commandDescription; | ||
protected AMap currentMap; | ||
|
||
public abstract void execute(); | ||
public Command(){ | ||
|
||
public Command() { | ||
commandDescription = "Impossible"; | ||
currentMap = null; | ||
} | ||
public String getCommandDescription(){ | ||
|
||
public String getCommandDescription() { | ||
return commandDescription; | ||
} | ||
public AMap getCurrentMap(){ | ||
|
||
public AMap getCurrentMap() { | ||
return currentMap; | ||
} | ||
|
||
public void setCurrentMap(AMap givenMap){ | ||
public void setCurrentMap(AMap givenMap) { | ||
currentMap = givenMap; | ||
} | ||
|
||
public void setPlayerStatus(PlayerStatus playerStatus) { | ||
this.playerStatus = playerStatus; | ||
} | ||
|
||
public void setTextBox(TextBox textBox){ | ||
this.textBox = textBox; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package command; | ||
|
||
import ui.Ui; | ||
|
||
public class HelpCommand extends Command { | ||
public HelpCommand(){ | ||
commandDescription = "HelpMe!!"; | ||
} | ||
@Override | ||
public void execute() { | ||
Ui ui = new Ui(); | ||
ui.printHelpMenu(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,6 @@ | |
public class QuitCommand extends Command{ | ||
@Override | ||
public void execute() { | ||
|
||
System.exit(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
package command.fight; | ||
|
||
import command.Command; | ||
import map.*; | ||
|
||
public class RunningCommand extends Command { | ||
public RunningCommand() { | ||
commandDescription = "RUN!"; | ||
} | ||
@Override | ||
public void execute(){ | ||
|
||
AMap initMap = new FirstMap(); | ||
initMap.initMap(30, 10); | ||
initMap.initPlayerLocation(0, 0); | ||
initMap.placeMonsterInTheMap(2, 3); | ||
currentMap = initMap; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,26 @@ | ||
package command.mapmove; | ||
|
||
import InteractableEntity.*; | ||
import map.*; | ||
import map.BattleInterface.BattleInterface; | ||
|
||
public class InteractingCommand extends MapMoveCommand { | ||
@Override | ||
public void execute() { | ||
String entityInteractedWith = currentMap.handleInteract(); | ||
System.out.println(entityInteractedWith); | ||
AMap battleMap; | ||
switch (entityInteractedWith) { | ||
case "@": | ||
InteractableEntity monster = new Enemy(10, 10); | ||
battleMap = new BattleInterface(playerStatus, textBox, monster); | ||
battleMap.initMap(30, 10); | ||
currentMap = battleMap; | ||
break; | ||
default: | ||
battleMap = new BattleInterface(null, null, null); | ||
break; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,110 +1,113 @@ | ||
package map; | ||
import command.Command; | ||
|
||
import java.util.ArrayList; | ||
|
||
public abstract class AMap { | ||
protected static ArrayList<AMap> storedMap; | ||
protected int width; | ||
protected int height; | ||
protected ArrayList<ArrayList<Character>> storedMap; | ||
protected ArrayList<ArrayList<Character>> currentMap; | ||
protected int playerX; | ||
protected int playerY; | ||
protected String mapName; | ||
|
||
|
||
|
||
public void initMap(int givenWidth, int givenHeight){ | ||
public void initMap(int givenWidth, int givenHeight) { | ||
this.width = givenWidth; | ||
this.height = givenHeight; | ||
this.storedMap = new ArrayList<>(height); | ||
this.currentMap = new ArrayList<>(height); | ||
|
||
for (int i = 0; i < height; i += 1){ | ||
for (int i = 0; i < height; i += 1) { | ||
ArrayList<Character> row = new ArrayList<>(width); | ||
for (int j = 0; j < width; j += 1){ | ||
for (int j = 0; j < width; j += 1) { | ||
row.add('.'); | ||
} | ||
storedMap.add(row); | ||
currentMap.add(row); | ||
} | ||
} | ||
|
||
|
||
public ArrayList<ArrayList<Character>> getStoredMap() { | ||
return storedMap; | ||
public ArrayList<ArrayList<Character>> getCurrentMap() { | ||
return currentMap; | ||
} | ||
|
||
public void initPlayerLocation(int x, int y){ | ||
if (x >= 0 && x < width && y >= 0 && y < height){ | ||
storedMap.get(y).set(x, 'P'); | ||
public void initPlayerLocation(int x, int y) { | ||
if (x >= 0 && x < width && y >= 0 && y < height) { | ||
currentMap.get(y).set(x, 'P'); | ||
this.playerX = x; | ||
this.playerY = y; | ||
} | ||
} | ||
|
||
|
||
public void movePlayerUpOne(){ | ||
if (this.playerY - 1 >= 0){ | ||
storedMap.get(playerY).set(playerX, '.'); | ||
storedMap.get(playerY - 1).set(playerX, 'P'); | ||
public void movePlayerUpOne() { | ||
if (this.playerY - 1 >= 0) { | ||
currentMap.get(playerY).set(playerX, '.'); | ||
currentMap.get(playerY - 1).set(playerX, 'P'); | ||
this.playerY -= 1; | ||
} | ||
} | ||
|
||
|
||
public void movePlayerDownOne(){ | ||
if (this.playerY + 1 < height){ | ||
storedMap.get(playerY).set(playerX, '.'); | ||
storedMap.get(playerY + 1).set(playerX, 'P'); | ||
public void movePlayerDownOne() { | ||
if (this.playerY + 1 < height) { | ||
currentMap.get(playerY).set(playerX, '.'); | ||
currentMap.get(playerY + 1).set(playerX, 'P'); | ||
this.playerY += 1; | ||
} | ||
} | ||
|
||
|
||
public void movePlayerLeftOne(){ | ||
if (this.playerX - 1 >= 0){ | ||
storedMap.get(playerY).set(playerX, '.'); | ||
storedMap.get(playerY).set(playerX - 1, 'P'); | ||
public void movePlayerLeftOne() { | ||
if (this.playerX - 1 >= 0) { | ||
currentMap.get(playerY).set(playerX, '.'); | ||
currentMap.get(playerY).set(playerX - 1, 'P'); | ||
this.playerX -= 1; | ||
} | ||
} | ||
|
||
|
||
public void movePlayerRightOne(){ | ||
if (this.playerY + 1 < width){ | ||
storedMap.get(playerY).set(playerX, '.'); | ||
storedMap.get(playerY).set(playerX + 1, 'P'); | ||
public void movePlayerRightOne() { | ||
if (this.playerY + 1 < width) { | ||
currentMap.get(playerY).set(playerX, '.'); | ||
currentMap.get(playerY).set(playerX + 1, 'P'); | ||
this.playerX += 1; | ||
} | ||
} | ||
|
||
|
||
public ArrayList<ArrayList<Character>> getMap(){ | ||
return storedMap; | ||
public ArrayList<ArrayList<Character>> getMap() { | ||
return currentMap; | ||
} | ||
|
||
public String handleInteract() { | ||
if (playerY > 0 && storedMap.get(playerY - 1).get(playerX) != '.') { | ||
return String.valueOf(storedMap.get(playerY - 1).get(playerX)); | ||
if (playerY > 0 && currentMap.get(playerY - 1).get(playerX) != '.') { | ||
return String.valueOf(currentMap.get(playerY - 1).get(playerX)); | ||
} | ||
|
||
if (playerX < storedMap.get(0).size() - 1 && storedMap.get(playerY).get(playerX + 1) != '.') { | ||
return String.valueOf(storedMap.get(playerY).get(playerX + 1)); | ||
if (playerX < currentMap.get(0).size() - 1 && currentMap.get(playerY).get(playerX + 1) != '.') { | ||
return String.valueOf(currentMap.get(playerY).get(playerX + 1)); | ||
} | ||
|
||
if (playerY < storedMap.size() - 1 && storedMap.get(playerY + 1).get(playerX) != '.') { | ||
return String.valueOf(storedMap.get(playerY + 1).get(playerX)); | ||
if (playerY < currentMap.size() - 1 && currentMap.get(playerY + 1).get(playerX) != '.') { | ||
return String.valueOf(currentMap.get(playerY + 1).get(playerX)); | ||
} | ||
|
||
if (playerX > 0 && storedMap.get(playerY).get(playerX - 1) != '.') { | ||
return String.valueOf(storedMap.get(playerY).get(playerX - 1)); | ||
if (playerX > 0 && currentMap.get(playerY).get(playerX - 1) != '.') { | ||
return String.valueOf(currentMap.get(playerY).get(playerX - 1)); | ||
} | ||
return "no interaction"; | ||
} | ||
|
||
public void placeMonsterInTheMap(int x, int y) { | ||
currentMap.get(y).set(x, '@'); | ||
} | ||
|
||
public int getPlayerX(){ | ||
public int getPlayerX() { | ||
return playerX; | ||
} | ||
|
||
public int getPlayerY(){ | ||
public int getPlayerY() { | ||
return playerY; | ||
} | ||
|
||
} |
Oops, something went wrong.