View Javadoc

1   /* 
2    * MPhaseType.java 
3    * Created on 21 févr. 2004
4    * 
5    *   Magic-Project is a turn based strategy simulator
6    *   Copyright (C) 2003-2007 Fabrice Daugan
7    *
8    *   This program is free software; you can redistribute it and/or modify it 
9    * under the terms of the GNU General Public License as published by the Free 
10   * Software Foundation; either version 2 of the License, or (at your option) any
11   * later version.
12   *
13   *   This program is distributed in the hope that it will be useful, but WITHOUT 
14   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15   * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
16   * details.
17   *
18   *   You should have received a copy of the GNU General Public License along  
19   * with this program; if not, write to the Free Software Foundation, Inc., 
20   * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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  		// Log.debug("new PHASE " + phaseName + "(id=" + id + ")");
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 }