I am currently attempting to make a Trading Card Game and I have got a whole array of features working already, yet I am stuck now at the portion where one player can attacker another player (more strictly: the monster cards of another player on the field). The game is designed primarely to be played with two players in mind, though having it open for future extensions is never a bad idea.
This is the design I have so far, shown as a minimalistic example in pseudo-code:
class Game
private final Player self
private final Player opponent
class Player
private final String name
...
The game loops over all players and lets them do their turn, which may involve attacking another player. That method has the following structure:
class AttackMonsterAction
private final int monsterIndex
private final int targetMonsterIndex
private final Player targetPlayer
public void performAction(final Player player)
If it is of any relevance, I am coding this in Java.
My concrete question is the following: How do I create my class design such that AttackMonsterAction
called from a certain Player
object, can reference "the other player"?
GameState
solution from @GrahamA. It seems nice first, but it makes it for example harder to test, because anAttackMonsterAction
does not have to know for example how many turns have been made - so you should not bother it with information from aGameState
that it does not need or care of.AttackMonsterAction
, I updated it to reflect my current version where it does include thetargetPlayer
.