Skip to content

Commit

Permalink
Merge pull request #43 from tannerlie/branch-enemy-display-jar-bug
Browse files Browse the repository at this point in the history
Fix enemy display issue on Jar
  • Loading branch information
tannerlie committed Mar 27, 2024
2 parents 07fc075 + 528fa33 commit 5662c74
Show file tree
Hide file tree
Showing 17 changed files with 176 additions and 42 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ checkstyle {
run{
enableAssertions = true
standardInput = System.in
enableAssertions = true
}
5 changes: 4 additions & 1 deletion src/main/java/InteractableEntity/Enemy.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public abstract class Enemy extends InteractableEntity{
protected int damage;
protected int defence;
protected int health;
protected String filePath;


public Enemy(int dmg, int def, int hp, int xCoordinate, int yCoordinate, int exp, int money){
Expand Down Expand Up @@ -43,5 +44,7 @@ public int getYCoordinate(){
return this.y;
}

public abstract void setHeight(int height);
public String getFilePath() {
return filePath;
}
}
5 changes: 4 additions & 1 deletion src/main/java/InteractableEntity/InteractableEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ public abstract class InteractableEntity {
protected int y;
protected int exp_dropped;
protected int money_dropped;

protected String name;

public abstract int getHealth();
Expand All @@ -14,6 +13,10 @@ public abstract class InteractableEntity {

public abstract int getDamage();

public abstract String getName();

public abstract String getFilePath();

public int getExp_dropped(){
return exp_dropped;
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/InteractableEntity/enemies/Centaur.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package InteractableEntity.enemies;

import InteractableEntity.Enemy;
import static filereader.filepath.EnemiesDesignFilePath.CENTAUR_PATH;

public class Centaur extends Enemy {
protected int height;

public Centaur(int dmg, int def, int hp, int xCoordinate, int yCoordinate, int exp, int money) {
super(dmg, def, hp, xCoordinate, yCoordinate, exp, money);
this.height = 12;
this.name = "Centaur";
this.filePath = CENTAUR_PATH;
}

@Override
public int getHeight() {
return height;
public String getName() {
return name;
}

@Override
public void setHeight(int height) {
this.height = height;
public void setName(String name) {
this.name = name;
}
}
22 changes: 22 additions & 0 deletions src/main/java/InteractableEntity/enemies/Demon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package InteractableEntity.enemies;

import InteractableEntity.Enemy;
import static filereader.filepath.EnemiesDesignFilePath.DEMON_PATH;

public class Demon extends Enemy {

public Demon(int dmg, int def, int hp, int xCoordinate, int yCoordinate, int exp, int money) {
super(dmg, def, hp, xCoordinate, yCoordinate, exp, money);
this.name = "Demon";
this.filePath = DEMON_PATH;
}

@Override
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
22 changes: 22 additions & 0 deletions src/main/java/InteractableEntity/enemies/Dragon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package InteractableEntity.enemies;

import InteractableEntity.Enemy;
import static filereader.filepath.EnemiesDesignFilePath.DRAGON_PATH;

public class Dragon extends Enemy {

public Dragon(int dmg, int def, int hp, int xCoordinate, int yCoordinate, int exp, int money) {
super(dmg, def, hp, xCoordinate, yCoordinate, exp, money);
this.name = "Dragon";
this.filePath = DRAGON_PATH;
}

@Override
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
14 changes: 7 additions & 7 deletions src/main/java/InteractableEntity/enemies/Goblin.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package InteractableEntity.enemies;

import InteractableEntity.Enemy;
import static filereader.filepath.EnemiesDesignFilePath.GOBLIN_PATH;

public class Goblin extends Enemy {
protected int height;

public Goblin(int dmg, int def, int hp, int xCoordinate, int yCoordinate, int exp, int money) {
super(dmg, def, hp, xCoordinate, yCoordinate, exp, money);
this.height = 12;
this.name = "Goblin";
this.filePath = GOBLIN_PATH;
}

@Override
public int getHeight() {
return height;
public String getName() {
return name;
}

@Override
public void setHeight(int height) {
this.height = height;
public void setName(String name) {
this.name = name;
}
}
22 changes: 22 additions & 0 deletions src/main/java/InteractableEntity/enemies/Gryphon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package InteractableEntity.enemies;

import InteractableEntity.Enemy;
import static filereader.filepath.EnemiesDesignFilePath.GRYPHON_PATH;

public class Gryphon extends Enemy {

public Gryphon(int dmg, int def, int hp, int xCoordinate, int yCoordinate, int exp, int money) {
super(dmg, def, hp, xCoordinate, yCoordinate, exp, money);
this.name = "Gryphon";
this.filePath = GRYPHON_PATH;
}

@Override
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
5 changes: 2 additions & 3 deletions src/main/java/command/mapmove/InteractingCommand.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package command.mapmove;

import InteractableEntity.*;
import InteractableEntity.enemies.Centaur;
import InteractableEntity.enemies.Goblin;
import InteractableEntity.enemies.*;
import map.*;
import map.BattleInterface.BattleInterface;
import static main.CalculaChroniclesOfTheAlgorithmicKingdom.*;
Expand All @@ -22,8 +21,8 @@ public void execute() {
case "@": //centaur
int x_pos = currentMap.getInteractX();
int y_pos = currentMap.getInteractY();
textBox.setNextDialogue("*the Centaur stares at you menacingly*");
InteractableEntity monster = new Centaur(10, 10, 10, x_pos, y_pos, 10, 10);
textBox.setNextDialogue("*the " + monster.getName() + " stares at you menacingly*");
battleMap = new BattleInterface(playerStatus, textBox, monster);
battleMap.initMap(30, monster.getHeight());
storedMaps.add(battleMap);
Expand Down
30 changes: 12 additions & 18 deletions src/main/java/filereader/FileReader.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package filereader;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import command.ErrorCommand;

import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;

public class FileReader {
private final String filePath;
Expand All @@ -17,25 +14,22 @@ public FileReader(String filePath) {
}

public ArrayList<ArrayList<Character>> readEnemyDesign() throws IOException {
File f = new File(filePath);
System.out.println(filePath);
if (f.exists()) {
System.out.println("exist");
} else {
boolean fe = f.createNewFile();
System.out.println("no exist");
}
Scanner in = new Scanner(f);
ArrayList<ArrayList<Character>> map = new ArrayList<>();
while (in.hasNextLine()) {
InputStream inputStream = getClass().getClassLoader().getResourceAsStream(filePath);
if (inputStream == null) {
throw new IllegalArgumentException("file not found at: " + filePath);
}
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = reader.readLine()) != null) {
ArrayList<Character> row = new ArrayList<>();
String line = in.nextLine();
for (int i = 0; i < line.length(); i += 1) {
row.add(line.charAt(i));
}
map.add(row);
}
reader.close();
inputStream.close();
return map;
}

}
7 changes: 5 additions & 2 deletions src/main/java/filereader/filepath/EnemiesDesignFilePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ public class EnemiesDesignFilePath {

public EnemiesDesignFilePath() {}

public final static String GOBLIN_PATH = "./src/main/java/InteractableEntity/enemiesDesign/goblin.txt";
public final static String CENTAUR_PATH = "./src/main/java/InteractableEntity/enemiesDesign/centaur.txt";
public final static String GOBLIN_PATH = "enemiesDesign/goblin.txt";
public final static String CENTAUR_PATH = "enemiesDesign/centaur.txt";
public final static String DEMON_PATH = "enemiesDesign/demon.txt";
public final static String GRYPHON_PATH = "enemiesDesign/gryphon.txt";
public final static String DRAGON_PATH = "enemiesDesign/dragon.txt";
}
5 changes: 2 additions & 3 deletions src/main/java/map/BattleInterface/BattleInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,11 @@ public void initMap(int givenWidth, int givenHeight) {
this.height = givenHeight;
this.currentMap = new ArrayList<>(height);

FileReader fileReader = new FileReader(EnemiesDesignFilePath.CENTAUR_PATH);
FileReader fileReader = new FileReader(currentEntity.getFilePath());
try {
currentMap = fileReader.readEnemyDesign();
} catch (Exception e) {
System.out.println(e);

// display exception, see how sihan wants to do.
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/enemiesDesign/demon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
| |
| , , /\ /\ |
| /( /\ )\ _\ \_/ /_ |
| |\_||_/| < \_ _/ > |
| \______/ \|0 0|/ |
| _\/_ _(_ ^ _)_ |
| ( () ) /`\|V"""V|/`\ |
| {} \ \_____/ / |
| () /\ )=( /\ |
| {} / \_/\=/\_/ \ |
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
39 changes: 39 additions & 0 deletions src/main/resources/enemiesDesign/dragon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
| / ) |
| ( |\ |
| /| \\ |
| // \\ |
| /// \| |
| /( \ )\ |
| \\ \_ //) |
| \\ :\__ /// |
| \\ ) // \ |
| \\: / // |/ |
| \\ / \ // \ |
| /) \ ___..-' (| \_| |
| // / _.' \ \ \ |
| /| \ \________ \ | / |
| (| _ _ __/ '-. ) /.' |
| \\ . '-.__ \_ / / \ |
| \\_'. > --._ '. \ / / / |
| \ \ \ \ \ .' /.' |
| \ \ '._ / \ ) / .' | |
| \ \_ \_ | .'_/ __/ |
| \ \ \_ | / / _/ \_ |
| \ \ / _.' / / \ |
| \ | /.' / .' '-,_ |
| \ \ .' _.'_/ \ |
| /\ /\ ) ___( /_.' \ | |
| | _\__// \ (.' _/ | | |
| \/_ __ /--'` , __/ / |
| (o ) /o) \ '. : \___.-'_/ \__/ |
| /:/: , ) : ( /_.'__/-'|_ _ / |
| /:/: __/\ > __,_.----.__\ / (/(/(/ |
| (_(,_/V .'/--' _/ __/ | / |
| VvvV //` _.-' _.' \ \ |
| n_n// (((/->/ | / |
| '--' ~=' \ | |
| | |_,,, |
| \ \ / |
| '.__) |
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
File renamed without changes.
15 changes: 15 additions & 0 deletions src/main/resources/enemiesDesign/gryphon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
| ______ |
| ______,---'__,---' |
| _,-'---_---__,---' |
| /_ (, ---____', |
| / ',, `, ,-' |
| ;/) ,',,_/,' |
| | /\ ,.'//\ |
| `-` \ ,,' `. |
| `', ,-- `. |
| '/ / | `, _ |
| //'',.\_ .\\ ,{==>- |
| __// __;_`- \ `;.__,;' |
| ((,--,) (((,------; `--' |
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

0 comments on commit 5662c74

Please sign in to comment.