| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| GameEventFirstRoll |
|
| 1.2;1.2 |
| 1 | /****************************************************************************** | |
| 2 | * GameEventFirstRoll.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.1 2011/05/22 05:08:59 dick | |
| 10 | * All GameEvent objects are named starting with GameEvent. | |
| 11 | * | |
| 12 | * Revision 1.1 2011/05/21 05:11:36 dick | |
| 13 | * Handle the First Roll event. | |
| 14 | * | |
| 15 | * Revision 1.3 2011/05/16 21:20:25 dick | |
| 16 | * toString() gives some helpful debug info. | |
| 17 | * | |
| 18 | * Revision 1.2 2011/05/16 14:16:05 dick | |
| 19 | * getPlayerName() moves to the base class. | |
| 20 | * | |
| 21 | * Revision 1.1 2011/05/16 11:34:22 dick | |
| 22 | * Define one player Roll of the dice. | |
| 23 | * | |
| 24 | */ | |
| 25 | ||
| 26 | /* | |
| 27 | * This program is free software: you can redistribute it and/or modify | |
| 28 | * it under the terms of the GNU General Public License as published by | |
| 29 | * the Free Software Foundation, either version 3 of the License, or | |
| 30 | * (at your option) any later version. | |
| 31 | * | |
| 32 | * This program is distributed in the hope that it will be useful, | |
| 33 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 34 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 35 | * GNU General Public License for more details. | |
| 36 | * | |
| 37 | * You should have received a copy of the GNU General Public License | |
| 38 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 39 | * | |
| 40 | * The Original Code is BuckoFIBS, <http://www.buckosoft.com/BuckoFIBS/>. | |
| 41 | * The Initial Developer of the Original Code is Dick Balaska and BuckoSoft, Corp. | |
| 42 | * | |
| 43 | */ | |
| 44 | package com.buckosoft.fibs.domain.gameEvent; | |
| 45 | ||
| 46 | ||
| 47 | ||
| 48 | /** Define one player dice roll. i.e. "<code>You rolled 3, BlunderBot_X rolled 2</code>" | |
| 49 | * @author Dick Balaska | |
| 50 | * @since 2011/05/18 | |
| 51 | * @version $Revision$ <br> $Date$ | |
| 52 | * @see com.buckosoft.fibs.BuckoFIBS.GameManager | |
| 53 | * @see <a href="http://cvs.buckosoft.com/Projects/BuckoFIBS/BuckoFIBS/src/main/java/com/buckosoft/fibs/domain/gameEvent/GameEventFirstRoll.java">cvs GameEventFirstRoll.java</a> | |
| 54 | */ | |
| 55 | 0 | public class GameEventFirstRoll extends GameEventRoll { |
| 56 | 0 | private String[] playerNames = new String[2]; |
| 57 | ||
| 58 | @Override | |
| 59 | public Type getType() { | |
| 60 | 0 | return(Type.FirstRoll); |
| 61 | } | |
| 62 | ||
| 63 | @Override | |
| 64 | public Life getLife() { | |
| 65 | 0 | return(Life.Persistent); |
| 66 | } | |
| 67 | ||
| 68 | /** Return the player names of this event | |
| 69 | * @return The first and second player of this event. | |
| 70 | */ | |
| 71 | public String[] getPlayerNames() { | |
| 72 | 0 | return(playerNames); |
| 73 | } | |
| 74 | ||
| 75 | /** Parse the first roll string. "You rolled 3, BlunderBot_X rolled 2" | |
| 76 | * @param s The fibs string to parse | |
| 77 | */ | |
| 78 | public void parse(String s) { | |
| 79 | 0 | String[] ss = s.split(" "); |
| 80 | 0 | playerNames[0] = ss[0]; |
| 81 | 0 | playerNames[1] = ss[3]; |
| 82 | 0 | dice[0] = 0; |
| 83 | 0 | dice[1] = 0; |
| 84 | try { | |
| 85 | 0 | dice[0] = Integer.parseInt(ss[2].substring(0, 1)); |
| 86 | 0 | dice[1] = Integer.parseInt(ss[5].substring(0, 1)); |
| 87 | 0 | } catch (NumberFormatException e) { |
| 88 | 0 | e.printStackTrace(); |
| 89 | 0 | } |
| 90 | 0 | } |
| 91 | ||
| 92 | /** Return a debug string of this event | |
| 93 | * @return "<code>{player} first-roll 6-6</code>" | |
| 94 | */ | |
| 95 | public String toString() { | |
| 96 | 0 | String s = this.playerNames[0] + " first-roll " + dice[0] + "-" + dice[1]; |
| 97 | 0 | return(s); |
| 98 | } | |
| 99 | ||
| 100 | } |