![]() ![]() ![]() ![]() |
BINGO! |
[PENDING: this page should probably link to the "What's Interesting" discussions when further information is available about a particular class][PENDING: this page should also probably include snapshots of the UI classes where appropriate]
The code for the BINGO Game and Player programs are in 3 packages:
bingo.game
-- contains the classes and interfaces that implement the Game program.bingo.player
-- contains the classes and interfaces that implement the Player program.bingo.shared
-- contains the classes and interfaces that are or can be shared by both programs.The
bingo.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.The bingo.player package
Player
-- the main program for the Player application.When invoked, this class creates the UI for the Player application, implemented by
ControlPane
,bingo.shared.LightBoardPane
, andbingo.shared.GameStatusLabel
, and initializes it with the last-saved program settings. The Player class also creates aPlayerQueue
which is used to serialize RMI calls to the Game application.
ControlPane
-- implements the area of the Player's UI that lets the user change program settings and register for a game.
CardWindow
-- implements a window that the Player uses to display BINGO cards.The Player application displays one
CardWindow
per card being played in the current game.CardWindow
creates aPaperPane
for the background of the BINGO card and 25NumberButton
s, one for each space on the BINGO card.
PaperPane
-- a simple class that is used to display the background forCardWindow
.
NumberButton
-- a class used to implement each number on a BINGO card (used byCardWindow
).
PlayerParameters
-- keeps track of all the program settings for the Player application.These settings include whether or not the application should beep to announce new balls, the player's name, the name of the machine on which the Game application is running, the number of cards to play in each game, and the random number seed used to generate the cards. Also, this class, as a subclass of
bingo.shared.Parameters
, converts the program settings toProperties
, saves them to the file system whenever a change takes effect, and reads them in on start up.
PlayerQueue
-- a subclass ofjava.awt.EventQueue
used by the Player to serialize RMI calls to the Game application.The Player application posts events to this queue for each RMI call to the Game. The Player can invoke any one of three different remote methods in the Game. Each remote method is represented by one of these event classes:
RegisterEvent
,StatusRequestEvent
, andIWonEvent
. WhenPlayerQueue
processes an event in the queue, it makes the appropriate RMI call.
RegisterEvent
-- the event representing a remote method call to the Game application'smayIPlay
method.
StatusRequestEvent
-- the event representing a remote method call to the Game application'swhatsHappening
method.
IWonEvent
-- the event representing a remote method call to the Game application'sBINGO
method.
The bingo.shared package
Registrar
-- an interfaceThis interface is implemented by
bingo.game.RegistrarImpl
and defines the three remote methods supported by the Game application that can be called by the Player. One method is called by the Player to register for a game, one is called by the Player to claim BINGO, and one is called to get status from the Game.
Constants
-- an interface that contains a collection of game constants.One constant define in this file is the port number used by the Game to broadcast packets to the Player. Three other constants are group names used to categorize the broadcast packets into three types of information: balls, player status updates, and game status updates.
ErrorMessages
-- this class contains a collection of static methods that both the Game and the Player can call to print error messages.
BingoBall
-- a BINGO ball.Used extensively by
Card
andBallAnnouncer
.
Card
-- a BINGO card.Each space on the card contains a
BingoBall
. Created and signed by the Game.
EntranceTicket
-- an instance of this class is created by the Registrar when a Player registers and returned to the Player.It contains the Player's ID, cards, and other information needed by the Player to play.
PlayerRecord
-- represents a Player.Used by the
Registrar
andPlayerInfoPane
to keep track of players.
Answer
-- returned to the Player when the Player claims BINGO.This class informs the Player whether or not they actually won.
OverallStatusPane
-- implements the Game status UI.This window creates a
LightBoardPane
,PlayerInfoPane
, and aGameStatusLabel
. This is general enough that it could be used by the Player or another application.
PlayerInfoPane
-- used by the Game to display the players that are registered in this game.This Pane is a
PlayerListener
and uses aPlayerListenerThread
to listen for player status updates on theMulticastSocket
.
GameStatusLabel
-- used by the Player and by the Game to display game status.This Label is a
GameListener
and uses aGameListenerThread
to listen for game status updates on theMulticastSocket
.
LightBoardPane
-- used by the Player and by the Game to display the balls that have been announced in this game.This particular status pane works differently than the
PlayerInfoPane
andGameStatusLabel
. This Pane is not aBallListener
and doesn't use aBallListenerThread
, but must be created and informed of announced balls by aBallListener
using aBallListenerThread
. This is because the information is needed at a higher level in each program (theBallAnnouncer
throws an end-of-game ball which has implications for the rest of the program).
Utilities
-- a class with a couple of useful methods for positioning Swing components.This class is only used by the Player application, but could be used by other applications.
Listener
-- an empty interface whose sole purpose is to be a superinterface toBallListener
,PlayerListener
andGameListener
.
ListenerThread
-- the abstract superclass ofBallListenerThread
,PlayerListenerThread
, andGameListenerThread
.This class is a subclass of
Thread
provides a constructor which must be called by its subclass's constructors. Additionally, this class provides thestopListening
andfinalize
methods for its subclasses.
BallListener
-- an interface that defines the methods a class must implement in order to listen to balls as they are announced.This interface is implemented by
bingo.shared.OverallStatusPane
andbingo.player.Player
. ABallListener
uses aBallListenerThread
to listen to aMulticastSocket
for announced balls. The thread notifies itsBallListener
of interesting activities on the socket.
BallListenerThread
-- a subclass ofListenerThread
that receives balls from theMulticastSocket
as they are sent by the Game.This thread is created with a
BallListener
which is informed of each ball as it is announced.
PlayerListener
-- an interface that defines the methods a class must implement in order to listen to player status updates.A
PlayerListener
uses aPlayerListenerThread
to listen to aMulticastSocket
for player status messages. The thread notifies itsPlayerListener
of interesting activities on the socket.PlayerInfoPane
implements this interface and creates aPlayerListenerThread
for listening.
PlayerListenerThread
-- a subclass ofListenerThread
that gets player status updates from theMulticastSocket
as they are sent by the Game.This thread is created with a
PlayerListener
which is informed of status messages as they are received.
GameListener
-- an interface that defines the methods a class must implement in order to listen to game status updates.A
GameListener
uses aGameListenerThread
to listen to aMulticastSocket
for game status messages. The thread notifies itsGameListener
of interesting activities on the socket.GameStatusLabel
implements this interface and createsGameListenerThread
for listening.
GameListenerThread
-- a subclass ofListenerThread
that gets game status updates from theMulticastSocket
as they are sent by the RingMaster.This thread is created with a
GameListener
which is informed of status messages as they are received.
BingoException
,NoMoreBallsException
-- exceptions for the BINGO game.
![]() ![]() ![]() ![]() |
BINGO! |