View Javadoc
1   /******************************************************************************
2    * GameEvent.java - An Event that occurs during the course of a game.
3    * $Id$
4    * 
5    * BuckoFIBS - Backgammon by BuckoSoft
6    * Copyright© 2011 - Dick Balaska - BuckoSoft, Corp.
7    * 
8    * $Log$
9    * Revision 1.14  2011/07/16 03:52:18  dick
10   * Double becomes YouDouble and OpponentDouble.
11   *
12   * Revision 1.13  2011/07/04 03:34:20  dick
13   * Add FirstMove.
14   *
15   * Revision 1.12  2011/06/15 02:37:53  dick
16   * Use Board.O, not 0.
17   *
18   * Revision 1.11  2011/06/05 06:48:14  dick
19   * Define the type AcceptAndWin.
20   *
21   * Revision 1.10  2011/06/02 18:59:42  dick
22   * Add the resign types.
23   *
24   * Revision 1.9  2011/05/31 19:45:58  dick
25   * Javadoc.
26   *
27   * Revision 1.8  2011/05/25 06:11:13  dick
28   * Javadoc.
29   *
30   * Revision 1.7  2011/05/22 05:08:59  dick
31   * All GameEvent objects are named starting with GameEvent.
32   *
33   * Revision 1.6  2011/05/21 05:09:53  dick
34   * Define an attribute type Life, for short lived vs. long lived event objects.
35   *
36   * Revision 1.5  2011/05/18 05:53:44  dick
37   * Add getDepth().
38   *
39   * Revision 1.4  2011/05/17 23:15:50  dick
40   * link fix.
41   *
42   * Revision 1.3  2011/05/16 14:15:32  dick
43   * Add getPlayerName().
44   *
45   * Revision 1.2  2011/05/16 11:35:11  dick
46   * GameEvent is an abstract class, not an interface, so we can have some common methods.
47   *
48   * Revision 1.1  2011/05/15 02:16:39  dick
49   * Move the GameEvent objects to c.b.f.domain.gameEvent.
50   *
51   * Revision 1.1  2011/05/13 14:21:30  dick
52   * Define an Interface for a game event.
53   * We define a GameEvent as an event to be serialized to the gui.
54   * Like "Move 6 to 2".  "You double". "Redraw board".
55   *
56   */
57  
58  /* 
59   * This program is free software: you can redistribute it and/or modify
60   * it under the terms of the GNU General Public License as published by
61   * the Free Software Foundation, either version 3 of the License, or
62   * (at your option) any later version.
63   *
64   * This program is distributed in the hope that it will be useful,
65   * but WITHOUT ANY WARRANTY; without even the implied warranty of
66   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
67   * GNU General Public License for more details.
68   *
69   * You should have received a copy of the GNU General Public License
70   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
71   *
72   * The Original Code is BuckoFIBS, <http://www.buckosoft.com/BuckoFIBS/>.
73   * The Initial Developer of the Original Code is Dick Balaska and BuckoSoft, Corp.
74   * 
75   */
76  package com.buckosoft.fibs.domain.gameEvent;
77  
78  import com.buckosoft.fibs.domain.Board;
79  
80  /** Abstract Base Class to define a single event of a backgammon game in Fibs.
81   * One game's worth of events are kept in the GameManager's eventList.<br>
82   * One yucky thing is that event's owners are chaotic.  Some are determined by playerName, others by xo.
83   * @author Dick Balaska
84   * @since 2011/05/11
85   * @version $Revision$ <br> $Date$
86   * @see com.buckosoft.fibs.BuckoFIBS.GameManager
87   * @see <a href="http://cvs.buckosoft.com/Projects/BuckoFIBS/BuckoFIBS/src/main/java/com/buckosoft/fibs/domain/gameEvent/GameEvent.java">cvs GameEvent.java</a>
88   */
89  public abstract class GameEvent {
90  	protected	int		who;
91  	protected	String	playerName;
92  
93  	/** A game event type.
94  	 * Events get Listed in GameManager and Type tells the different kinds apart. <br>
95  	 * <br>
96  	 * Should handle these events:<br><ul>
97  	 * 	<li>case FIBS_PlayerMoves:
98  	 *	<li>case FIBS_FirstRoll:
99  	 *	<li>case FIBS_MakesFirstMove:
100 	 *	<li>case FIBS_PlayerRolls:
101 	 *	<li>case FIBS_CantMove:
102 	 *	<li>case FIBS_OnlyPossibleMove:
103 	 * </ul>
104 	 * @author Dick Balaska
105 	 * @since 2011/05/11
106 	 * @version $Revision$ <br> $Date$
107 	 * @see com.buckosoft.fibs.BuckoFIBS.GameManager
108 	 * @see <a href="http://cvs.buckosoft.com/Projects/BuckoFIBS/BuckoFIBS/src/main/java/com/buckosoft/fibs/domain/gameEvent/GameEvent.java">cvs GameEvent.java</a>
109 	 */
110 	public enum Type {
111 		/** Board state */
112 		Board,
113 		/** Player has moved these pieces */
114 		Move,
115 		/** Player has rolled these dice. */
116 		Roll,
117 		/** Opponent has pushed the double cube onto the board */
118 		//OpponentDouble,
119 		/** You have pushed the double cube onto the board */
120 		//YouDouble,
121 		/** someone has doubled */
122 		Double,
123 		/** One player has rolled die, and the other player the other die. */
124 		FirstRoll,
125 		/** Someone makes the fist move */
126 		FirstMove,
127 		/** Player can't move. */
128 		CantMove,
129 		/** You should roll or double. GUI event */
130 		PleaseRollOrDouble,
131 		/** You should please move your pieces. GUI event */
132 		PleaseMove,
133 		/** You should accept or reject the double */
134 		PleaseAcceptOrRejectDouble,
135 		/** Someone wants to resign */
136 		Resign,
137 		/** FIBS wants a decision */
138 		PleaseAcceptOrRejectResign,
139 		/** A Player has rejected the resign offer */
140 		RejectResign,
141 		/** A Player has accepted the resign and won the game */ 
142 		AcceptAndWin,
143 	}
144 
145 	/** Get the Type of this GameEvent
146 	 * @return The Type of this GameEvent
147 	 */
148 	abstract public Type	getType();
149 
150 	
151 	/** events have two possible lives: transient and persistent.
152 	 *  
153 	 */
154 	public enum Life {
155 		/** Gets sent to the animation manager.  Deleted from queue when another message wants to get
156 		 * appended to the queue. <br>
157 		 * i.e. Don't tell the player to roll the dice once we have moved beyond that. 
158 		 */
159 		Transient,
160 		/** Event stays in the game queue for the duration of the game */
161 		Persistent
162 	}
163 
164 	/** Get the Life type of this GameEvent
165 	 * @return The permanent life type for this GameEvent
166 	 */
167 	abstract public Life	getLife();
168 	
169 	/** Who's event is this?
170 	 * @param xo Either Board.X or Board.O
171 	 */
172 	public void setWho(int xo) {
173 		this.who = xo;
174 	}
175 	/** Return the creator of this event (Black or White). <br>
176 	 * GameManager handles setting who because the object doesn't know about the Board (who is which player).
177 	 * @return {@link Board#X} or {@link Board#O} depending on who made this event
178 	 */
179 	public	int	getWho() {
180 		return(this.who);
181 	}
182 	
183 	/** Return -1 or 1 depending on whether this event plays the negative side or positive side of the board.
184 	 * @return -1 or 1
185 	 */
186 	public int	getDepth() {
187 		if (this.who == Board.O)
188 			return(-1);
189 		return(1);
190 	}
191 
192 	/** Get the playerName of this event.
193 	 * setPlayerName() is usually handled in the subclasses, which is where the parsing is.
194 	 * @return The name of the player who owns this event.
195 	 */
196 	public	String	getPlayerName() {
197 		return(playerName);
198 	}
199 	
200 	/** Set the playerName of this event.
201 	 * @param playerName The name of the player who created this event.
202 	 */
203 	public void setPlayerName(String playerName) {
204 		this.playerName = playerName;
205 	}
206 	
207 }