1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package net.sf.magicproject.test;
22
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.util.List;
26
27 import net.sf.magicproject.clickable.ability.Ability;
28 import net.sf.magicproject.clickable.targetable.card.MCard;
29 import net.sf.magicproject.event.BecomeTapped;
30 import net.sf.magicproject.event.BecomeUnTapped;
31 import net.sf.magicproject.event.MEventListener;
32 import net.sf.magicproject.event.MovedCard;
33 import net.sf.magicproject.token.IdZones;
34
35 /***
36 * Test the previous place of component. Valid only for card component.
37 *
38 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
39 * @since 0.91
40 */
41 public class PreviousZone extends TestCard {
42
43 /***
44 * Create an instance of HasColor by reading a file. Offset's file must
45 * pointing on the first byte of this test <br>
46 * <ul>
47 * Structure of InputStream : Data[size]
48 * <li>idZone to test [1]</li>
49 * </ul>
50 *
51 * @param inputFile
52 * is the file containing this event
53 * @throws IOException
54 * if error occurred during the reading process from the specified
55 * input stream
56 */
57 PreviousZone(InputStream inputFile) throws IOException {
58 super(inputFile);
59 idZone = inputFile.read();
60 }
61
62 /***
63 * Creates a new instance of InZone <br>
64 *
65 * @param idZone
66 * @param on
67 */
68 public PreviousZone(int idZone, TestOn on) {
69 super(on);
70 this.idZone = idZone;
71 }
72
73 @Override
74 public boolean testCard(Ability ability, MCard tested) {
75
76 MCard card = on.getCard(ability, tested);
77 switch (idZone) {
78 case IdZones.PLAY_TAPPED:
79 return card.getIdZone() == IdZones.PLAY && card.tapped;
80 case IdZones.PLAY_UNTAPPED:
81 return card.getIdZone() == IdZones.PLAY && !card.tapped;
82 default:
83 return idZone == card.getIdZone();
84 }
85 }
86
87 @Override
88 public void extractTriggeredEvents(List<MEventListener> res, MCard source,
89 Test globalTest) {
90 if (idZone >= IdZones.PLAY_TAPPED) {
91
92 res.add(new BecomeTapped(IdZones.PLAY, And.append(new IsTested(on),
93 globalTest), source));
94 res.add(new BecomeUnTapped(IdZones.PLAY, And.append(new IsTested(on),
95 globalTest), source));
96 }
97 res.add(new MovedCard(IdZones.PLAY, And.append(new IsTested(on),
98 new PreviousZone(idZone, on)), globalTest, source));
99 res.add(new MovedCard(IdZones.PLAY, new IsTested(on), And.append(
100 new PreviousZone(idZone, on), globalTest), source));
101 }
102
103 /***
104 * Is the color to match during each test
105 */
106 private int idZone;
107
108 }