1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package net.sf.magicproject.test;
23
24 import java.io.IOException;
25 import java.io.InputStream;
26
27 import net.sf.magicproject.clickable.ability.Ability;
28 import net.sf.magicproject.clickable.targetable.Targetable;
29 import net.sf.magicproject.clickable.targetable.card.MCard;
30 import net.sf.magicproject.clickable.targetable.card.TriggeredCard;
31 import net.sf.magicproject.clickable.targetable.player.Player;
32
33 /***
34 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
35 * @since 0.60
36 */
37 public abstract class TestCard extends TestObject {
38
39 /***
40 * Create an instance of TestCard
41 * <ul>
42 * Structure of InputStream : Data[size] used targetable for test [1]
43 * <li>used targetable for test [1]
44 * </ul>
45 *
46 * @param inputFile
47 * is the file containing this test
48 * @throws IOException
49 */
50 protected TestCard(InputStream inputFile) throws IOException {
51 super(inputFile);
52 }
53
54 /***
55 * Creates a new instance of TestCard <br>
56 *
57 * @param on
58 * The test manager giving the objet (card, player, ability,..) on
59 * witch the test would be applyed on
60 */
61 protected TestCard(TestOn on) {
62 super(on);
63 }
64
65 @Override
66 public final boolean test(Ability ability, Targetable tested) {
67 if (tested instanceof MCard) {
68 return testCard(ability, (MCard) tested);
69 }
70 if (tested instanceof TriggeredCard) {
71 return testCard(ability, ((TriggeredCard) tested).triggeredAbility
72 .getCard());
73 }
74 if (tested instanceof Player && on != TestOn.TESTED) {
75 return testCard(ability, ability.getCard());
76 }
77 return false;
78 }
79
80 /***
81 * Return the result of test beetwen left and right op applied on the
82 * specified card.
83 *
84 * @param ability
85 * is the ability owning this test. The card component of this
86 * ability should correspond to the card owning this test too.
87 * @param tested
88 * the tested card
89 * @return true if the specified card matches with the test to do
90 */
91 protected abstract boolean testCard(Ability ability, MCard tested);
92
93 }