View Javadoc

1   /*
2    * TestCard.java
3    * Created on 25 feb. 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.test;
23  
24  import java.io.IOException;
25  import java.io.InputStream;
26  
27  import net.sf.magicproject.clickable.ability.Ability;
28  import net.sf.magicproject.clickable.targetable.Targetable;
29  import net.sf.magicproject.clickable.targetable.card.MCard;
30  import net.sf.magicproject.clickable.targetable.card.TriggeredCard;
31  import net.sf.magicproject.clickable.targetable.player.Player;
32  
33  /***
34   * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
35   * @since 0.60
36   */
37  public abstract class TestCard extends TestObject {
38  
39  	/***
40  	 * Create an instance of TestCard
41  	 * <ul>
42  	 * Structure of InputStream : Data[size] used targetable for test [1]
43  	 * <li>used targetable for test [1]
44  	 * </ul>
45  	 * 
46  	 * @param inputFile
47  	 *          is the file containing this test
48  	 * @throws IOException
49  	 */
50  	protected TestCard(InputStream inputFile) throws IOException {
51  		super(inputFile);
52  	}
53  
54  	/***
55  	 * Creates a new instance of TestCard <br>
56  	 * 
57  	 * @param on
58  	 *          The test manager giving the objet (card, player, ability,..) on
59  	 *          witch the test would be applyed on
60  	 */
61  	protected TestCard(TestOn on) {
62  		super(on);
63  	}
64  
65  	@Override
66  	public final boolean test(Ability ability, Targetable tested) {
67  		if (tested instanceof MCard) {
68  			return testCard(ability, (MCard) tested);
69  		}
70  		if (tested instanceof TriggeredCard) {
71  			return testCard(ability, ((TriggeredCard) tested).triggeredAbility
72  					.getCard());
73  		}
74  		if (tested instanceof Player && on != TestOn.TESTED) {
75  			return testCard(ability, ability.getCard());
76  		}
77  		return false;
78  	}
79  
80  	/***
81  	 * Return the result of test beetwen left and right op applied on the
82  	 * specified card.
83  	 * 
84  	 * @param ability
85  	 *          is the ability owning this test. The card component of this
86  	 *          ability should correspond to the card owning this test too.
87  	 * @param tested
88  	 *          the tested card
89  	 * @return true if the specified card matches with the test to do
90  	 */
91  	protected abstract boolean testCard(Ability ability, MCard tested);
92  
93  }