dimanche 16 juin 2019

How to implement visitor pattern into trading card game

First, sorry for my english, i am not native speaker.

I have an assignment and i need to implement a pokemon trading card game. Actually i have the base of the game (see UML diagram) and after some improvements i have reached a second UML . I had implemented the attacks using double dispatch. But now i must use the visitor pattern to implement effects that can affect other components of the game like the enemy pokemon, the deck of the enemy, etc. I don't know wich is the best approach to do this.

enter image description here

I have created a game driver that is itering over a trainer queue where i put the cards that can have effects, then, with a visitor, i give him a reference to the game driver so he can implement the effect in an isolated environment (i think that this can improve the extensibility of the code).

queue = activeTrainer.getTrainerQueue();
for(ITrainerCard c: queue){
    IVisitor v = new SpellVisitor();
    v.set(this);
    c.accept(v);
}

I expect to pass some junit test showing that i can implement this entities (cards):

  • An object called Potion that can heal a pokemon.
  • A stadium called Luck Stadium that can randomly give a card to the trainer.
  • A support card called ProfessorJuniper that can discard all the hand of the trainer and draw 7 new cards.

Aucun commentaire:

Enregistrer un commentaire