Ben
Ben

Reputation: 3

How to design an RPG class system with OOP in java?

I am making a roguelike based on Trystan's Tutorial and running into issues with implementing a class system. I'm pretty sure the solution is simple, but bear with me.

class Creature {
    int HP;
    CharacterClass playerClass = new Wizard();
    HP = playerClass.hitDie;
    ArrayList<Ability> creatureAbilityList = new ArrayList<>();
    creatureAbilityList.add(classAbilityList.get(1));
}

class CharacterClass {
    int hitDie;
    ArrayList<Ability> classAbilityList = new ArrayList<>();
}

class Wizard extends CharacterClass {
    Wizard() {
        hitDie = 6;
        classAbilityList.add(new Ability(magicMissile));
    }
}

I'm getting a "Syntax error on token ";", , expected", on the semicolon following "new Wizard()". I'm fairly sure that this isn't the issue however, but instead the way that my classes and inheritance is set up. How should I set up the code instead? Any help would be appreciated.

Upvotes: 0

Views: 670

Answers (2)

Stefan
Stefan

Reputation: 2385

The problem is the row below. It should be

    int HP=playerClass.hitDie;

(and remove the line int HP;)

Upvotes: 3

marco
marco

Reputation: 681

you should make hitDie private, and make it accessible with getter and setter to enable the polimorphism (and so the getHitDie() invoked will be the one of the class Wizard instead of the one of the class CharacterClass)

Upvotes: 0

Related Questions