Commit 217721f0 authored by Mamadou Saliou DIALLO's avatar Mamadou Saliou DIALLO

feat: handle PlacedCard-Token association.

parent 8263b7ca
package fr.univnantes.alma.model;
import fr.univnantes.alma.model.card.place.PlaceCard;
import fr.univnantes.alma.model.player.Creature;
import fr.univnantes.alma.model.player.Tracked;
import fr.univnantes.alma.references.associations.BidirectionalManyToOne;
import fr.univnantes.alma.references.associations.BidirectionalOneToOne;
import fr.univnantes.alma.references.interfaces.ManyToOneAssociation;
import fr.univnantes.alma.references.interfaces.OneToOneAssociation;
/**
......@@ -13,13 +17,17 @@ public class Token {
*/
private OneToOneAssociation<Token, Creature> creature;
/**
* Card on which the token is placed.
*/
private ManyToOneAssociation<Token, PlaceCard> card;
/**
* Create new Token.
*/
public Token() {
creature = new BidirectionalOneToOne<>(this, (Creature creature) -> {
return creature.getCreatureToken();
});
creature = new BidirectionalOneToOne<>(this, Creature::getCreatureToken);
card = new BidirectionalManyToOne<>(this, PlaceCard::getToken);
}
/**
......@@ -29,4 +37,12 @@ public class Token {
public OneToOneAssociation<Token, Creature> getCreature() {
return creature;
}
/**
* Return the card on which the token is placed.
* @return Card
*/
public ManyToOneAssociation<Token, PlaceCard> getCard() {
return card;
}
}
package fr.univnantes.alma.model.card.place;
import fr.univnantes.alma.model.BoardGame;
import fr.univnantes.alma.model.Token;
import fr.univnantes.alma.model.card.BasicCard;
import fr.univnantes.alma.model.player.Tracked;
import fr.univnantes.alma.references.associations.BidirectionalManyToOne;
import fr.univnantes.alma.references.associations.BidirectionalOneToMany;
import fr.univnantes.alma.references.interfaces.ManyToOneAssociation;
import fr.univnantes.alma.references.interfaces.OneToManyAssociation;
/**
* Basic place card.
......@@ -26,6 +29,11 @@ public abstract class BasicPlaceCard extends BasicCard implements PlaceCard {
*/
private ManyToOneAssociation<PlaceCard, Tracked> discardOwner;
/**
* The token placed on the card.
*/
OneToManyAssociation<PlaceCard, Token> tokens;
/**
* Create new instance of place card.
* @param cardNumber card number
......@@ -36,6 +44,7 @@ public abstract class BasicPlaceCard extends BasicCard implements PlaceCard {
this.number = cardNumber;
handOwner = new BidirectionalManyToOne<>(this, Tracked::getHand);
discardOwner = new BidirectionalManyToOne<>(this, Tracked::getDiscard);
tokens = new BidirectionalOneToMany<>(this, Token::getCard);
}
/**
......@@ -66,4 +75,11 @@ public abstract class BasicPlaceCard extends BasicCard implements PlaceCard {
public ManyToOneAssociation<PlaceCard, Tracked> getDiscardOwner() {
return discardOwner;
}
/**
* @inheritdoc}
*/
public OneToManyAssociation<PlaceCard, Token> getToken() {
return tokens;
}
}
package fr.univnantes.alma.model.card.place;
import fr.univnantes.alma.model.Token;
import fr.univnantes.alma.model.card.Card;
import fr.univnantes.alma.references.interfaces.ManyToOneAssociation;
import fr.univnantes.alma.references.interfaces.OneToManyAssociation;
public interface PlaceCard extends Card {
/**
......@@ -9,4 +10,10 @@ public interface PlaceCard extends Card {
* @return card number
*/
Integer getNumber();
/**
* Return the token placed on the card.
* @return Token
*/
OneToManyAssociation<PlaceCard, Token> getToken();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment