Putting It All Together |
bingo.game
The following lists and describes all the classes in thebingo.game
package.
BINGO
-- the main program for the BINGO Game.This class creates a
RingMaster
object, aRegistrar
(and registers it as a remote object), and aControlPane
in aJFrame
.
RingMaster
-- this object is the ring master for the Game, and creates and controls most of the other objects in the Game program and their communication.
- This object maintains the game state and the game number.
- This object is also used to synchronize the activities of
GamesThread
,RegistrarImpl
, andBallAnnouncer
.- Additionally, this object creates most of the other objects needed by the game:
When creating these objects, the
- a
SocketGate
for broadcasting messages to the Player.- a
GameParameters
object for maintaining the parameters of the game, and reading them from and writing them to the file system asProperties
when necessary- a
Notary
for signing cards- a
Roster
for keeping track of players- a
Stack
for keeping track of the balls that have been announced in the current gameRingMaster
either passes references to other objects into the constructor so that the objects can directly message one another, or provides an API so that the objects can indirectly message one another through theRingMaster
.
RegistrarImpl
-- this class implements a remote object--theRegistrar
.The Player uses RMI to call one of the
Registrar
's three remote methods:
whatsHappening
--to get a status string from the GamemayIPlay
--to register for the next game and get cards to play withBINGO
--to claim BINGO, this method verifies the card and tells the player whether or not the card really won
ControlPane
-- this class implements the control area of the Game window.This class also creates a
GamesThread
to cycle through games until the user clicks the No More Games button.
GamesThread
-- this class is a subclass ofThread
whoserun
method continually cycles through BINGO games until told to stop.
GamesThread
is created byControlPane
, and loops until told to stop by theControlPane
. Each iteration of the loop is one BINGO game. A BINGO game begins by waiting for the first player to register. After the first player registers, the loop starts a count down during which other players can register. After the count down has complete, the game begins. TheGamesThread
creates and starts aBallAnnouncer
thread that randomly chooses and announces balls until there's a winner, or until there are no more balls. After a game is over, the cycle begins again.
BallAnnouncer
-- a thread subclass.This class is used by the Game announce each ball to the players.
BagOfBalls
-- an interface that defines the protocol for a "bag of balls".The protocol includes one method definition,
getNext
, which theBallAnnouncer
calls to reach into the bag and choose the next BINGO ball.Currently, the BINGO game has one class that implements this interface,
RandomBag
. This is the class used by the game to generate a random sequence of balls to announce. However, we use an interface here so that programmers can easily substitute their own implementations of aBagOfBalls
. (Incidentally, we used this feature to implement "cheater" bags so that we could more easily test the game.)
RandomBag
-- our implementation ofBagOfBalls
.This is the actual class that generates a random sequence of balls to be announced by
BallAnnouncer
.
GameParameters
-- keeps track of all the game parameters.Game parameters include max number of players per game, max number of cards per player, and so on. Also, this class, as a subclass of
bingo.shared.Parameters
, converts the game parameters toProperties
, saves them to the file system whenever a change takes effect, and reads them in on start up.
NotaryPublic
-- digitally signs cards and verifies the signature on any card claiming BINGO.
Roster
-- keeps a list of the players in the current game.The
Roster
contains onePlayerRecord
object for each player. APlayerRecord
contains the player's name, ID, and number of cards.
SocketGate
-- broadcasts status messages from the Game to the Player programs.All messages that are broadcast from the Game go through this object. This includes the balls that are announced, games status messages, and player status updates. To receive these messages the player program must listen for them on different groups of a
MulticastSocket
.
States
-- an interface that declares a few constants used by theRingMaster
to indicate the current state of the game.
Putting It All Together |