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.stack.phasetype;
23
24 import java.awt.Image;
25 import java.io.IOException;
26 import java.io.InputStream;
27
28 import net.sf.magicproject.stack.StackManager;
29 import net.sf.magicproject.token.IdConst;
30 import net.sf.magicproject.tools.MToolKit;
31 import net.sf.magicproject.tools.Picture;
32
33 /***
34 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
35 * @since 0.54
36 */
37 public class PhaseType {
38
39 /***
40 * Creates a new instance of PhaseType reading in the specified stream and
41 * following the following structure :
42 * <ul>
43 * Structure of InputStream : Data[size]
44 * <li>phase name + '\0' [...]</li>
45 * <li>phase identifiant [1]</li>
46 * <li>empty stack playable, idCards for current player [2]</li>
47 * <li>empty stack playable, idCards for non-current player [2]</li>
48 * <li>middle resolution, playable idCards for current player [2]</li>
49 * <li>middle resolution, playable idCards for non-current player [2]</li>
50 * </ul>
51 * Picure's name used for this phase corresponds to this phase name. <br>
52 *
53 * @param dbFile
54 * straem where phase name would be read
55 * @throws IOException
56 * if io exception occurred
57 */
58 public PhaseType(InputStream dbFile) throws IOException {
59 this.phaseName = MToolKit.readString(dbFile);
60 id = dbFile.read();
61 emptyStack = new EmptyStack(dbFile);
62 middleResolution = new MiddleResolution(dbFile);
63
64 normalIcon = Picture.loadImage(MToolKit.getTbsPicture("phases/" + phaseName
65 + IdConst.TYPE_PIC));
66 highLightedIcon = Picture.loadImage(MToolKit.getTbsPicture("phases/"
67 + phaseName + "h.gif"));
68 }
69
70 /***
71 * Tell if we can cast a card with idCard
72 *
73 * @param idActivePlayer
74 * the active player identifiant
75 * @param idCard
76 * id of card we would casting
77 * @return true if we can cast a card with idCard
78 */
79 public boolean canICast(int idActivePlayer, int idCard) {
80 final boolean isYou = idActivePlayer == StackManager.idCurrentPlayer;
81 return emptyStack.canICast(idCard, isYou)
82 || middleResolution.canICast(idCard, isYou);
83 }
84
85 private StackCondition emptyStack;
86
87 private StackCondition middleResolution;
88
89 /***
90 * Phase name of this phase type
91 */
92 public String phaseName;
93
94 /***
95 * Identifiant of this phase type
96 */
97 public int id;
98
99 /***
100 *
101 */
102 public Image highLightedIcon;
103
104 /***
105 *
106 */
107 public Image normalIcon;
108
109 }