Using Java
You are part of a team working on a new role playing game. Your part is to design and create the classes for the hierarchy of game objects (such as trees, walls, zombies, aliens, and good guys. You are to draw a complete class diagram that shows the entire hierarchy of your classes. For each class, come up with suitable methods based on the type of object. You also are to create a program called Assignment4 that tests the objects in a new role playing game.
You are to design a class to represent each type of game object. All objects should have fields for the following data:
· name
· location
The stationary objects (rooms, trees and walls) are game objects and should have additional fields for the following data:
· damagePoints
The collectable objects (coins, weapons, and health potions) are game objects and should have additional fields for the following data:
· value
· type (an enum with choices such COINS, HEALTH_POTION, AXE, SWORD, MACE, MAGIC_WAND, BOMB)
The moveable objects are game objects and should have additional fields for the following data:
· health
· direction
· speed
The bad guy objects (zombies and aliens) are moveable objects and should have additional fields for the following data:
· meanFactor
· defeatPoints
The good guy objects (warriers, wizards, and hobbits) are moveable objects and should have additional fields for the following data:
· strength
· intelligence
· backPack (ArrayList of collectable objects)
The main program (aka test program) should build an ArrayList of stationary objects and an ArrayList of moveable objects. It should build an ArrayList of collectable objects for each good guy’s backpack. The main program should go through all objects in each ArrayList and call their common methods (e.g., display(), move(), fight(), etc.).
Expert Answer
import java.util.ArrayList;
abstract class GameObjects {
protected String name;
protected String location;
public String getLocation() {
return location;
}
public GameObjects(String name, String location) {
super();
this.name = name;
this.location = location;
}
public void setLocation(String location) {
this.location = location;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
class StationaryObjects extends GameObjects {
protected int damagePoints;
public int getDamagePoints() {
return damagePoints;
}
public StationaryObjects(String name, String location, int damagePoints) {
super(name, location);
this.damagePoints = damagePoints;
}
public void setDamagePoints(int damagePoints) {
this.damagePoints = damagePoints;
}
}
class MoveableObjects extends GameObjects {
protected int speed;
protected int health;
protected String direction;
public MoveableObjects(String name, String location, int speed, int health, String direction) {
super(name, location);
this.speed = speed;
this.health = health;
this.direction = direction;
}
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
public int getHealth() {
return health;
}
public void setHealth(int health) {
this.health = health;
}
public String getDirection() {
return direction;
}
public void setDirection(String direction) {
this.direction = direction;
}
}
class CollectableObjects extends GameObjects {
protected int value;
protected Type type;
public enum Type {
COIN,
HEALTH_POTION,
AXE,
SORWD,
MACE,
BOMB;
}
public CollectableObjects(String name, String location, int value, Type type) {
super(name, location);
this.value = value;
this.type = type;
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
}
class GoodGuy extends MoveableObjects {
protected int strength;
protected int intelligence;
protected ArrayList<CollectableObjects> backpack;
public GoodGuy(String name, String location, int speed, int health, String direction, int strength,
int intelligence, ArrayList<CollectableObjects> backpack) {
super(name, location, speed, health, direction);
this.strength = strength;
this.intelligence = intelligence;
this.backpack = backpack;
}
public int getStrength() {
return strength;
}
public void setStrength(int strength) {
this.strength = strength;
}
public int getIntelligence() {
return intelligence;
}
public void setIntelligence(int intelligence) {
this.intelligence = intelligence;
}
public ArrayList<CollectableObjects> getBackpack() {
return backpack;
}
public void setBackpack(ArrayList<CollectableObjects> backpack) {
this.backpack = backpack;
}
}
class BadGuy extends MoveableObjects {
protected int defeatPoint;
protected int meanFactors;
public BadGuy(String name, String location, int speed, int health, String direction, int defeatPoint,
int meanFactors) {
super(name, location, speed, health, direction);
this.defeatPoint = defeatPoint;
this.meanFactors = meanFactors;
}
public int getDefeatPoint() {
return defeatPoint;
}
public void setDefeatPoint(int defeatPoint) {
this.defeatPoint = defeatPoint;
}
public int getMeanFactors() {
return meanFactors;
}
public void setMeanFactors(int meanFactors) {
this.meanFactors = meanFactors;
}
}
As the project is quite huge and according to Chegg am only supposed to write one class but I completed almost all classes you would need. It is now your turn to code the main method only. Let me know if you need anything else.