View Javadoc

1   /*
2    * Created on Aug 5, 2004 
3    * Original filename was EmptyStack.java
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.io.IOException;
25  import java.io.InputStream;
26  
27  import net.sf.magicproject.clickable.targetable.card.MCard;
28  import net.sf.magicproject.stack.StackManager;
29  
30  /***
31   * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
32   */
33  public class EmptyStack extends StackCondition {
34  
35  	/***
36  	 * Creates a new instance of MiddleResolution <br>
37  	 * <ul>
38  	 * Structure of InputStream : Data[size]
39  	 * <li>playable idCards for current player [2]</li>
40  	 * <li>playable idCards for non-current player [2]</li>
41  	 * </ul>
42  	 * 
43  	 * @param inputStream
44  	 * @throws IOException
45  	 */
46  	EmptyStack(InputStream inputStream) throws IOException {
47  		super(inputStream);
48  	}
49  
50  	/***
51  	 * Tell if a player can cast a card with this idCard.
52  	 * 
53  	 * @param idCard
54  	 *          id of card we would casting
55  	 * @param isYou
56  	 *          is the current player waiting for that
57  	 * @return true if the player can cast a card with this idCard
58  	 */
59  	@Override
60  	public boolean canICast(int idCard, boolean isYou) {
61  		if (isYou) {
62  			return StackManager.isEmpty() && idCardsForYOU != 0
63  					&& (idCard == 0 || MCard.intersectionIdCard(idCardsForYOU, idCard));
64  		}
65  		return StackManager.isEmpty()
66  				&& idCardsForOPPONENT != 0
67  				&& (idCard == 0 || MCard.intersectionIdCard(idCardsForOPPONENT, idCard));
68  	}
69  
70  }