Commit 8263b7ca authored by Mamadou Saliou DIALLO's avatar Mamadou Saliou DIALLO
Browse files

feat: create pawn class and handle his associations.

Handled associations: Pawn-Square and Pawn-Tracked.
parent 2c12a00c
package fr.univnantes.alma.model;
import fr.univnantes.alma.model.player.Creature;
import fr.univnantes.alma.model.player.Tracked;
import fr.univnantes.alma.model.square.Square;
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;
/**
* Pawn used by the tracked.
*/
public class Pawn {
/**
* Associated square.
*/
private OneToOneAssociation<Pawn, Square> square;
/**
* Owner of the card (Creature hand).
*/
private ManyToOneAssociation<Pawn, Tracked> owner;
/**
* Create new Pawn.
*/
public Pawn() {
square = new BidirectionalOneToOne<>(this, Square::getPawn);
owner = new BidirectionalManyToOne<>(this, Tracked::getPawns);
}
/**
* Return the associated square to the pawn.
* @return Square.
*/
public OneToOneAssociation<Pawn, Square> getSquare() {
return square;
}
/**
* Return pawn owner.
* @return Tracked
*/
public ManyToOneAssociation<Pawn, Tracked> getOwner() {
return owner;
}
}
package fr.univnantes.alma.model.player;
import fr.univnantes.alma.model.Pawn;
import fr.univnantes.alma.model.card.place.PlaceCard;
import fr.univnantes.alma.references.associations.BidirectionalOneToMany;
import fr.univnantes.alma.references.interfaces.OneToManyAssociation;
......@@ -18,6 +19,12 @@ public class Tracked extends Player {
* Tracked player discard.
*/
private OneToManyAssociation<Tracked, PlaceCard> discard;
/**
* Tracked player discard.
*/
private OneToManyAssociation<Tracked, Pawn> pawns;
/**
* Create new Tracked Player.
* By default, player is UNBLOCKED.
......@@ -30,6 +37,7 @@ public class Tracked extends Player {
hand = new BidirectionalOneToMany<>(this, PlaceCard::getHandOwner);
discard = new BidirectionalOneToMany<>(this,
PlaceCard::getDiscardOwner);
pawns = new BidirectionalOneToMany<>(this, Pawn::getOwner);
}
/**
......@@ -48,4 +56,11 @@ public class Tracked extends Player {
return discard;
}
/**
* Return pawns.
* @return Pawns
*/
public OneToManyAssociation<Tracked, Pawn> getPawns() {
return pawns;
}
}
package fr.univnantes.alma.model.square;
import fr.univnantes.alma.model.Pawn;
import fr.univnantes.alma.references.associations.BidirectionalOneToOne;
import fr.univnantes.alma.references.interfaces.OneToOneAssociation;
/***
* Game board square.
*/
......@@ -10,12 +14,18 @@ public abstract class Square {
*/
private int position;
/**
* Associated square.
*/
private OneToOneAssociation<Square, Pawn> pawn;
/**
* Create new instance of Square.
* @param squarePosition square position
*/
public Square(final int squarePosition) {
this.position = squarePosition;
pawn = new BidirectionalOneToOne<>(this, Pawn::getSquare);
}
/**
......@@ -25,4 +35,12 @@ public abstract class Square {
public int getPosition() {
return position;
}
/**
* Return associated pawn to the square.
* @return Pawn
*/
public OneToOneAssociation<Square, Pawn> getPawn() {
return pawn;
}
}
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