1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.sf.magicproject.stack;
24
25 import java.util.ArrayList;
26 import java.util.List;
27
28 import net.sf.magicproject.clickable.Clickable;
29 import net.sf.magicproject.clickable.targetable.Targetable;
30 import net.sf.magicproject.clickable.targetable.TargetableFactory;
31 import net.sf.magicproject.token.IdZones;
32 import net.sf.magicproject.zone.MZone;
33
34 /***
35 * Represents the target settings as color, id card, owner, ... of the target.
36 * Before a target will be added to the targeted list, this test is verified in
37 * order to valid the target.
38 *
39 * @see net.sf.magicproject.action.Actiontype
40 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
41 * @since 0.86 new algorythme to determine valid targets
42 * @since 0.86 a target cannot be added twice in the target-list
43 */
44 public class TargetManager {
45
46 /***
47 * Highlight the given targets and the corresponding zones.
48 *
49 * @param validTargets
50 * the valid targets.
51 */
52 public void manageTargets(List<Targetable> validTargets) {
53 final boolean[] highlightedZones = new boolean[IdZones.NB_ZONE * 2];
54 Targetable.targetize(validTargets, highlightedZones);
55 if (this.validTargets != null) {
56 this.validTargets.clear();
57 }
58 this.validTargets = validTargets;
59 zones.clear();
60 for (int i = highlightedZones.length; i-- > 0;) {
61 if (highlightedZones[i]) {
62 final MZone highlightZone = StackManager.PLAYERS[i / IdZones.NB_ZONE].zoneManager
63 .getContainer(i % IdZones.NB_ZONE);
64 zones.add(highlightZone);
65 highlightZone.highLight(TargetableFactory.TARGET_COLOR);
66 }
67 }
68 }
69
70 /***
71 * Indicates that we're no longer looking for a target
72 */
73 public void clearTarget() {
74 if (validTargets != null) {
75 Clickable.disHighlight(validTargets);
76 validTargets.clear();
77 validTargets = null;
78 }
79 for (MZone zone : zones) {
80 zone.disHighLight();
81 }
82 zones.clear();
83 }
84
85 /***
86 * The current list of Zones containing highlighted targets.
87 */
88 private final List<MZone> zones = new ArrayList<MZone>();
89
90 /***
91 * The current list of valid targets. Is null if there was no choice.
92 */
93 private List<Targetable> validTargets = null;
94
95 }