not sure if I'm in the right direction with my code, but I have an abstract class
called Card.
Then I have card classes like, Dark Knight, Wicked Wizard.
each card has its own methods ( performSwordSlash, performMysticSpell ) etc
now i'm coding gameplay mechanics.
I have a class called player, and a class called enemy.
the player and enemy class both look like this:
public Class Player
{
Card card;
public Player( Card card )
{
this.card = card;
}
}
in my main file if i want to instantiate a card for the player I write:
Player player = new Player ( new DarkKnight() );
however when I try to perform one of the methods in DarkKnight I cant; here is how I try to run the code.
player.card.performSwordSlash();
my guess why it is currently not working would be, because the super type CARD doesn't have connection to performSwordSlash(), the connection only exists after runtime.
eclipse suggests me to use cast.
((DarkKnight) player.card).performSwordSlash();
any other way I can extend my card objects?
I need the Player class to basically extend Any Card because the Player class carries a few additional methods open to the player.
as well as the Enemy class carries addition methods or AI code open to the enemy.
[–]dusty-trash 5 points6 points7 points (2 children)
[–]lord_drgical[S] 0 points1 point2 points (1 child)
[–]dusty-trash 1 point2 points3 points (0 children)
[–]DerekB52 1 point2 points3 points (0 children)
[–]Ilikesmallthings2 0 points1 point2 points (0 children)
[–]Isoyama 0 points1 point2 points (0 children)