Question: Use your own theme to make your own class design and implementation unique, giving the character unique attributes and actions.
Implement a main game character object oriented class type to simulate what is common to all characters in your game
A class data field (variable) (data member) to represent the name/identifier of the character/ make sure each character can carry an item
public abstract class Hero {
private String name;
private Item item;
public Hero(String name, Item item) {
this.name = name;
this.item = item;
}
public abstract String battleRoar();
public String getName() {
return name;
}
public int attack(){
return item.getStrength();
}
}
public class Gandalf extends Hero {
private int magicPower;
public Gendalf(String name, Item item, int magicPower) {
super(name, item);
this.magicPower = magicPower;
}
@Override
public String battleRoar() {
return "You shall not pass.";
}
@Override
public int attack() {
return super.attack() + magicPower;
}
}
public class Frodo extends Hero{
public Frodo(String name, Item item){
super(name, item);
}
@Override
public String battleRoar() {
return "For the Fellowship!";
}
}
public class Item {
private String name;
private int strength;
public Item(String name, int strength) {
this.name = name;
this.strength = strength;
}
public String getName() {
return name;
}
public int getStrength() {
return strength;
}
}
Comments
Leave a comment