Commit 4155f84f authored by Mamadou Saliou DIALLO's avatar Mamadou Saliou DIALLO

feat: handle players classes associations.

Handle:
- Creature - TrackingCard association
- Creature - Token association
- Tracked - PlaceCard association
parent 8a47d40b
package fr.univnantes.alma.model;
import fr.univnantes.alma.model.player.Creature;
import fr.univnantes.alma.references.associations.BidirectionalOneToOne;
import fr.univnantes.alma.references.interfaces.OneToOneAssociation;
/**
* Token.
*/
public class Token {
/**
* Associated creature.
*/
private OneToOneAssociation<Token, Creature> creature;
/**
* Create new Token.
*/
public Token() {
creature = new BidirectionalOneToOne<>(this, (Creature creature) -> {
return creature.getCreatureToken();
});
}
/**
* Return the associated creature to the token.
* @return creature.
*/
public OneToOneAssociation<Token, Creature> getCreature() {
return creature;
}
}
......@@ -5,20 +5,21 @@ import fr.univnantes.alma.model.BoardGame;
/**
* Represent a single card.
*/
public abstract class BasicCard implements Card{
public abstract class BasicCard implements Card {
/**
* Card name.
*/
private String name;
/**
* Create new instance of card
* @param name
* Create new instance of card.
* @param cardName
*/
public BasicCard(String name) {
this.name = name;
public BasicCard(String cardName) {
this.name = cardName;
}
/**
* Return the name of the card.
*
......@@ -33,6 +34,6 @@ public abstract class BasicCard implements Card{
* {@inheritdoc}
*/
@Override
public abstract void applyEffect(final BoardGame boardGame);
public abstract void applyEffect(BoardGame boardGame);
}
package fr.univnantes.alma.model.card;
import fr.univnantes.alma.model.BoardGame;
import fr.univnantes.alma.references.interfaces.ManyToOneAssociation;
/**
* Represent a place card.
......@@ -18,4 +19,16 @@ public interface Card {
* @return return the name of the card
*/
String getName();
/**
* Return hand owner.
* @return Hand owner
*/
ManyToOneAssociation getHandOwner();
/**
* Return discard owner.
* @return Discard owner
*/
ManyToOneAssociation getDiscardOwner();
}
......@@ -2,18 +2,30 @@ package fr.univnantes.alma.model.card.place;
import fr.univnantes.alma.model.BoardGame;
import fr.univnantes.alma.model.card.BasicCard;
import fr.univnantes.alma.model.card.Card;
import fr.univnantes.alma.model.player.Tracked;
import fr.univnantes.alma.references.associations.BidirectionalManyToOne;
import fr.univnantes.alma.references.interfaces.ManyToOneAssociation;
/**
* Basic place card
*/
public abstract class BasicPlaceCard extends BasicCard implements PlaceCard{
public abstract class BasicPlaceCard extends BasicCard implements PlaceCard {
/**
* card number.
*/
private Integer number;
/**
* Owner of the card (tracked hand).
*/
private ManyToOneAssociation<PlaceCard, Tracked> handOwner;
/**
* Owner of the card (tracked discard).
*/
private ManyToOneAssociation<PlaceCard, Tracked> discardOwner;
/**
* Create new instance of place card.
* @param number cardNumber
......@@ -21,6 +33,8 @@ public abstract class BasicPlaceCard extends BasicCard implements PlaceCard{
public BasicPlaceCard(Integer number, String name) {
super(name);
this.number = number;
handOwner = new BidirectionalManyToOne<>(this, Tracked::getHand);
discardOwner = new BidirectionalManyToOne<>(this, Tracked::getDiscard);
}
/**
......@@ -36,4 +50,19 @@ public abstract class BasicPlaceCard extends BasicCard implements PlaceCard{
public Integer getNumber() {
return number;
}
/**
* Return hand of the tracked player.
* @return card list
*/
public ManyToOneAssociation<PlaceCard, Tracked> getHandOwner() {
return handOwner;
}
/**
* {@inheritdoc}
*/
public ManyToOneAssociation<PlaceCard, Tracked> getDiscardOwner() {
return discardOwner;
}
}
package fr.univnantes.alma.model.card.place;
import fr.univnantes.alma.model.card.Card;
import fr.univnantes.alma.references.interfaces.ManyToOneAssociation;
public interface PlaceCard extends Card {
/**
......
package fr.univnantes.alma.model.card.player.track;
import fr.univnantes.alma.model.card.BasicCard;
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.interfaces.ManyToOneAssociation;
/**
* Basic tracking card.
......@@ -18,6 +22,16 @@ public abstract class BasicTrackingCard extends BasicCard
*/
private String phase;
/**
* Owner of the card (Creature hand).
*/
private ManyToOneAssociation<TrackingCard, Creature> handOwner;
/**
* Owner of the card (Creature discard).
*/
private ManyToOneAssociation<TrackingCard, Creature> discardOwner;
/**
* Create new instance of tracking card
*
......@@ -27,6 +41,8 @@ public abstract class BasicTrackingCard extends BasicCard
public BasicTrackingCard(String phase, String name) {
super(name);
this.phase = phase;
handOwner = new BidirectionalManyToOne<>(this, Creature::getHand);
discardOwner = new BidirectionalManyToOne<>(this, Creature::getDiscard);
}
/**
......@@ -44,4 +60,20 @@ public abstract class BasicTrackingCard extends BasicCard
public String getPhase() {
return phase;
}
/**
* {@inheritdoc}
*/
@Override
public ManyToOneAssociation<TrackingCard, Creature> getHandOwner() {
return handOwner;
}
/**
* {@inheritdoc}
*/
@Override
public ManyToOneAssociation<TrackingCard, Creature> getDiscardOwner() {
return discardOwner;
}
}
......@@ -21,7 +21,7 @@ public class RelentlessnessCard extends BasicTrackingCard {
* {@inheritdoc}
*/
@Override
public void applyEffect(BoardGame boardGame) {
public void applyEffect(final BoardGame boardGame) {
}
}
package fr.univnantes.alma.model.player;
import fr.univnantes.alma.model.Token;
import fr.univnantes.alma.model.card.player.track.TrackingCard;
import fr.univnantes.alma.references.associations.BidirectionalOneToMany;
import fr.univnantes.alma.references.associations.BidirectionalOneToOne;
import fr.univnantes.alma.references.interfaces.OneToManyAssociation;
import fr.univnantes.alma.references.interfaces.OneToOneAssociation;
/**
* Single Creature game player.
*/
public class Creature extends Player{
public class Creature extends Player {
/**
* Creature token.
*/
private OneToOneAssociation<Creature, Token> creatureToken;
/**
* Artemia token.
*/
private OneToOneAssociation<Creature, Token> artemiaToken;
/**
* Target token.
*/
private OneToOneAssociation<Creature, Token> targetToken;
/**
* Creature player hand.
*/
private OneToManyAssociation<Creature, TrackingCard> hand;
/**
* Creature player discard.
*/
private OneToManyAssociation<Creature, TrackingCard> discard;
/**
* Create new Creature Player.
* By default, player is UNBLOCKED.
*
* @param id player ID
* @param name Player name
*/
public Creature(String id, String name) {
super(id, name);
creatureToken = new BidirectionalOneToOne<>(this, Token::getCreature);
artemiaToken = new BidirectionalOneToOne<>(this, Token::getCreature);
targetToken = new BidirectionalOneToOne<>(this, Token::getCreature);
hand = new BidirectionalOneToMany<>(this, TrackingCard::getHandOwner);
discard = new BidirectionalOneToMany<>(this,
TrackingCard::getDiscardOwner);
}
/**
* Return Creature token.
* @return Creature Token
*/
public OneToOneAssociation<Creature, Token> getCreatureToken() {
return creatureToken;
}
/**
* Return Atermia token.
* @return Artemia Token
*/
public OneToOneAssociation<Creature, Token> getArtemiaToken() {
return artemiaToken;
}
/**
* Return Target token.
* @return Target token
*/
public OneToOneAssociation<Creature, Token> getTargetToken() {
return targetToken;
}
/**
* Return the list of cards in the creature's hand.
* @return card list.
*/
public OneToManyAssociation<Creature, TrackingCard> getHand() {
return hand;
}
/**
* Return the list of cards to the creature's discard pile.
* @return card list
*/
public OneToManyAssociation<Creature, TrackingCard> getDiscard() {
return discard;
}
}
......@@ -4,4 +4,55 @@ package fr.univnantes.alma.model.player;
* Single game player.
*/
public abstract class Player {
/**
* Player state.
*/
private PlayerState state;
/**
* Palyer ID.
*/
private String id;
/**
* Player name.
*/
private String name;
/**
* Create new Player.
* By default, player is UNBLOCKED.
* @param playerId player ID
* @param playerName Player name
*/
public Player(String playerId, String playerName) {
this.id = playerId;
this.name = playerName;
state = PlayerState.UNBLOCKED;
}
/**
* Return the player state.
* @return PlayerState
*/
public PlayerState getState() {
return state;
}
/**
* Retunr player ID.
* @return Player ID
*/
public String getId() {
return id;
}
/**
* Return player name.
* @return player name
*/
public String getName() {
return name;
}
}
package fr.univnantes.alma.model.player;
/**
* Player state.
*/
public enum PlayerState {
/**
* Player is unblocked, he can do a specific actions.
*/
UNBLOCKED,
/**
* Player is blocked, he can't do anything.
*/
BLOCKED
}
package fr.univnantes.alma.model.player;
import fr.univnantes.alma.model.card.place.PlaceCard;
import fr.univnantes.alma.references.associations.BidirectionalOneToMany;
import fr.univnantes.alma.references.interfaces.OneToManyAssociation;
/**
* Single Tracked game player.
*/
public class Tracked extends Player{
public class Tracked extends Player {
/**
* Tracked player hand.
*/
private OneToManyAssociation<Tracked, PlaceCard> hand;
/**
* Tracked player discard.
*/
private OneToManyAssociation<Tracked, PlaceCard> discard;
/**
* Create new Tracked Player.
* By default, player is UNBLOCKED.
*
* @param id player ID
* @param name Player name
*/
public Tracked(String id, String name) {
super(id, name);
hand = new BidirectionalOneToMany<>(this, PlaceCard::getHandOwner);
discard = new BidirectionalOneToMany<>(this,
PlaceCard::getDiscardOwner);
}
/**
* Return the list of cards in the creature's hand.
* @return card list.
*/
public OneToManyAssociation<Tracked, PlaceCard> getHand() {
return hand;
}
/**
* Return the list of cards to the creature's discard pile.
* @return card list
*/
public OneToManyAssociation<Tracked, PlaceCard> getDiscard() {
return discard;
}
}
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