javaclassooproguelike

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.


Solution

  • The problem is the row below. It should be

        int HP=playerClass.hitDie;
    

    (and remove the line int HP;)