Hello,
I worked with Python for about a year. Then I moved on to C/C++. Now I'm learning Java. I know the basics of programming really well, and I'm starting to get a good grasp of OOP.
I'm learning the syntax of abstract classes and inheritance in Java. I thought it would be fun to make a small program to use the new syntax I learned, so decided to make a small RPG (I know--typical project).
Say I have a Character class.
public class Character
{
private String name;
private int level;
public void moveNorth()
{
// code to move north
}
// more methods for movement
}
So, it's rather simple. What if I'm going about my business in a world and talk to an NPC. The NPC asks me if I want to be a magician or a warrior. I want the character to acquire a set of methods and variables depending on his/her answer.
For instance, a warrior might have DoubleSlash(), PowerStrike(), LungeAttack(), and a variable for keeping track of something like mana for warriors. And a magician might have FireBall(), LightningStrike(), Heal(), Weaken(), and a variable for mana.
How could I have my character gain a certain set of skills? I haven't found anything for java on conditional inheritance. I'm trying to avoid giving all the skills to the character and having a million true/false flags for whether the character can use the skill or not. That would add a lot of hassle.
Thanks for your input.
Mouche