diff --git a/src/battle/Battle.java b/src/battle/Battle.java index 96c7ce7..95a8503 100644 --- a/src/battle/Battle.java +++ b/src/battle/Battle.java @@ -13,7 +13,7 @@ public static void main(String[] args) { boolean running = true; while (running) { enemy = new Enemy(); - //enemy.getInfo(); + enemy.getInfo(); enemy.takeDamage(player.getStrength()); enemy.stillAlive(); diff --git a/src/battle/Enemy.java b/src/battle/Enemy.java index e0a287b..a07ea92 100644 --- a/src/battle/Enemy.java +++ b/src/battle/Enemy.java @@ -11,76 +11,44 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; -public class Enemy { - - public Enemy() { - - try { - - File fXmlFile = new File("enemy.xml"); - DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); - Document doc = dBuilder.parse(fXmlFile); - - NodeList nList = doc.getElementsByTagName("Enemy"); - - Random random = new Random(); +public class Enemy extends Entity{ - Node nNode = nList.item(random.nextInt(nList.getLength())); - - if (nNode.getNodeType() == Node.ELEMENT_NODE) { - - Element eElement = (Element) nNode; - - name = eElement.getElementsByTagName("Name").item(0).getTextContent(); - health = Integer.parseInt(eElement.getElementsByTagName("Health").item(0).getTextContent()); - strength = Integer.parseInt(eElement.getElementsByTagName("Strength").item(0).getTextContent()); - exp = Integer.parseInt(eElement.getElementsByTagName("Exp").item(0).getTextContent()); + public Enemy() { + //super(name, health, strength, exp); - } - } catch (Exception e) { - e.printStackTrace(); + try { + + File fXmlFile = new File("enemy.xml"); + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + Document doc = dBuilder.parse(fXmlFile); + + NodeList nList = doc.getElementsByTagName("Enemy"); + + Random random = new Random(); + + Node nNode = nList.item(random.nextInt(nList.getLength())); + + if (nNode.getNodeType() == Node.ELEMENT_NODE) { + + Element eElement = (Element) nNode; + + name = eElement.getElementsByTagName("Name").item(0).getTextContent(); + health = Integer.parseInt(eElement.getElementsByTagName("Health").item(0).getTextContent()); + strength = Integer.parseInt(eElement.getElementsByTagName("Strength").item(0).getTextContent()); + exp = Integer.parseInt(eElement.getElementsByTagName("Exp").item(0).getTextContent()); + + } + } catch (Exception e) { + e.printStackTrace(); + } + } + public void stillAlive() { + if (this.getHealth() <=0){ + System.out.println("You defeated " + this.getName() + "!"); } } - - private String name; - private int health; - private int strength; - private int exp; - - - public String getName() { - return name; - } - - public int getHealth() { - return health; - } - - public int getStrength() { - return strength; - } - - public int getExp() { - return exp; - } - - public void getInfo() { - System.out.println("Enemy: " + getName() + " | Health: " + getHealth() + " | Strength: " + getStrength()); - - } - - public void takeDamage(int strength2) { - this.health = getHealth() - strength2; - } - public void stillAlive() { - if (this.health <=0){ - System.out.println("You have defeated: " + getName()); - } - - } -} diff --git a/src/battle/Entity.java b/src/battle/Entity.java new file mode 100644 index 0000000..85a28f3 --- /dev/null +++ b/src/battle/Entity.java @@ -0,0 +1,43 @@ +package battle; + +public class Entity { + public Entity(){ + + } + + protected String name; + protected int health; + protected int strength; + protected int exp; + + public String getName() { + return name; + } + + public int getHealth() { + return health; + } + + public int getStrength() { + return strength; + } + + public int getExp() { + return exp; + } + + public void getInfo() { + System.out.println("Name: " + getName() + " | Health: " + getHealth() + " | Strength: " + getStrength()); + + } + + public void takeDamage(int strength2) { + this.health = getHealth() - strength2; + + } + + public void stillAlive() { + } + +} + diff --git a/src/battle/Player.java b/src/battle/Player.java index fc346c4..a35d9fd 100644 --- a/src/battle/Player.java +++ b/src/battle/Player.java @@ -1,52 +1,17 @@ package battle; -public class Player{ - - public Player(String name, int health, int strength, int exp){ +public class Player extends Entity{ + + public Player(String name, int health, int strength, int exp) { this.name = name; this.health = health; this.strength = strength; this.exp = exp; - } - - private String name; - private int health; - private int strength; - private int exp; - - public String getName() { - return name; - } - - public int getHealth() { - return health; - } - - public int getStrength() { - return strength; - } - - public int getExp() { - return exp; - } - - public void getInfo() { - System.out.println("Name: " + getName() + " | Health: " + getHealth() + " | Strength: " + getStrength()); - - } - - public void takeDamage(int strength2) { - this.health = getHealth() - strength2; - - } - + } public void stillAlive() { - if (this.health <=0){ - System.out.println("You died! How Lame"); + if (this.getHealth() <=0){ + System.out.println("You died! How Lame"); } - } - - }