View Javadoc
1   /******************************************************************************
2    * GameEventPleaseMove.java - Fibs wants the player to decide what pieces to move.
3    * $Id$
4    * 
5    * BuckoFIBS - Backgammon by BuckoSoft
6    * Copyright© 2011 - Dick Balaska - BuckoSoft, Corp.
7    * 
8    * $Log$
9    * Revision 1.2  2011/05/21 20:22:19  dick
10   * Add toString().
11   *
12   * Revision 1.1  2011/05/21 05:13:16  dick
13   * Fibs wants the player to decide what pieces to move.
14   *
15   */
16  
17  /* 
18   * This program is free software: you can redistribute it and/or modify
19   * it under the terms of the GNU General Public License as published by
20   * the Free Software Foundation, either version 3 of the License, or
21   * (at your option) any later version.
22   *
23   * This program is distributed in the hope that it will be useful,
24   * but WITHOUT ANY WARRANTY; without even the implied warranty of
25   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26   * GNU General Public License for more details.
27   *
28   * You should have received a copy of the GNU General Public License
29   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
30   *
31   * The Original Code is BuckoFIBS, <http://www.buckosoft.com/BuckoFIBS/>.
32   * The Initial Developer of the Original Code is Dick Balaska and BuckoSoft, Corp.
33   * 
34   */
35  package com.buckosoft.fibs.domain.gameEvent;
36  
37  
38  /** Fibs wants the player to decide what pieces to move.
39   * @author Dick Balaska
40   * @since 2011/05/18
41   * @version $Revision$ <br> $Date$
42   * @see com.buckosoft.fibs.BuckoFIBS.GameManager
43   * @see <a href="http://cvs.buckosoft.com/Projects/BuckoFIBS/BuckoFIBS/src/main/java/com/buckosoft/fibs/domain/gameEvent/GameEventPleaseMove.java">cvs GameEventPleaseMove.java</a>
44   */
45  public class GameEventPleaseMove extends GameEvent {
46  	private int checkersToMove;
47  	private	int[] dice = new int[2];
48  
49  	@Override
50  	public Type getType() {
51  		return(Type.PleaseMove);
52  	}
53  
54  	@Override
55  	public Life getLife() {
56  		return(Life.Transient);
57  	}
58  
59  	/** Default constructor */
60  	public GameEventPleaseMove() {}
61  
62  	/** How many checkers should You move this turn?
63  	 * @return the checkersToMove
64  	 */
65  	public int getCheckersToMove() {
66  		return checkersToMove;
67  	}
68  
69  	/** Set the number of checkers that will be moved this turn.
70  	 * Note that this is/should be only called from the FIBS_YourTurnToMove handler 
71  	 * (first roll of the game is always 2 dice)
72  	 * @param checkersToMove The number of checkers.
73  	 */
74  	public void setCheckersToMove(int checkersToMove) {
75  		this.checkersToMove = checkersToMove;
76  	}
77  
78  	/** Return the two dice rolled in this event
79  	 * @return The array of the dice
80  	 */
81  	public int[]	getDice() {
82  		return(dice);
83  	}
84  	
85  	/** Set the dice to be used for this turn
86  	 * @param dice The dice (from the previous roll)
87  	 */
88  	public void setDice(int[] dice) {
89  		this.dice = dice;
90  	}
91  
92  	/** Parse the number of pieces to move. "<code>Please move 2 pieces.</code>"
93  	 * @param s The string from fibs.
94  	 */
95  	public void parse(String s) {
96  		String[] ss = s.split(" ");
97  		try {
98  			this.checkersToMove = Integer.parseInt(ss[2]);
99  		} catch (NumberFormatException e) {
100 			e.printStackTrace();
101 		}
102 	}
103 	
104 	/** A debug string of this object.
105 	 * @return "<code>Please move {checkersToMove} pieces. Dice= {dice0}-{dice1}</code>"
106 	 */
107 	public String toString() {
108 		return("Please move " + this.checkersToMove + " pieces.  Dice= " + dice[0] + "-" + dice[1]);
109 	}
110 }