View Javadoc
1   /******************************************************************************
2    * GameEventRoll.java - Define one player Roll of the dice
3    * $Id$
4    * 
5    * BuckoFIBS - Backgammon by BuckoSoft
6    * Copyright© 2011 - Dick Balaska - BuckoSoft, Corp.
7    * 
8    * $Log$
9    * Revision 1.4  2011/05/21 05:14:39  dick
10   * Roll is persistent.  Make the dice protected so FirstRoll can get them.
11   *
12   * Revision 1.3  2011/05/16 21:20:25  dick
13   * toString() gives some helpful debug info.
14   *
15   * Revision 1.2  2011/05/16 14:16:05  dick
16   * getPlayerName() moves to the base class.
17   *
18   * Revision 1.1  2011/05/16 11:34:22  dick
19   * Define one player Roll of the dice.
20   *
21   */
22  
23  /* 
24   * This program is free software: you can redistribute it and/or modify
25   * it under the terms of the GNU General Public License as published by
26   * the Free Software Foundation, either version 3 of the License, or
27   * (at your option) any later version.
28   *
29   * This program is distributed in the hope that it will be useful,
30   * but WITHOUT ANY WARRANTY; without even the implied warranty of
31   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32   * GNU General Public License for more details.
33   *
34   * You should have received a copy of the GNU General Public License
35   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
36   *
37   * The Original Code is BuckoFIBS, <http://www.buckosoft.com/BuckoFIBS/>.
38   * The Initial Developer of the Original Code is Dick Balaska and BuckoSoft, Corp.
39   * 
40   */
41  package com.buckosoft.fibs.domain.gameEvent;
42  
43  
44  /** Define one player dice roll.  i.e. "BlunderBot_IV rolls 2 and 6."
45   * @author Dick Balaska
46   * @since 2011/05/15
47   * @version $Revision$ <br> $Date$
48   * @see com.buckosoft.fibs.BuckoFIBS.GameManager
49   * @see <a href="http://cvs.buckosoft.com/Projects/BuckoFIBS/BuckoFIBS/src/main/java/com/buckosoft/fibs/domain/gameEvent/GameEventRoll.java">cvs GameEventRoll.java</a>
50   */
51  public class GameEventRoll extends GameEvent {
52  	protected	int[] dice = new int[2];
53  
54  	@Override
55  	public Type getType() {
56  		return(Type.Roll);
57  	}
58  
59  	@Override
60  	public Life getLife() {
61  		return(Life.Persistent);
62  	}
63  
64  	/** Return the two dice rolled in this event
65  	 * @return The array of the dice
66  	 */
67  	public int[]	getDice() {
68  		return(dice);
69  	}
70  	
71  	public void parse(String s) {
72  		String[] ss = s.split(" ");
73  		playerName = ss[0];
74  		dice[0] = 0;
75  		dice[1] = 0;
76  		try {
77  			dice[0] = Integer.parseInt(ss[2]);
78  			dice[1] = Integer.parseInt(ss[4].substring(0, 1));
79  		} catch (NumberFormatException e) {
80  			e.printStackTrace();
81  		}
82  	}
83  	public String	toString() {
84  		String s = this.playerName + " roll " + dice[0] + "-" + dice[1];
85  		return(s);
86  	}
87  
88  }