Skip to content

Commit

Permalink
Merge pull request #14 from BestDownLoader365/version_1+fix_bug
Browse files Browse the repository at this point in the history
Complete First Version
  • Loading branch information
BestDownLoader365 committed Mar 18, 2024
2 parents 818b0d3 + b698b4d commit be32295
Show file tree
Hide file tree
Showing 16 changed files with 235 additions and 135 deletions.
20 changes: 0 additions & 20 deletions src/main/java/BattleInterface/BattleInterface.java

This file was deleted.

4 changes: 1 addition & 3 deletions src/main/java/InteractableEntity/Enemy.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
public class Enemy extends InteractableEntity{
protected int damage;
protected int defence;
protected String currentImage;

public Enemy(int dmg, int def, String img){
public Enemy(int dmg, int def){
this.damage = dmg;
this.defence = def;
this.currentImage = img;
}
}
25 changes: 20 additions & 5 deletions src/main/java/command/Command.java
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;
}
}
14 changes: 14 additions & 0 deletions src/main/java/command/HelpCommand.java
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();
}
}
2 changes: 1 addition & 1 deletion src/main/java/command/QuitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
public class QuitCommand extends Command{
@Override
public void execute() {

System.exit(0);
}
}
2 changes: 2 additions & 0 deletions src/main/java/command/fight/FightingCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package command.fight;

import command.Command;
import map.AMap;
import map.FirstMap;

public class FightingCommand extends Command {
public FightingCommand() {
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/command/fight/RunningCommand.java
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;
}
}
17 changes: 17 additions & 0 deletions src/main/java/command/mapmove/InteractingCommand.java
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;
}

}
}
1 change: 0 additions & 1 deletion src/main/java/command/mapmove/MovingDownwardCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ public class MovingDownwardCommand extends MapMoveCommand {
@Override
public void execute() {
currentMap.movePlayerDownOne();

}
}
33 changes: 25 additions & 8 deletions src/main/java/main/CalculaChroniclesOfTheAlgorithmicKingdom.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main;

import command.Command;
import map.FirstMap;
import map.*;
import parser.Parser;
import textbox.PlayerStatus;
import textbox.TextBox;
Expand All @@ -17,21 +17,38 @@ public void startGame() {
PlayerStatus playerStatus = new PlayerStatus(100, 0, 0);
TextBox textBox = new TextBox();
Parser parser = new Parser();
FirstMap map = new FirstMap();

AMap map = new FirstMap();
Ui ui = new Ui();

map.initMap(30, 10);
map.initPlayerLocation(0,0);
map.initPlayerLocation(0, 0);
map.placeMonsterInTheMap(2, 3);
textBox.initTextBox();

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

Command userCommand;
while (true) {
String userCommandText = ui.readInCommand();
String userCommandText = parser.readInCommand();
userCommand = parser.parserCommand(userCommandText);
userCommand.setCurrentMap(map);
setUserCommand(userCommand, map, playerStatus, textBox);

userCommand.execute();
ui.printPlayerStatus(playerStatus);
ui.printMap(map);

map = userCommand.getCurrentMap();
if (!userCommand.getCommandDescription().equals("HelpMe!!")) {
ui.printPlayerStatus(playerStatus);
ui.printMap(map);
}
textBox.nextTextBoxBasedOnMapAndCommand(userCommand, map);
}
}

private static void setUserCommand(Command userCommand, AMap map, PlayerStatus playerStatus, TextBox textBox) {
userCommand.setCurrentMap(map);
userCommand.setPlayerStatus(playerStatus);
userCommand.setTextBox(textBox);
}
}
87 changes: 45 additions & 42 deletions src/main/java/map/AMap.java
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;
}

}
Loading

0 comments on commit be32295

Please sign in to comment.