In this programming project, which follows up on the Bingo Game Lab, you will add more functionality to your Bingo Game.
The program needs several enhancements to act like a real Bingo game. One problem is that the card should be initialized with a different set of random numbers every time the game is played; instead, this version places the same pre-defined numbers in each column every time. (Another difference is that a real game would have multiple cards, but our game still has only one card.) There are a variety of patterns that could be considered a winning pattern in Bingo, such as a complete diagonal of marked numbers, marked numbers in the four corners, marked numbers in a postage stamp pattern etc. Each of these could be considered a separate strategy for winning.
Add column headings to the Bingo card.
BingoCardclass to add the letters that spell out the word "BINGO" as column headings on the top of your Bingo card, as in the picture below. Your code should use a loop that iterates over all of the entries in the first row; it should not add each letter individually. The
substringmethod of the
Stringclass will be useful for retrieving the individual letters from the
BINGOvariable. If this is coded correctly, your program should work just as well if the line:
private static final String BINGO = "BINGO";is replaced with the line:
private static final String BINGO = "BINGOLO";(Stop and Think: What color should the Bingo letters be? Is it a color given by the user or a color you define? Which class knows what color the heading should be? Notice that the Bingo Card doesn't know about the Bingo GUI. We can still access methods in the
BingoGUIclass that are static methods by using
findCellContainingand your column-winning strategy) as necessary. Compile and run your program, comparing your expected and actual results.
indicateCardWonmethod to "mark" the letters in the column headings.
Initialize Card with Random Numbers
getUnusedRandomNumber methods to initialize the cells
on a Bingo card with unique random numbers from the correct range in
each column, as in the picture above. That is, the "B" column
might contain five different random numbers in the range of 1
.. 15, the "I" column should have five different random numbers in
the range of 16 .. 30, etc. (The "B" range should actually
go from 1 to the subrange size, in case the subrange size is a
number other than 15.)
You will use the
instance variable to make sure that the same number is not added to
the card more than once. An entry in the
numUsed array should be
true if the corresponding number has already been
false otherwise. For example, if you randomly
pick the number 45, and if
numUsed has the value
true, then 45 has already been used and you can't use it
numUsed has the value
then you can put a 45 on your card. (Don't forget to set
Use the comments for the
numUsed instance variable and the comments provided in
the methods to guide your implementation.
Add additional winning strategy options.
Optional: Add one or more "free" spaces to your card.
Submit your modifications.