View Javadoc

1   /*
2    * Created on Dec 3, 2004 
3    * Original filename was TestedIsMe.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   */
23  package net.sf.magicproject.test;
24  
25  import java.io.IOException;
26  import java.io.InputStream;
27  
28  import net.sf.magicproject.clickable.ability.Ability;
29  import net.sf.magicproject.clickable.targetable.card.MCard;
30  
31  /***
32   * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
33   * @since 0.80
34   * @since 0.91 an additional component 'other' is used.
35   */
36  public class IsTested extends TestCard {
37  
38  	/***
39  	 * The other component to test
40  	 */
41  	private final TestOn other;
42  
43  	/***
44  	 * Create an instance of IsTested by reading a file. Offset's file must
45  	 * pointing on the first byte of this test <br>
46  	 * <ul>
47  	 * Structure of InputStream : Data[size]
48  	 * <li>card TestOn [1]</li>
49  	 * <li>other TestOn [1]</li>
50  	 * </ul>
51  	 * 
52  	 * @param inputFile
53  	 *          is the file containing this event
54  	 * @throws IOException
55  	 *           if error occurred during the reading process from the specified
56  	 *           input stream
57  	 */
58  	protected IsTested(InputStream inputFile) throws IOException {
59  		super(inputFile);
60  		other = TestOn.deserialize(inputFile);
61  	}
62  
63  	/***
64  	 * Create an instance of TestedIsMe <br>
65  	 * 
66  	 * @param on
67  	 *          the card that would be compared to the tesed one.
68  	 */
69  	public IsTested(TestOn on) {
70  		this(on, TestOn.TESTED);
71  	}
72  
73  	/***
74  	 * Create an instance of TestedIsMe <br>
75  	 * 
76  	 * @param on
77  	 *          the card that would be compared to the tesed one.
78  	 * @param other
79  	 *          The other component to test.
80  	 */
81  	public IsTested(TestOn on, TestOn other) {
82  		super(on);
83  		this.other = other;
84  	}
85  
86  	@Override
87  	public boolean testCard(Ability ability, MCard tested) {
88  		return other.getTargetable(ability, tested) == on.getTargetable(ability,
89  				tested);
90  	}
91  
92  	/***
93  	 * Default instance representing the test against ME and TESTED.
94  	 */
95  	public static final IsTested TESTED_IS_ME = new IsTested(TestOn.THIS);
96  
97  	/***
98  	 * Default instance representing the test against ATTACHED_TO and TESTED.
99  	 */
100 	public static final Test TESTED_IS_ATTACHED_TO = new IsTested(TestOn.TESTED,
101 			TestOn.ATTACHED_TO);
102 
103 }