Coverage Summary for Class: Card05 (it.polimi.ingsw.Model)
Class |
Class, %
|
Method, %
|
Branch, %
|
Line, %
|
Card05 |
100%
(1/1)
|
100%
(6/6)
|
87,5%
(14/16)
|
95,7%
(22/23)
|
1 package it.polimi.ingsw.Model;
2
3 import it.polimi.ingsw.Exceptions.Input.GenericInputValidationException;
4 import it.polimi.ingsw.Exceptions.Input.InputValidationException;
5 import it.polimi.ingsw.Exceptions.Input.InvalidElementException;
6 import it.polimi.ingsw.Exceptions.Operation.FailedOperationException;
7 import it.polimi.ingsw.Misc.OptionalValue;
8 import it.polimi.ingsw.Model.Enums.StateType;
9
10 import java.io.Serial;
11 import java.util.ArrayList;
12
13 /**
14 * In Setup, put the 4 No Entry tiles on this card.
15 * EFFECT: Place a No Entrytile on an Island of your choice.
16 * The first time Mother Nature ends her movement there, put the No Entry tile back onto this card
17 * DO NOT calculate influence on that Island, or place any Towers.
18 */
19 public class Card05 extends StatefulEffect {
20 @Serial
21 private static final long serialVersionUID = 107L; // convention: 1 for model, (01 -> 99) for objects
22
23 //List containing card's tiles
24 private final ArrayList<NoEntryTile> tiles;
25
26 public Card05(Model ctx) {
27 super(5, 2, StateType.NOENTRY, ctx);
28 tiles = new ArrayList<>(4);
29 for (int i = 0; i < 4; i++) {
30 tiles.add(new NoEntryTile(this));
31 }
32 }
33
34 /**
35 * Get card's content
36 *
37 * @return ArrayList of Objects with noEntryTile (Can be casted to {@link NoEntryTile})
38 */
39 public ArrayList<Object> getState() {
40 return new ArrayList<>(tiles);
41 }
42
43 /**
44 * Get card's stateType
45 *
46 * @return card's stateType
47 */
48 public StateType getStateType() {
49 return stateType;
50 }
51
52 /**
53 * Refer to: {@link CharacterCard#overridableCheckInput(CharacterCardInput)} for further information
54 *
55 * @param input CharacterCardInput should contain:
56 * <ul>
57 * <li>A valid island's ID </li>
58 * </ul>
59 */
60 public OptionalValue<InputValidationException> overridableCheckInput(CharacterCardInput input) {
61 if (input.getTargetIsland().isEmpty()) {
62 return OptionalValue.of(new InvalidElementException("Target Island")); // target ti not set
63 }
64 Island ti = input.getTargetIsland().get();
65 if (ti.getId() < 0 || ti.getId() >= 12) {
66 return OptionalValue.of(new InvalidElementException("Target Island")); // target ti out of bounds for id
67 }
68 if (!this.context.getMutableIslandField().getMutableIslands().contains(ti)) {
69 return OptionalValue.of(new InvalidElementException("Target Island")); // target ti not in field
70 } // note: if island is in field then the island must also be in a group, due to how islandfield works.
71 if (tiles.size() == 0) {
72 return OptionalValue.of(new GenericInputValidationException("Card05",
73 "has finished all its NoEntryTile(s)"));
74 }
75 //all tests passed
76 return OptionalValue.empty();
77 }
78
79 /**
80 * Refer to: {@link CharacterCard#unsafeApplyEffect(CharacterCardInput)} for further information
81 */
82 @Override
83 protected void unsafeApplyEffect(CharacterCardInput input) throws Exception {
84 Island ti = input.getTargetIsland().get();
85 for (IslandGroup ig : this.context.getMutableIslandField().getMutableGroups()) {
86 if (ig.contains(ti)) {
87 ig.addNoEntry(tiles.remove(0));
88 return;
89 }
90 }
91 throw new FailedOperationException("Card05.unsafeApplyEffect", "Target Island was not contained in any IslandGroup");
92 }
93
94 /**
95 * Add NoEntryTile to card
96 *
97 * @param tile tile to add
98 */
99 public void tileReset(NoEntryTile tile) {
100 this.tiles.add(tile);
101 }
102
103 //test-purpose only
104 }