Commit 41e68cd1 authored by Mamadou Saliou DIALLO's avatar Mamadou Saliou DIALLO
Browse files

feat: implement test for Creature and Tracked

parent 8a1e7ee0
......@@ -7,11 +7,23 @@ import fr.univnantes.alma.references.associations.BidirectionalOneToOne;
import fr.univnantes.alma.references.interfaces.OneToManyAssociation;
import fr.univnantes.alma.references.interfaces.OneToOneAssociation;
import java.util.List;
/**
* Single Creature game player.
*/
public class Creature extends Player {
/**
* Initial size of player hands.
*/
public static final int INIT_HAND_SIZE = 3;
/**
* Max length of player hand.
*/
public static final int MAX_HAND_SIZE = 3;
/**
* Creature token.
*/
......@@ -93,4 +105,107 @@ public class Creature extends Player {
public OneToManyAssociation<Creature, TrackingCard> getDiscard() {
return discard;
}
/**
* Add place card to the hand.
* @param card card to add
* @return true if the card is added and false otherwise
*/
public Boolean addCardToHand(TrackingCard card) {
if (card == null) {
throw new IllegalArgumentException("Card can't be null");
}
if (hand.size() > MAX_HAND_SIZE) {
return false;
}
if (hand.contains(card)) {
throw new IllegalArgumentException("Card already in hand");
}
return hand.add(card);
}
/**
* Remove Place from hand.
* @param card card to remove
* @return true if the card is removed and false otherwise
*/
public Boolean removeCardFromHand(TrackingCard card) {
if (card == null) {
throw new IllegalArgumentException("Card can't be null");
}
return hand.remove(card);
}
/**
* Remove card form player hand and put it to his discard.
* @param card card to discard
* @return true if the card is discarded and false otherwise
*/
public Boolean discard(TrackingCard card) {
if (!hand.contains(card)) {
throw new IllegalArgumentException("Card not exist in player hand");
}
if (discard.size() >= MAX_HAND_SIZE) {
return false;
}
hand.remove(card);
return discard.add(card);
}
/**
* Remove card form player discard and put it to his hand.
* @param card card to put in the hand
* @return true if the card is added to hand and false otherwise
*/
public Boolean putCardBackInHand(TrackingCard card) {
if (!discard.contains(card)) {
throw new IllegalArgumentException(
"Card not exist in player discard");
}
if (hand.size() >= MAX_HAND_SIZE) {
return false;
}
discard.remove(card);
return hand.add(card);
}
/**
* Player hand size.
* @return Hand size
*/
public int getHandSize() {
return hand.size();
}
/**
* Player discard size.
* @return discard size
*/
public int getDiscardSize() {
return discard.size();
}
/**
* Init player hand with place cards.
* @param cards Card List
*/
public void initHand(List<TrackingCard> cards) {
if (cards == null) {
throw new IllegalArgumentException("Card list cannot be null");
}
if (cards.size() != INIT_HAND_SIZE) {
throw new IllegalArgumentException("Card list must be exactly "
+ INIT_HAND_SIZE);
}
if (hand.size() > 0) {
throw new UnsupportedOperationException("Hand already initialized");
}
hand.addAll(cards);
}
}
......@@ -4,6 +4,7 @@ package fr.univnantes.alma.model.player;
* Single game player.
*/
public abstract class Player {
/**
* Player state.
*/
......
......@@ -5,10 +5,21 @@ import fr.univnantes.alma.model.card.place.PlaceCard;
import fr.univnantes.alma.references.associations.BidirectionalOneToMany;
import fr.univnantes.alma.references.interfaces.OneToManyAssociation;
import java.util.List;
/**
* Single Tracked game player.
*/
public class Tracked extends Player {
/**
* Initial size of player hands.
*/
public static final int INIT_HAND_SIZE = 5;
/**
* Max length of player hand.
*/
public static final int MAX_HAND_SIZE = 10;
/**
* Tracked player hand.
......@@ -63,4 +74,107 @@ public class Tracked extends Player {
public OneToManyAssociation<Tracked, Pawn> getPawns() {
return pawns;
}
/**
* Add place card to the hand.
* @param card card to add
* @return true if the card is added and false otherwise
*/
public Boolean addCardToHand(PlaceCard card) {
if (card == null) {
throw new IllegalArgumentException("Card can't be null");
}
if (hand.size() > MAX_HAND_SIZE) {
return false;
}
if (hand.contains(card)) {
throw new IllegalArgumentException("Card already in hand");
}
return hand.add(card);
}
/**
* Remove Place from hand.
* @param card card to remove
* @return true if the card is removed and false otherwise
*/
public Boolean removeCardFromHand(PlaceCard card) {
if (card == null) {
throw new IllegalArgumentException("Card can't be null");
}
return hand.remove(card);
}
/**
* Remove card form player hand and put it to his discard.
* @param card card to discard
* @return true if the card is discarded and false otherwise
*/
public Boolean discard(PlaceCard card) {
if (!hand.contains(card)) {
throw new IllegalArgumentException("Card not exist in player hand");
}
if (discard.size() >= MAX_HAND_SIZE) {
return false;
}
hand.remove(card);
return discard.add(card);
}
/**
* Remove card form player discard and put it to his hand.
* @param card card to put in the hand
* @return true if the card is added to hand and false otherwise
*/
public Boolean putCardBackInHand(PlaceCard card) {
if (!discard.contains(card)) {
throw new IllegalArgumentException(
"Card not exist in player discard");
}
if (hand.size() >= MAX_HAND_SIZE) {
return false;
}
discard.remove(card);
return hand.add(card);
}
/**
* Player hand size.
* @return Hand size
*/
public int getHandSize() {
return hand.size();
}
/**
* Player discard size.
* @return discard size
*/
public int getDiscardSize() {
return discard.size();
}
/**
* Init player hand with place cards.
* @param cards Card List
*/
public void initHand(List<PlaceCard> cards) {
if (cards == null) {
throw new IllegalArgumentException("Card list cannot be null");
}
if (cards.size() != INIT_HAND_SIZE) {
throw new IllegalArgumentException("Card list must be exactly "
+ INIT_HAND_SIZE);
}
if (hand.size() > 0) {
throw new UnsupportedOperationException("Hand already initialized");
}
hand.addAll(cards);
}
}
......@@ -251,7 +251,7 @@ class TrackedTest {
});
/**
* (2) When card list size is different to {@link Player#INIT_HAND_SIZE}.
* (2) When card list size is different to {@link Tracked#INIT_HAND_SIZE}.
*/
int expectedSize = cards1.size() - 1;
cards1.remove(0);
......
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