Coverage Summary for Class: Card12 (it.polimi.ingsw.Model)

Class Class, % Method, % Branch, % Line, %
Card12 100% (1/1) 100% (3/3) 100% (8/8) 100% (11/11)


1 package it.polimi.ingsw.Model; 2  3 import it.polimi.ingsw.Exceptions.Input.InputValidationException; 4 import it.polimi.ingsw.Exceptions.Input.InvalidElementException; 5 import it.polimi.ingsw.Misc.OptionalValue; 6  7 import java.io.Serial; 8  9 /** 10  * EFFECT: Choose a type of Student: every player 11  * (including yourself) must return 3 Students of that type 12  * from their Dining Room to the bag. If any player has 13  * fewer than 3 Students of that type, return as many 14  * Students as they have. 15  */ 16 public class Card12 extends StatelessEffect { 17  @Serial 18  private static final long serialVersionUID = 114L; // convention: 1 for model, (01 -> 99) for objects 19  20  public Card12(Model ctx) { 21  super(12, 3, ctx); 22  } 23  24  /** 25  * Refer to: {@link CharacterCard#overridableCheckInput(CharacterCardInput)} for further information 26  * 27  * @param input CharacterCardInput should contain: 28  * <ul> 29  * <li>A valid PawnColour</li> 30  * </ul> 31  */ 32  public OptionalValue<InputValidationException> overridableCheckInput(CharacterCardInput input) { 33  if (input.getTargetPawn().isEmpty()) { 34  return OptionalValue.of(new InvalidElementException("Target Pawn Colour")); 35  } 36  return OptionalValue.empty(); 37  } 38  39  /** 40  * Refer to: {@link CharacterCard#unsafeApplyEffect(CharacterCardInput)} for further information 41  */ 42  @Override 43  protected void unsafeApplyEffect(CharacterCardInput input) throws Exception { 44  for (PlayerBoard p : this.context.getMutablePlayerBoards()) { 45  //If any player has fewer than 3 Students of that type, return as many Students as they have. 46  int amountToRemove = Math.min(3, p.getDiningRoomCount(input.getTargetPawn().get())); 47  48  for (int i = 0; i < amountToRemove; i++) { 49  this.context.removeStudentFromDiningRoom(input.getTargetPawn().get(), p); 50  } 51  52  for (int i = 0; i < amountToRemove; i++) { 53  this.context.getMutableStudentBag().appendAndShuffle(input.getTargetPawn().get()); 54  } 55  } 56  } 57  58  //test purpose only 59 }