View Javadoc

1   /*
2    *   Magic-Project is a turn based strategy simulator
3    *   Copyright (C) 2003-2007 Fabrice Daugan
4    *
5    *   This program is free software; you can redistribute it and/or modify it 
6    * under the terms of the GNU General Public License as published by the Free 
7    * Software Foundation; either version 2 of the License, or (at your option) any
8    * later version.
9    *
10   *   This program is distributed in the hope that it will be useful, but WITHOUT 
11   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12   * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
13   * details.
14   *
15   *   You should have received a copy of the GNU General Public License along  
16   * with this program; if not, write to the Free Software Foundation, Inc., 
17   * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   * 
19   */
20  package net.sf.magicproject.test;
21  
22  import java.io.InputStream;
23  import java.util.List;
24  import java.util.Map;
25  
26  import net.sf.magicproject.clickable.ability.Ability;
27  import net.sf.magicproject.clickable.targetable.Targetable;
28  import net.sf.magicproject.clickable.targetable.card.MCard;
29  import net.sf.magicproject.clickable.targetable.player.Player;
30  import net.sf.magicproject.event.MEventListener;
31  import net.sf.magicproject.event.context.ContextEventListener;
32  import net.sf.magicproject.expression.Expression;
33  
34  /***
35   * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
36   * @since 0.54
37   */
38  public abstract class Test {
39  
40  	/***
41  	 * <ul>
42  	 * Structure of InputStream : Data[size]
43  	 * <li>tested on (idTestedOn) [1]</li>
44  	 * </ul>
45  	 * 
46  	 * @param inputFile
47  	 *          is the file containing this test
48  	 */
49  	protected Test(InputStream inputFile) {
50  		// System.out.println("TEST " + this.getClass() + "(" + getIdTest() + ")");
51  	}
52  
53  	/***
54  	 * Creates a new instance of Test <br>
55  	 */
56  	protected Test() {
57  		super();
58  	}
59  
60  	/***
61  	 * Return this test where values depending on values of this action have been
62  	 * replaced.
63  	 * 
64  	 * @param values
65  	 *          are referencable values.
66  	 * @return a parsed test.
67  	 * @since 0.85
68  	 */
69  	public Test getConstraintTest(Map<String, Expression> values) {
70  		return this;
71  	}
72  
73  	/***
74  	 * Indicates if the specified card matches with the test to do
75  	 * 
76  	 * @param ability
77  	 *          is the ability owning this test. The card component of this
78  	 *          ability should correspond to the card owning this test too.
79  	 * @param tested
80  	 *          the tested card
81  	 * @return true if the specified card matches with the test to do
82  	 */
83  	public abstract boolean test(Ability ability, Targetable tested);
84  
85  	/***
86  	 * Add to the specified list, the events modifying the result of this test.
87  	 * 
88  	 * @param res
89  	 *          is the list of events to fill
90  	 * @param source
91  	 *          is the card source of event
92  	 * @param globalTest
93  	 *          the optional global test to include in the event test.
94  	 */
95  	public void extractTriggeredEvents(List<MEventListener> res, MCard source,
96  			Test globalTest) {
97  		// No event associated to this test
98  	}
99  
100 	/***
101 	 * Return the controller making true this test. If several players or no
102 	 * player can make this test true, the <code>null</code> value is returned.
103 	 * 
104 	 * @param ability
105 	 *          is the ability owning this test. The card component of this
106 	 *          ability should correspond to the card owning this test too.
107 	 * @param context
108 	 *          is the context of current ability
109 	 * @return the controller making true this test. If several player or no
110 	 *         player can make this test true, the <code>null</code> value is
111 	 *         returned.
112 	 */
113 	public Player getOptimizedController(Ability ability,
114 			ContextEventListener context) {
115 		return null;
116 	}
117 
118 	/***
119 	 * Indicates if the specified card matches with the test to do.
120 	 * 
121 	 * @param ability
122 	 *          is the ability owning this test. The card component of this
123 	 *          ability should correspond to the card owning this test too.
124 	 * @param tested
125 	 *          the tested card
126 	 * @return true if the specified card matches with the test to do
127 	 */
128 	public boolean testPreemption(Ability ability, Targetable tested) {
129 		return test(ability, tested);
130 	}
131 
132 }