User Tools

Site Tools


bingo

This is an old revision of the document!


Bingo

It's not just a song from summer camp, its an old-timey game: Here is a Video Explaining the rules. We will start with the machine that randomly chooses the Bingo Ball to be called. Next we will generate the player's BingoCard which the user needs to mark until a winning Bingo pattern is made. Finally we will make a BingoGame class that will put all these elements together by showing the called numbers, the player's BingoCards and a BINGO button if the player thinks they have a winning Bingo Pattern.

1. BingoBallHopper

First we will make a BingoBallHopper class that will make all 75 bingo balls, and randomly selecting them one at a time, kepping track of which ones were called. To save time here is the BingoBall.java class, the BingoHopperTester, and the starter code BingoHopper.java. You just have to finish the constructor, the nextBall() method and called() method. Read the comments above each for the details.

2. BingoCell

Next we turn to the player's Bingo cards. We will make a clickable box for each square that we'll call the BingoCell class, then make a 5×5 grid of these which we will call the BingoCard class.

The BingoCell class would be a subclass of Cell that would add the attributes of a number and a font. It will have its own draw method that can draw its number. Here is a hint on how to do one of the Constructors:

Here is a hint on how to build upon the draw method of the parent class:

For now, let a cell that is “off” represent an uncalled number, and a “on” cell be one that the player has clicked on when that number is called. Later you may wish represent a called number differently. The class should have the following:

  1. The Cell class 3 Constructors to allow a client class more access and flexibility. Add at least one more constructor to the BingCell class that uses one of the other Cell class's constructors. Remember to have a parameter to initialize the BingoCell's number
  2. accessor methods so a client class can know a cell's number (getNumber, getFont, setNumber, setFont)
  3. Change the draw method so that if the number is 0, it will draw “free” instead. Here is a hint:

You can test out your BingoCell class by adapting CellTester.java to construct new BingoCells in the resetCells() method.

hint

The rest would not need to be changed since a BingoCell is a Cell. (Eventually, your BingoBoard class would be the ultimate test of your BingoCell class) When you are done, the CellTester application should look like something like this:

3. BingoCard

The BingoCard class will need:

  1. the line import java.awt.*;
  2. a 2-D array of BingoCells called board
  3. a top, left for the top corner of the board should be drawn
  4. a size for the of the BingoBoard. The board will be square, because of margins, the size of the BingoCells would be a fraction of the size.
  5. a method contains(int number) that returns true if the number is in board, and false otherwise.
  6. a method randomInt(int min, int max) that returns a random number from min to max, inclusive that is not already on the board (Hint: The number of possible choices would be Math.abs(max-min)+1).
  7. 2 Constructors: one that has three parameters (top, left, and size) and another without parameters (that sets the top and left to 0, and the size fo 350). Each constructor so that the card so that:
    1. The “B” column has 5 unique numbers from 1-15
    2. The “I” column has 5 unique numbers from 16-30
    3. The “N” column has 4 unique numbers from 31-45, with the center a “Free” cell
    4. The “G” column has 5 unique numbers from 46-60
    5. The “O” column has 5 unique numbers from 61-75
  8. a toString method that has no parameters, and returns a string representation of the board. Use \n to make a newline in the String to get different rows. It should be similar to :
  9. a method 'hasBingoSelected' (that returns a boolean) which detects a win for the rows, columns, and diagonals Sometimes there are variants of the game such as “blackout,” or “corners,” or “box” variants).
  10. a draw method (that takes a Graphics parameter) which calls all the BingoCells in board to draw themselves.

The “Extreme Programming” approach is to begin by writing one or more client classes of BingoBoard to test each of these specifications. The first 4 can be done with a text based application, starting off with a simple one like

The draw method can be tested by BingoBoardTester that might look like this:

4. BingoGame

The BingoGame class can have one or more BingoBoards and random numbers from 1-75 can be “called out.” These are randomly selected, but each number can only be called out once. The number called is only on the screen temporarily (you probably want to use the javax.swing.Timer like the Simon Game

It is up to the player to “dob” or select the ones that are called. There should be a bingo button for the player to press if they think they have a “Bingo”.

bingo.1620325832.txt.gz · Last modified: 2021/05/06 14:30 by frchris