View Javadoc
1   /******************************************************************************
2    * GameEventFirstMove.java - Someone makes the first move
3    * $Id$
4    * 
5    * BuckoFIBS - Backgammon by BuckoSoft
6    * Copyright© 2011 - Dick Balaska - BuckoSoft, Corp.
7    * 
8    * $Log$
9    */
10  
11  /* 
12   * This program is free software: you can redistribute it and/or modify
13   * it under the terms of the GNU General Public License as published by
14   * the Free Software Foundation, either version 3 of the License, or
15   * (at your option) any later version.
16   *
17   * This program is distributed in the hope that it will be useful,
18   * but WITHOUT ANY WARRANTY; without even the implied warranty of
19   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20   * GNU General Public License for more details.
21   *
22   * You should have received a copy of the GNU General Public License
23   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24   *
25   * The Original Code is BuckoFIBS, <http://www.buckosoft.com/BuckoFIBS/>.
26   * The Initial Developer of the Original Code is Dick Balaska and BuckoSoft, Corp.
27   * 
28   */
29  package com.buckosoft.fibs.domain.gameEvent;
30  
31  import org.slf4j.Logger;
32  import org.slf4j.LoggerFactory;
33  
34  import com.buckosoft.fibs.domain.Board;
35  
36  
37  /** Someone makes the first move.
38   * @author Dick Balaska
39   * @since 2011/06/26
40   * @version $Revision$ <br> $Date$
41   * @see com.buckosoft.fibs.BuckoFIBS.GameManager
42   * @see <a href="http://cvs.buckosoft.com/Projects/BuckoFIBS/BuckoFIBS/src/main/java/com/buckosoft/fibs/domain/gameEvent/GameEventFirstMove.java">cvs GameEventFirstMove.java</a>
43   */
44  public class GameEventFirstMove extends GameEvent {
45      private Logger logger = LoggerFactory.getLogger(getClass());
46  	private	int[] dice = new int[2];
47  
48  	@Override
49  	public Type getType() {
50  		return(Type.FirstMove);
51  	}
52  
53  	@Override
54  	public Life getLife() {
55  		return(Life.Transient);
56  	}
57  
58  	/** Default constructor */
59  	public GameEventFirstMove() {}
60  
61  	/** Return the two dice rolled in this event
62  	 * @return The array of the dice
63  	 */
64  	public int[]	getDice() {
65  		return(dice);
66  	}
67  	
68  	/** Set the dice to be used for this turn
69  	 * @param dice The dice (from the previous roll)
70  	 */
71  	public void setDice(int[] dice) {
72  		this.dice = dice;
73  	}
74  
75  	/** Parse either "<code>It's your turn to move.</code>" or "<code>dickbalaska makes the first move.</code>"
76  	 * along with the first dice.
77  	 * @param s The FIBS string to parse.
78  	 * @param firstRoll The previous FirstRoll which contains his and her dice.
79  	 * @param board A board to match player names against.
80  	 */
81  	public void parse(String s, GameEventFirstRoll firstRoll, Board board) {
82  		this.dice = firstRoll.getDice();
83  		String[] ss = s.split(" ", 2);
84  		if (ss[0].equals("It's"))
85  			this.who = Board.O;
86  		else if (ss[0].equals(firstRoll.getPlayerNames()[0]))
87  			this.who = Board.O;
88  		else if (ss[0].equals(firstRoll.getPlayerNames()[1]))
89  			this.who = Board.X;
90  		else if (ss[0].equals(board.getPlayerName()[Board.O]))
91  			this.who = Board.O;
92  		else if (ss[0].equals(board.getPlayerName()[Board.X]))
93  			this.who = Board.X;
94  		else {
95  			logger.error("Can't Determine first move player");
96  			logger.error("s = " + s);
97  			logger.error("firstRoll = " + firstRoll.toString());
98  		}
99  			
100 	}
101 
102 	/** A debug string of this object.
103 	 * @return "<code>Please move {checkersToMove} pieces. Dice= {dice0}-{dice1}</code>"
104 	 */
105 	public String toString() {
106 		return("First move. who=" + who + " Dice= " + dice[0] + "-" + dice[1]);
107 	}
108 }