1 /******************************************************************************
2 * GameEventDouble.java - Someone has doubled
3 * $Id$
4 *
5 * BuckoFIBS - Backgammon by BuckoSoft
6 * Copyright© 2013 - Dick Balaska - BuckoSoft, Corp.
7 *
8 * $Log$
9 * Revision 1.4 2013/09/12 06:40:24 dick
10 * Animating the double cube.
11 *
12 */
13
14 /*
15 * This program is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 *
28 * The Original Code is BuckoFIBS, <http://www.buckosoft.com/BuckoFIBS/>.
29 * The Initial Developer of the Original Code is Dick Balaska and BuckoSoft, Corp.
30 *
31 */
32 package com.buckosoft.fibs.domain.gameEvent;
33
34 import com.buckosoft.fibs.domain.Board;
35
36 /** Someone doubled. Awaiting opponent's reply.
37 * @author Dick Balaska
38 * @since 2013/09/09
39 * @version $Revision$ <br> $Date$
40 * @see com.buckosoft.fibs.BuckoFIBS.GameManager
41 * @see <a href="http://cvs.buckosoft.com/Projects/BuckoFIBS/BuckoFIBS/src/main/java/com/buckosoft/fibs/domain/gameEvent/GameEventDouble.java">cvs GameEventDouble.java</a>
42 */
43 public class GameEventDouble extends GameEvent {
44 private int cubeBefore;
45 private int cubeAfter;
46 protected int whoDoubled;
47
48 @Override
49 public Type getType() {
50 return(Type.Double);
51 }
52
53 @Override
54 public Life getLife() {
55 return(Life.Persistent);
56 }
57
58 /** Return {@link Board#X} or {@link Board#O}
59 */
60 public int getWhoDoubled() {
61 return(whoDoubled);
62 }
63
64 /** A dummy parser. Nothing to parse for this event
65 * @param unused
66 */
67 public void parse(String unused) {
68 }
69
70 /** Get the value of the cube before the double
71 * @return the cubeBefore
72 */
73 public int getCubeBefore() {
74 return cubeBefore;
75 }
76
77 /** Set the current value of cube as well as the derived, next value of the cube (if accepted).
78 * @param cubeBefore the value of the cube (from the last board) to set
79 */
80 public void setCubeBefore(int cubeBefore) {
81 this.cubeBefore = cubeBefore;
82 this.cubeAfter = this.cubeBefore * 2;
83 if (this.cubeAfter > 64)
84 this.cubeAfter = 1;
85 }
86
87 /** Get the value of the cube after the double
88 * @return the cubeAfter
89 */
90 public int getCubeAfter() {
91 return cubeAfter;
92 }
93
94 /**
95 * @param cubeAfter the cubeAfter to set
96 */
97 //public void setCubeAfter(int cubeAfter) {
98 // this.cubeAfter = cubeAfter;
99 //}
100
101 /** Parse the string that created this GameEvent. <br>
102 * <code>dickbalaska doubles.</code>
103 * @param s The FIBS string
104 * @param b The Board prior to this double (used to determine which player is doubling)
105 */
106 public void parse(String s, Board b) {
107 String[] ss = s.split(" ");
108 playerName = ss[0];
109 if (playerName.equals(b.getPlayerName()[Board.O])) {
110 whoDoubled = Board.turnO;
111 b.getWasDoubled()[Board.O] = true;
112 } else {
113 whoDoubled = Board.turnX;
114 b.getWasDoubled()[Board.X]= true;
115 }
116 }
117
118 }