Mathematical Bingo
Plan
the project | Design
the project | Programming
| Assignments
We will make
- to find sums that the computer generates, to wait for the Bingo
We need to know
- to work with the buttons, to define events on them
We will learn
- to create a square game board of the buttons, to put various
Captions on the buttons, to check the fulfillment of the more difficult
condition.
Mathematical Bingo
is quite interesting game for one player or for a player and
a computer: on the board of 5x5 boxes there are 25 numbers of
the range, e.g. from 2 to 20 (for older children we can choose
bigger numbers). Then the computer generates examples to add
(for older pupils we can use other mathematical operations.)
The player's task is to find the result for this example on
the board or to press the button pass, if there is not
the result on the board.
If the player finds the result correctly, this number disappears
from the board. The game will finish if all numbers in any line
or column or diagonal are "disappeared". If the player does
not determine the result correctly or he or she does not notice
the result on the board, the number of his or her errors will
increase. |
 |
The game board for Bingo is 5x5 sized and it consists of the buttons
- it could consist of the turtles, but the solution with the buttons
is easier.
On each of them there will be the number generated by the computer
written in its Caption
(command in the context menu Change).
The button New game is for starting the new game. The button
Pass passes the example if its result is not on the board.
There are several texts on the page:
- text1, is the generated example e.g. to add two numbers
of the range from 1 to 10
- text2 with the notice Errors
- text3 to count the errors, there is the value 0 at the
beginning
- text4 with the red notice BINGO, if the player wins
At the beginning cancel the turtle t1
formed at the beginning of Imagine - select Erase
t1 in its context menu.
The game board could be created by copying through Clipboard, but
after previous project we can create the class.
What is common for all buttons - bingo?
- size, select e.g. 40x40 pixels
- the event onPush,
that finds out whether the player solve the correct number that
is the solution of generated example and then it finds out whether
there is bingo - we can define the command checkBingo
- procedure checkBingo,
that finds out if there is bingo in any line or column or diagonal,
i.e. if all buttons in this shape have an empty Caption
How do they differ vice versa?
- position
- value in Caption
Create the class Bingo, with the variable size and event
onPush that
calls the command checkBingo.
We define the command checkBingo
in the procedure editor - we could define it in the line but it is
more transparent in the editor.
? newClass "Button "Bingo
[size [40 40] onPush [checkBingo]]
Browse the Explore window, double click on the class Bingo
and in the Procedure tab define one simple procedure checkBingo
; we clear its item Caption of the button where the event
onPush became
the procedure is so simple that we cannot imagine what to
type in yet.
to checkBingo
setCaption "||
end
To create the buttons of the game board we use the global procedure
gameButtons
that is able to create all 25 buttons Bingo:
? ed "gameButtons
to gameButtons
let "x -140
let "y 110
let "randomNumber 2+random 19
repeat 5
[let "r repc
repeat 5
[let "s repc let "randomNumber 2+random 19
new "Bingo
[name (word :r :s)
pos (list :x :y)
Caption (:randomNumber)]
make "x :x+40]
make "x -140 make "y :y-40]
end
Create the game board and try to click on individual buttons:
? gameButtons
There are 25 buttons in 5 lines; there is a number up to twenty
on each of them. If we click on the button, the number disappears.
Insert the new button on the page, change its name to newGame,
change Caption
to New game
and define the event onPush
to call the procedure gameButtons,
try the button.
Insert another button on the page, change its name to pass,
change Caption
to pass.
Note: We use the same term for the buttons' name and caption;
so it is easy to remember.
Insert the textBox
on the page, the example will appear in there - notice that its
name is text1,
change its font, size and colour as you like.
When is the new example to appear?
- at the beginning of the new game,
- at right or wrong result of the example, i.e. at the event
onPush of
any button Bingo of the game board,
- at pressing the button pass
There are several situations where we generate a new example. That's
why we need to create a global command:
? ed "genExample
to genExample
let "add1 1+random 10
let "add2 1+random 10
make "mySum :add1+:add2
text1'setValue (word :add1 "+ :add2 "=)
end
Note: Variables add1
and add2 are
local, but the variable mySum
is global we will need this variable to check the value on
the pressed button - Bingo.
Now complete the calls of the procedure in all three mentioned
situations:
- open the dialogue Change
of the button newGame
and type in the call of the command genExample
after the call of the command gameButtons
- press the Explore Project Window and change the command checkBingo
so that the Caption
empties only if the value in global variable
mySum
is equal to value on that button. After checking
this value, call the command for generating a new example again:
to checkBingo
if Caption=:mySum [setCaption
"||]
genExample
end
- Open the dialogue Change
of the button pass
and in its event onPush
also type in the call of the command for generating
a new addition example
The command checkBingo
is expected to find out whether
there is an error after a player's turn; i.e. a player clicked
the button with the wrong result. Then we need to increase the number
of the player's errors. They could be stored e.g. in the text or
whether at this click on the button there is bingo, i.e. if
all the buttons - Bingo in any line, column or diagonal have an
empty Caption. Then the notice BINGO will be shown, that
can be prepared in the text too
We could check whole the game board, but because we well named
the buttons ( similarly as we name matrixes in Mathematic), we
can check just the line or the column where the bingo could really
appear according to the last player's click. We divide the checking
of lines, columns and diagonals into three parts:
the line, where bingo could appear is determined by the
first element of the clicked turtle's name, i.e. we need to
check whole line by checking if the buttons in this line have
an empty Caption
the column, with the bingo is determined by the second element
of the name of the clicked button. i.e. we need to check whole
column by checking if the buttons in this column have an empty
Caption
There are only two diagonals so we can either check them always
or we can find out if the button is in this diagonal and check it
only in that case put another three texts on the page to know which
texts should be shown at described situations. Edit their font,
size and colour as you like:
- notice Errors
- nearby text3
with initial value 0 that will add player's errors

- text4
with the notice BINGO that is hidden at the beginning of the game
and it is shown at the moment when bingo appears
In context menu select Change, Appearance tab and
hide text4
by removing the tick in the item Shown. In the context menu
of the button newGame
complete hiding the text into the event onPush
after previous calls: gameButtons
genExample text4'hideMe
Finish the command checkBingo
of the class Bingo:
to checkBingo
ifElse
Caption=:mySum [setCaption "||][text3'setValue text3'value+1]
; are there 5 empty Captions in the
line?
let "r first myName
let "isBingo "true
repeat 5 [if ask word :r repc [Caption]<>"|| [make "isBingo
"false]]
if :isBingo [text4'showMe stop]
; are there 5 empty Captions in the
column?
let "s last myName
let "isBingo "true
repeat 5 [if ask word repc :s [Caption]<>"|| [make "isBingo
"false]]
if :isBingo [text4'showMe stop]
; is there the button on the main diagonal?
if (first myName)=(last
myName)
[let "isBingo "true
repeat 5 [if ask word repc repc [Caption]<>"||
[make "isBingo "false]]
if :isBingo [text4'showMe stop]]
; is there the button on the second diagonal?
if (first myName)+(last
myName)=6
[let "isBingo "true
repeat 5 [if ask word repc 6-repc [Caption]<>"||
[make "isBingo "false]]
if :isBingo [text4'showMe stop]]
genExample
end
The command is quite long - it is evidently the longest command
typed in our tutorial but it seems to be clear after previous
analysis.
- Complete the project and assign 0 in text3
at the beginning of the game We will count errors only
for one game.
- At pressing the button pass view the result next to
command in text1
for a while.
- If the player commits an error, view the result next to command
in text1.
Simultaneously view the button with the notice understand
instead of the button pass. The player presses the button,
realises the right result, the button pass appears again and a
new example will be generated.
- While viewing the button understand let not work the
pressing of the buttons of the class "Bingo.
use the command ask
allOf "Bingo [setEnabled "false]
. Of course after pressing the button understand
do not forget to return responsing of these buttons.
- If the player press the button pass and the right result
was on the game board, alert him or her by some sound - realize
that you have to go through all buttons and find out if there
is the same value as in the variable mySum.
- If the button's Caption is empty, let it not to response
on another pressing, i.e. this will not count as the player's
error.
- Insert the computer's game into our game the player
and the computer alternate: the example is generated also to the
computer. If the result is on the game board, the program finds
this button automatically and empties its Caption. Then
the example for the player will generate as in the previous variants
of the game. If the computer gets bingo - i.e. if 5 empty boxes
in any line or column or diagonal will appear, the notice BINGO
for COMPUTER will be shown. Edit this notice and view it if
the player gets bingo.
- Count the number of the player's and computer's wins.
|