From 1232f150c966eea3b9e148117efc5334b110b23b Mon Sep 17 00:00:00 2001 From: jslightham <31053827+jslightham@users.noreply.github.com> Date: Fri, 31 May 2019 23:15:01 -0400 Subject: [PATCH] bleeding and bandages --- data/enemies.dat | 4 +- data/rooms.dat | 6 +-- data/words.dat | 4 +- src/com/bayviewglen/zork/Combat.java | 6 ++- src/com/bayviewglen/zork/Entities/Player.java | 11 +++- src/com/bayviewglen/zork/Game.java | 50 ++++++++++++++++++- src/com/bayviewglen/zork/Items/Bandage.java | 9 ++++ 7 files changed, 80 insertions(+), 10 deletions(-) create mode 100644 src/com/bayviewglen/zork/Items/Bandage.java diff --git a/data/enemies.dat b/data/enemies.dat index 668d236..1390ea3 100644 --- a/data/enemies.dat +++ b/data/enemies.dat @@ -1,8 +1,8 @@ Enemy Name: Henry Pellatt Description: The owner of the Castle -Starting Room: Apple Hallway +Starting Room: Billiard Room Damage Given: 25 -Loot: Crowbar +Loot: Point Enemy Name: Lady Pellatt Description: The wife to the owner of the Castle Starting Room: Lady Pellatt's Bedroom diff --git a/data/rooms.dat b/data/rooms.dat index 9358922..b624ec4 100644 --- a/data/rooms.dat +++ b/data/rooms.dat @@ -114,7 +114,7 @@ Room name: Sir Henry Mill Pellatt's Bathroom Room Description: You are now in Sir Henry Mill Pellatt's Bathroom. The floor mat is still quite wet.
Perhaps someone just took a shower. A half-empty shaving cream bottle lies on the counter, along with a toothbrush and some toothpaste. Locked: false Boarded: false -Items: Shavingcream, Toothbrush, Toothpaste +Items: Shavingcream, Toothbrush, Toothpaste, Bandage Riddler: Exit Rooms: N-Sir Henry Mill Pellatt's Bedroom @@ -122,7 +122,7 @@ Room name: Linen Closet Room Description: A whiff of lavender-scented laundry detergent enters your nostrils as you step into
a dark room. Ah, you must be in the Linen Closet. No one really comes in here other than the servants. I'm pretty sure Sir Pellatt and
Lady Pellatt don't even know this room exists. Locked: false Boarded: false -Items: Clothes +Items: Clothes, Bandage Riddler: Exit Rooms: E-Sir Henry Mill Pellatt's Bedroom, W-Guest Bedroom, S-Willow Bedroom @@ -202,7 +202,7 @@ Room name: Supply Closet Room Description: You are in the Supply Closet. A mop, bucket and a few towels lay on the ground. The space is quite small
and can only hold around 3 people. Nothing interesting seems to be happening in here. Locked: false Boarded: false -Items:Mop,Bucket,Towels +Items:Mop,Bucket,Towels, Robes Riddler: Exit Rooms: E-Silver Stairs (1st Floor), S-Kitchen, N-Serving and Breakfast Room diff --git a/data/words.dat b/data/words.dat index 08032e7..c0a2fe5 100644 --- a/data/words.dat +++ b/data/words.dat @@ -65,4 +65,6 @@ keyboard, item lightbulb, item craft, verb batteringram, item -ladypellatt, enemy \ No newline at end of file +ladypellatt, enemy +use, verb +bandage, item \ No newline at end of file diff --git a/src/com/bayviewglen/zork/Combat.java b/src/com/bayviewglen/zork/Combat.java index fa38bc2..9cdbaa5 100644 --- a/src/com/bayviewglen/zork/Combat.java +++ b/src/com/bayviewglen/zork/Combat.java @@ -36,7 +36,7 @@ public class Combat { System.out.println("You missed!"); - }else if(rand<0.15) { + }else if(rand<0.20) { enemy.setHealth(enemy.getHealth()-object.getDamage()*1.5); if(enemy.getHealth() < 0) enemy.setHealth(0); @@ -68,11 +68,13 @@ public class Combat { } else if(rand<0.1) { System.out.println(enemy.getName() + " missed!"); - }else if(rand < 0.15) { + }else if(rand < 0.50) { player.setHealth(player.getHealth()-enemy.getDamage()*1.5); if(player.getHealth() < 0) player.setHealth(0); System.out.println(enemy.getName() + " hit you with a critical hit, doing " + enemy.getDamage()*1.5 + " damage! Your health is now " + player.getHealth() + "%"); + System.out.println("You are now bleeding."); + player.setBleeding(true); } else { player.setHealth(player.getHealth()-enemy.getDamage()); diff --git a/src/com/bayviewglen/zork/Entities/Player.java b/src/com/bayviewglen/zork/Entities/Player.java index 1f6701e..d869a81 100644 --- a/src/com/bayviewglen/zork/Entities/Player.java +++ b/src/com/bayviewglen/zork/Entities/Player.java @@ -9,6 +9,7 @@ public class Player extends Entity{ private ArrayList inventory = new ArrayList(); private final int INVENTORY_CAPACITY = 120; private int currentInventoryWeight; + private boolean isBleeding; public Player() { super(100.0, 100.0); @@ -40,10 +41,18 @@ public class Player extends Entity{ } public void eat() { - health+=5; + health+=25; if(health > 100.0) { health = 100.0; } } + + public void setBleeding(boolean bleeding) { + this.isBleeding = bleeding; + } + + public boolean getBleeding() { + return isBleeding; + } } diff --git a/src/com/bayviewglen/zork/Game.java b/src/com/bayviewglen/zork/Game.java index c1a6329..f9be7a8 100644 --- a/src/com/bayviewglen/zork/Game.java +++ b/src/com/bayviewglen/zork/Game.java @@ -245,12 +245,28 @@ class Game { System.out.println( "Poof! You looked pretty banged up there, so I brought you back to the circle room. Your items are where you died."); player.setHealth(100.0); + player.setBleeding(false); + try { currentCombat.getEnemy().setHealth(100.0); currentCombat = null; + }catch (Exception e) { + + } } } } - + if(player.getBleeding()) { + player.setHealth(player.getHealth()-2); + System.out.println("You are bleeding. Find, and use bandages to stop bleeding."); + System.out.println("Your health is now " + player.getHealth() + "%"); + } + if(player.getHealth() <= 0) { + currentRoom = masterRoomMap.get("CIRCLE_ROOM"); + System.out.println( + "Poof! You looked pretty banged up there, so I brought you back to the circle room. Your items are where you died."); + player.setHealth(100.0); + player.setBleeding(false); + } Command command = parser.getCommand(); finished = processCommand(command); } @@ -589,6 +605,8 @@ class Game { } else { System.out.println("You do not have that weapon!"); } + }else { + System.out.println("Attack with what?"); } } break; @@ -637,6 +655,36 @@ class Game { System.out.println("Craft what?"); } break; + case "use": + if(command.hasItem()) { + Class clazz; + Item object; + try { + clazz = Class.forName( + "com.bayviewglen.zork.Items." + command.getItem().substring(0, 1).toUpperCase().trim() + + command.getItem().substring(1).trim()); + Constructor ctor = clazz.getConstructor(); + object = (Item) ctor.newInstance(); + if(!object.equals(new Bandage())) + throw new Exception(); + boolean hasBandage = false; + for(Item i : player.getInventory()) { + if(i.equals(new Bandage())) { + hasBandage = true; + } + } + if(hasBandage) { + System.out.println("You are no longer bleeding."); + player.setBleeding(false); + }else { + System.out.println("You do not have a bandage!"); + } + }catch (Exception e) { + System.out.println("You cannot use that item!"); + } + }else { + System.out.println("Use what?"); + } default: return false; } diff --git a/src/com/bayviewglen/zork/Items/Bandage.java b/src/com/bayviewglen/zork/Items/Bandage.java new file mode 100644 index 0000000..69d93cc --- /dev/null +++ b/src/com/bayviewglen/zork/Items/Bandage.java @@ -0,0 +1,9 @@ +package com.bayviewglen.zork.Items; + +public class Bandage extends CraftableItem{ + + public Bandage() { + super(98, "Bandage", "A bandage to stop bleeding", false, 100, 1); + super.addMaterial(new Robes()); + } +}