The JavaTM Tutorial

| Start of Tutorial > Start of Trail > Start of Lesson | Search Feedback Form

Trail: Putting It All Together
Lesson: BINGO!

## The Classes in the bingo.game Package

> The following lists and describes all the classes in the `bingo.game` package.
> - `BINGO`-- the main program for the BINGO Game.

>   This class creates a `RingMaster` object, a `Registrar` (and registers it as a remote object), and a `ControlPane` in a `JFrame`.

> - `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.

>   1. This object maintains the game state and the game number.
>   2. This object is also used to synchronize the activities of `GamesThread`, `RegistrarImpl`, and `BallAnnouncer`.
>   3. Additionally, this object creates most of the other objects needed by the game:
>      - 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 as `Properties` 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 game
>      When creating these objects, the `RingMaster` 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 the `RingMaster`.

> - `RegistrarImpl`-- this class implements a remote object--the `Registrar`.

>   The Player uses RMI to call one of the `Registrar`'s three remote methods:

>   1. `whatsHappening`--to get a status string from the Game
>   2. `mayIPlay`--to register for the next game and get cards to play with
>   3. `BINGO`--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 of `Thread` whose `run` method continually cycles through BINGO games until told to stop.

>   `GamesThread` is created by `ControlPane`, and loops until told to stop by the `ControlPane`. 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. The `GamesThread` creates and starts a `BallAnnouncer` 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 the `BallAnnouncer` 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 a `BagOfBalls`. (Incidentally, we used this feature to implement "cheater" bags so that we could more easily test the game.)

> - `RandomBag`-- our implementation of `BagOfBalls`.

>   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 to `Properties`, 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 one `PlayerRecord` object for each player. A `PlayerRecord` 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 the `RingMaster` to indicate the current state of the game.

| Start of Tutorial > Start of Trail > Start of Lesson | Search Feedback Form