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.
BingoCard
class 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 substring
method of the String
class will be useful for retrieving the individual letters from the BINGO
variable. 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
BingoGUI
class that are static
methods by using BingoGUI.staticMethodName()
.)
findCellContaining
and
your column-winning strategy) as necessary.
Compile and run your program, comparing your expected and actual results.
indicateCardWon
method to "mark" the
letters in the column headings.
Initialize Card with Random Numbers
Modify the initCol
and
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 numUsed
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
selected, and false
otherwise. For example, if you randomly
pick the number 45, and if numUsed[45]
has the value
true
, then 45 has already been used and you can't use it
again. If numUsed[45]
has the value false
,
then you can put a 45 on your card. (Don't forget to set
numUsed[45]
to true
.)
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.