I am working on a party game in java.
I struggle to make a proper class hierarchy for cards. The player can carry cards. There are different kind of cards so I made for each card group a separate class. There are the following classes for cards:
- Card (Superclass)
- NumberedCard (Subclass of Card)
- NumberedSpecialCard (Subclass of NumberedCard)
- MasterCard (Subclass of Card)
- WarriorMasterCard (Subclass of MasterCard)
- ...
- NumberedCard (Subclass of Card)
First I construct a NumberedSpecialCard:
NumberedSpecialCard firstPlayerThirdCard = new NumberedSpecialCard(13);
Next I add the card to a list (here firstPlayerCards)
List<Card> firstPlayerCards = new LinkedList<Card>();
firstPlayerCards.add(firstPlayerThirdCard);
Now I create a player object. The player can carry a list of cards.
Player firstPlayer = new Player(firstPlayerMumbles, firstPlayerCards, 1,"Player ONE");
The problem is that i can not access the 'bringMumbleIntoPlay' method which is defined in the NumberedSpecialCard class.
The following does not work:
firstPlayer.getCards().get(2).bringMumbleIntoPlay(allPlayers, firstPlayer, 1);
I do not want to change the class hierarchy (It pictures the real conditions very well.). Can someone help me?