Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need assistance with implementation of this java class Zombies can only attack after closing the distance (once they reach a distance of 0, after having

Need assistance with implementation of this java class

Zombies can only attack after closing the distance (once they reach a distance of 0, after having started 4 spaces away), and may only attack whomever is in front. Only the hero at the front may act, though each has different actions/targets. The zombies come in the following varieties:

CHUDs: Slow (can only move 1 space at a time) Weak (can only inflict 1HP damage per attack) Always hungry (can attack each turn once within range)

I need asistance with the CHUD class on the implementation if possible, Since if I have an understanding of doing this I can implement the rest

the rules for the CHUD zombie are above.

Apocalypse.java

********************************************

package apocalypse;

/** * Represents the basic functionality of being reanimated. * * All Undead starts at a distance of 4, and they can only attack once they get * to a distance of 0. Instead of HP, they have 'limbs'. A zombie with no limbs * isn't terribly scary anymore (so you can treat it as re-deadened). */ public interface Undead {

/** * @return distance (4 at furthest; 0 at closest) */ public int getDistance();

/** * Should only apply in cases where the Undead has a distance of zero, and * attacks the Survivor in the front, but that's up to the main program to * enforce. * * @param victim Owner of tasty, tasty brains * @return Something descriptive of how the attack went */ public String chomp(Survivor victim);

/** * Closes the distance. * * @return Whatever sound it makes while shambling */ public String advance();

/** * Accessor for pseudo-hitpoints * * @return Remaining unhealth */ public int getLimbs();

/** * Equivalent of injuring. Subtracts 'force' from number of limbs. No, a * zombie can't have 'negative limbs' left. * * @param force How many limbs to 'liberate' */ public void deLimb(int force);

/** * Zombies only attack when hungry. Everyone knows that. * * @return Hunger state */ public boolean getHungry();

/** * Just flavour text. * * @see Trioxin * @return Silliness */ default public String speak() { return getHungry() ? "braaainsss" : "*groans*"; }

/** * Lets you identify the 'type' easily. * * @return Type (of Undead) */ public String getLabel();

/** * Convenience for rendering the battlefield * * @return Single letter to reflect type (C/D/T) */ static public String render(Undead u) { String padding = " "; return u == null ? " " : padding.substring(0, 4 - u.getDistance()) + u.toString() + padding.substring(0, u.getDistance()); } }

Horde.java

*********************************

package apocalypse;

/** * Horde class * Note that we don't bother instantiating this one. Everything's static, so * we can just use everything directly. * *Before use, remember to prime it with 'populate'. * @see CHUD * @see Deadite * @see Trioxin */ public class Horde { private static int remaining=0; static Undead[] boo; public static int getRemaining() { return remaining; } /** * For initializing the horde. * * @param remaining How many Undeadies can be summoned * @param breadth How many can be on the field at any given time */ static void populate(int remaining, int breadth) { Horde.remaining=remaining; Horde.boo=new Undead[breadth]; for (int i=0;i

public static void replenish(int pos) { if (Horde.remaining<=0) { if (Horde.boo.length<=1) { Horde.boo=new Undead[0]; } else { Undead[] temp=new Undead[Horde.boo.length-1]; for (int i=0;i

Survivor.java

************************

package apocalypse; public abstract class Survivor { final static int maxHP=5; final static String victory="YAY!"; //Probably not necessary; just used if attempting to act after victory private int hitpoints=Survivor.maxHP; //?package-private to allow for healing? String name; //For at least the Medic, I'd suggest adding an instance variable to keep //track of the List of Survivors /** * @return What happened */ abstract public String act(); /** * @return Duh. */ public int getHP() { return hitpoints; } /** * Fun fact: if you try to 'injure' by a negative value, it'll heal! * Wonder if that could be useful... * @param HP delta value */ public void injure(int amt) { this.hitpoints-=amt; this.hitpoints=this.hitpoints<0?0:this.hitpoints>Survivor.maxHP?Survivor.maxHP:this.hitpoints; } /** * Just return "Sniper", "Medic", etc. * It isn't unheard of to have something like this when there are multiple * possible implementations, to easily discern between the types (without * needing to resort to reflection) */ abstract public String getRole(); /** * Does what it says on the box * @return A spaghetti dinner (whaddaya think?!?) */ public String getName() { return name; } /** * Overridden String representation of a Survivor. * (Feel free to override this further, though I don't know why you would */ public String toString() { return '['+getName()+':'+getRole()+'|'+getHP()+']'; } }

Undead.java

**************************

package apocalypse;

/** * Represents the basic functionality of being reanimated. * * All Undead starts at a distance of 4, and they can only attack once they get * to a distance of 0. * Instead of HP, they have 'limbs'. A zombie with no limbs isn't terribly * scary anymore (so you can treat it as re-deadened). * * @see CHUD * @see Deadite * @see Trioxin * @see Horde */ public interface Undead { /** * @return distance (4 at furthest; 0 at closest) */ public int getDistance(); /** * The primary joy of the living dead: chowing down on the living * not-yet-dead! * * Should only apply in cases where the Undead has a distance of zero, and * attacks the Survivor in the front, but that's up to the main program * to enforce. */ public String chomp(Survivor victim); /** * Closes the distance. * * @return Whatever sound it makes while shambling */ public String advance(); /** * Accessor for pseudo-hitpoints * @return Remaining unhealth */ public int getLimbs(); /** * Equivalent of injuring. Subtracts 'force' from number of limbs. * No, a zombie can't have 'negative limbs' left. * * @param force How many limbs to 'liberate' */ public void deLimb(int force); public boolean getHungry();

default public String speak() { return getHungry()?"braaainsss":"*groans*"; } public String getLabel(); /** * Convenience for rendering the battlefield * @return Single letter to reflect type (C/D/T) */ static public String render(Undead u) { String padding=" "; return u==null? " " : padding.substring(0,4-u.getDistance())+u.toString()+padding.substring(0,u.getDistance()) ; } }

CHUD.java

**************** package apocalypse;

public class CHUD implements Undead {

public CHUD() {

}

@Override public int getDistance() {

}

@Override public String chomp(Survivor victim) { }

@Override public String advance() { }

@Override public int getLimbs() { }

@Override public void deLimb(int force) { }

@Override public boolean getHungry() { }

@Override public String getLabel() { }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data, Mining, And Analytics Components Of Strategic Decision Making

Authors: Stephan Kudyba

1st Edition

1466568704, 9781466568709

More Books

Students also viewed these Databases questions

Question

Draw a tree diagram picturing a binomial experiment of four trials.

Answered: 1 week ago