1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.cb.jset.client;
21
22 import org.cb.jset.JSetGameImpl;
23 import org.cb.jset.SetGamePlayer;
24 import org.cb.jset.SetGameConnection;
25 import org.cb.jset.CardProperties;
26 import org.cb.jset.CardSet;
27 import org.cb.jset.MatchingException;
28
29
30 /***
31 * A Game implementation to play localy.
32 *
33 * FIXME GameListener not registered.
34 * @author jerome@coffeebreaks.org - last modified by $LastModifiedBy$
35 * @version $Id: LocalGame.java 130 2004-04-15 05:18:07Z jerome $
36 */
37 public class LocalGame extends AbstractGame
38 {
39 private JSetGameImpl _game;
40 private SetGamePlayer _player;
41 private SetGameConnection _connection;
42 private String _playerName = "Me";
43 private boolean _isBlocked = false;
44
45
46 public void start()
47 {
48 _game = new JSetGameImpl("Standalone", 1);
49 _game.start();
50 _player = initPlayer();
51 _connection = _game.connect(_player);
52 }
53
54 SetGamePlayer initPlayer()
55 {
56 return new MyPlayer();
57 }
58
59 public boolean isBlocked()
60 {
61 return _isBlocked;
62 }
63
64 public String getPlayerName()
65 {
66 return _playerName;
67 }
68
69 /***
70 * An implementation of a player for this local game.
71 */
72 class MyPlayer implements SetGamePlayer
73 {
74 /***
75 * @return the name of the player.
76 */
77 public String getName()
78 {
79 return getPlayerName();
80 }
81
82 /***
83 * Called by a game when the player should be blocked.
84 * @see #isBlocked()
85 */
86 public void block()
87 {
88 _isBlocked = true;
89 }
90
91 /***
92 * Called by a game when the player should be unblocked.
93 * @see #isBlocked()
94 */
95 public void unblock()
96 {
97 _isBlocked = false;
98 }
99
100 /***
101 * A blocked player doesn't have the right to play.
102 * @return <code>true</code> is the player is blocked, <code>false</code> otherwise.
103 */
104 public boolean isBlocked()
105 {
106 return _isBlocked;
107 }
108
109 /***
110 * Called to notify a disconnection from a game.
111 */
112 public void disconnect()
113 {
114
115 LocalGame.this.fireGameChange(new GameEvent(GameEvent.END));
116 }
117
118 /***
119 * @inheritDoc
120 */
121 public void cardsAdded(final CardProperties[] cards)
122 {
123 LocalGame.this.fireCardsAdded(cards);
124 }
125
126 /***
127 * @inheritDoc
128 */
129 public void setRemoved(final CardSet set)
130 {
131 LocalGame.this.fireSetRemoved(set);
132 }
133 }
134
135 public void stop()
136 {
137 _connection.close();
138 }
139
140 public void endTurn()
141 {
142 throw new IllegalStateException("FIXME: not implemented");
143 }
144
145 public void removeSet(final CardSet set) throws MatchingException
146 {
147 _connection.matchSet(set);
148 }
149 }