From cfc9741f19dcbfe01f796b8f542f12c62b63ba57 Mon Sep 17 00:00:00 2001
From: jslightham <31053827+jslightham@users.noreply.github.com>
Date: Fri, 31 May 2019 19:14:21 -0400
Subject: [PATCH] enemy drop loot on death
---
data/enemies.dat | 3 ++-
data/rooms.dat | 2 +-
.../bayviewglen/zork/Entities/Enemies/Enemy.java | 7 +++++++
src/com/bayviewglen/zork/Game.java | 16 +++++++++++++++-
4 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/data/enemies.dat b/data/enemies.dat
index 20db5aa..b147638 100644
--- a/data/enemies.dat
+++ b/data/enemies.dat
@@ -1,4 +1,5 @@
Enemy Name: Henry Pellatt
Description: The owner of the Castle
Starting Room: Circle Room
-Damage Given: 25
\ No newline at end of file
+Damage Given: 25
+Loot: Crowbar
\ No newline at end of file
diff --git a/data/rooms.dat b/data/rooms.dat
index ee27cde..17cc1d6 100644
--- a/data/rooms.dat
+++ b/data/rooms.dat
@@ -2,7 +2,7 @@ Room name: Circle Room
Room Description: You are in a circular room. The windows to the east are covered with boards that
let in just enough light to see. You spot a man in a tailored suit moving some crates around.
Locked: false
Boarded: false
-Items: Lightbulb,Candlestick
+Items: Lightbulb,Candlestick,Sword
Riddler: "Hello there. My name is Kevin and I am Sir Pellatt's butler. I understand that my master
Sir Pellatt has wrongfully imprisoned you. If you answer my riddle I can give you something to
help you with your escape - nothing comes for free you know!", "What goes moo?", "Cows", Lockpick
Exit Rooms: W-Apple Hallway
diff --git a/src/com/bayviewglen/zork/Entities/Enemies/Enemy.java b/src/com/bayviewglen/zork/Entities/Enemies/Enemy.java
index 1128342..bf5e804 100644
--- a/src/com/bayviewglen/zork/Entities/Enemies/Enemy.java
+++ b/src/com/bayviewglen/zork/Entities/Enemies/Enemy.java
@@ -7,6 +7,7 @@ public class Enemy extends Entity{
private String name;
private String description;
private String room;
+ private String loot;
private boolean blinded;
public Enemy(){
@@ -54,4 +55,10 @@ public class Enemy extends Entity{
public void setBlinded(boolean blinded) {
this.blinded = blinded;
}
+ public void setLoot(String loot) {
+ this.loot = loot;
+ }
+ public String getLoot() {
+ return loot;
+ }
}
diff --git a/src/com/bayviewglen/zork/Game.java b/src/com/bayviewglen/zork/Game.java
index 7dc9af3..9d17876 100644
--- a/src/com/bayviewglen/zork/Game.java
+++ b/src/com/bayviewglen/zork/Game.java
@@ -159,6 +159,9 @@ class Game {
// Read the Damage Given
int damageGiven = Integer.parseInt(enemyScanner.nextLine().split(":")[1].trim());
e.setDamageGiven(damageGiven);
+ // Read the Loot
+ String loot = enemyScanner.nextLine().split(":")[1].trim();
+ e.setLoot(loot);
}
}catch(Exception ex) {
}
@@ -224,7 +227,18 @@ class Game {
while (!finished) {
if(currentCombat != null) {
if(currentCombat.getEnemy().getHealth() <= 0.0) {
- System.out.println("You destroyed " + currentCombat.getEnemy().getName());
+ System.out.print("You destroyed " + currentCombat.getEnemy().getName() + "! ");
+ System.out.println(currentCombat.getEnemy().getName() + " seems to have dropped a " + currentCombat.getEnemy().getLoot());
+ Class> clazz;
+ Item object = null;
+ try {
+ clazz = Class.forName("com.bayviewglen.zork.Items." + currentCombat.getEnemy().getLoot().substring(0, 1).toUpperCase().trim() + currentCombat.getEnemy().getLoot().substring(1).trim());
+ Constructor> ctor = clazz.getConstructor();
+ object = (Item) ctor.newInstance();
+ }catch (Exception e) {
+
+ }
+ currentRoom.addItem(object);
masterEnemyMap.values().remove(currentRoom.getRoomName());
currentCombat = null;
}