Teaching
 Volume Number: 3 Issue Number: 12 Column Tag: Basic School

# Games for Teaching Children

By Dave Kelly, MacTutor Editorial Board

Happy 3rd Birthday MacTutor!!! I can hardly believe that MacTutor has been around for a whole 3 years. The Macintosh has certainly come a long way in that time. All the way from a puny 128K RAM model to the gobs of memory available for the Macintosh II. Let’s celebrate!

Every celebration should not be complete with out friends. First I thank all of you readers that have supported MacTutor these past years. But all of this would not be possible if not for the vision of one special, although fictitious character, Professor Mac. For those of you that have not met the Professor, turn to your front cover and take a look just in front of the big ‘M’ in MacTutor. The Professor started out teaching you Apple II Pascal in the “Apple Shoppe” (also published by David Smith). Since that time we’ve seen him popping in and out of the covers of MacTutor. (see Best of MacTutor Vol 1, pg. 1, 8, 13, 61, 71, 92, 107, 313; Best of MacTutor Vol 2, pg. 2, 20, 42, 357, 371-375; not to mention the numerous times the Professor appears at the end of each and every MacTutor column.

A few days ago, the Professor reminded me that I haven’t written any games lately. So what should the game do? Well, my oldest son, who was 3 (now age 6) when we started up MacTutor, is now in first grade. Thanks to vol. 1 no. 1, Kevin now knows his ABC’s. (see Best of MacTutor Vol 1, pg. 298). I guess besides learning to read the next thing that first graders learn to do is count. So a counting game!!!

Last week Kevin brought home some homework that was just type of game I was looking for. The problems showed a price tag with a price. To solve the problem, he had to cut and paste pictures of coins under the price tag to equal the amount on the tag. So Professor Mac’s coin game was born. The object of the game is to click on the fewest possible number of coins to equal the amount of money shown in the price tag. If too many coins are selected the answer is not wrong, but the program lets you know that you could have done it with fewer coins. If you know that you have too many coins you may subtract coins by clicking the radio button named subtract and clicking on the coin you want to remove. The game does require some ability to read. Children that don’t know their numbers will have problems with this. At least it passed my kid test Kevin loved it.

Fig. 1 Our coin game display

On the technical side: the program doesn’t have any real surprizes technically. However, there are a few annoyances that appear to be ZBasic’s fault. In fact, sometimes I wish I was writing in Pascal or C. The blow by blow description follows:

There are four PICT resources, a quarter, a dime, a nickel, and a penny, which are used. These resources should be installed in the application itself in order to work. Creation of the coins was done via Thunderscan® by clipping the scanned pictures into a resource file using ResEdit. The “Get Coin Resources” subroutine gets the handles to the resources by using the ROM function GETNAMEDRESOURCE. Each resource is then loaded into memory (from the disk). Each coin is displayed on right side of the screen to give you something to click on to select the coins in the game. The ZBasic PICTURE statement will display the PICT resources by using the handle for the resource which was retrieved with GETNAMED RESOURCE. The active area to select each coin is marked by the Qrect, Drect, Nrect and Prect rectangles. Here is where the first problem shows up. The SETRECT call is used to set up the coordinates of each rectangle. But the SETRECT parameters are mixed up. Inside Macintosh shows SetRect parameters as being left, top, right, bottom in that order (see IM page I-174), but the ZBasic manual says the ZBasic parameters for SETRECT are Top, Left, Bottom, Right. The call (fortunately) works like IM; there is a typo in the ZBasic manual, pg. E-169.

The event loop is established using menu, dialog and mouse events in the same way that has been demonstrated in other programs. There are a few funnies that show up though. In earlier versions of the program, when I was still working on it, I used MOUSE ON, MOUSE OFF to control the About menu dialog. The problem was that when the About dialog was closed the screen erased itself just after the refresh routine did its refresh. This left a blank where the dialog window was. The screen had been updated, but something in ZBasic was trying to do its own refresh (I guess?). When I turned off all the event trapping for the About routine, the screen refreshed properly. This appears to be one of those little obscure bugs in ZBasic that nobody has fixed yet. This one problem turned what should have been a few minutes of programming into several hours trying to figure out what was going on. The GETMOUSE routine turned out to be just the solution. I get the feeling that I should be writing all my code using the toolbox calls and leave the ZBasic routines to the cockroaches (or other ‘bugs’).

```‘Professor Mac’s Coin Game
‘By Dave Kelly
‘ For ZBasic™ version 4.0

WINDOW OFF
COORDINATE WINDOW
DEF MOUSE=-1
False=0:True=NOT False
DIM Qrect%(3), Drect%(3), Nrect%(3), Prect%(3),    Displayrect%(3)
DIM 63 A\$(4)
Mousy=0:’Set up point record
Mousx=0:’for mouse location
WINDOW 1,””,(2,22)-(510,335),4
CALL SETRECT(Qrect(0),388,0,510,80)
CALL SETRECT(Drect(0),388,81,510,140)
CALL SETRECT(Nrect(0),388,141,510,215)
CALL SETRECT(Prect(0),388,216,510,310)
CALL SETRECT(Displayrect(0),0,140,385,250)
BUTTON 2,0,”Subtract”,(300,110)-(375,130),2
Amount!=0
GOSUB “Get Coin Resources”
GOSUB “Draw Page”
ON DIALOG GOSUB “DialogEvent”
ON MOUSE GOSUB “MouseEvent”
DO
UNTIL TheEnd
END

CASE 255
GOSUB “Display Amount”
GOSUB “Draw Page”
CASE 1
CASE 2
END SELECT
RETURN

WINDOW 2,””,(100,40)-(415,310),-2
TEXT 0,12
PRINT @(5,1)”Professor Mac’s Coin Game”
PRINT @(10,2)”by”
PRINT @(8,3)”Dave Kelly”
PRINT @(7,5)”ZBasic version 4.0"
PRINT @(3,8)”Professor Mac’s MacTutor Store will”
PRINT @(3,9)”display prices on the price tag.”
PRINT @(3,10)”The object is to select (by clicking)”
PRINT @(3,11)”the fewest number of coins to equal”
PRINT @(3,12)”the price. Hopefully this may be of”
PRINT @(3,13)”assistance to children first learning”
DO
CALL GETMOUSE(Mousy)
outsiderect=(Mousx<0 OR Mousx>300 OR Mousy<0 OR Mousy>270)
UNTIL FN BUTTON AND NOT (outsiderect)
WINDOW CLOSE 2
RETURN

CASE 1
GOSUB “New”
CASE 2
GOSUB “Quit”
END SELECT
RETURN

“Quit”
‘Release all resource handles
CALL RELEASERESOURCE(QHndl&)
CALL RELEASERESOURCE(DHndl&)
CALL RELEASERESOURCE(NHndl&)
CALL RELEASERESOURCE(PHndl&)
CALL RELEASERESOURCE(THndl&)
CALL RELEASERESOURCE(MHndl&)
END

“New”
RANDOMIZE TIMER
Amount!=RND(100)*.01
NumOfQ%=0
NumOfD%=0
NumOfN%=0
NumOfP%=0
Total!=0
GOSUB “Display Amount”
GOSUB “Display Total”
GOSUB “Draw Display”
BUTTON 1,2
BUTTON 2,1
RETURN

“DialogEvent”
Dilg=DIALOG(0)
SELECT Dilg
CASE 5
RefWin=DIALOG(5)
‘Get window to refresh
WINDOW 1
GOSUB “Display Amount”
GOSUB “Draw Page”
CASE 1
Buttonpressed=DIALOG(1)
BUTTON Buttonpressed,2
LONG IF Buttonpressed=1
BUTTON 2,1
XELSE
BUTTON 1,1
END IF
END SELECT
RETURN

“Display Amount”
TEXT 3,24,1,0
PICTURE (60,50),THndl&
CALL MOVETO (130,100)
PRINT USING “\$#.##”;Amount!;SPC(2)
RETURN

“Display Total”
TEXT 2,12,1,0
CALL MOVETO(5,285)
PRINT NumOfQ;” Quarters, “; NumOfD;” Dimes, “;    NumOfN; “ Nickels,
“; NumOfP;” Pennies”
CALL MOVETO(5,300)
PRINT “Total:”;USING “\$#.##”;Total!
‘Check for winner
IF Total!=Amount! AND Total!<>0 THEN GOSUB “WinDialog”

RETURN

“WinDialog”
Temp!=Amount!
CorrectNumOfQ%=Temp!/.25
Temp!=Temp!-CorrectNumOfQ%*.25
CorrectNumOfD%=Temp!/.1
Temp!=Temp!-CorrectNumOfD%*.1
CorrectNumOfN%=Temp!/.05
Temp!=Temp!-CorrectNumOfN%*.05
CorrectNumOfP%=Temp!*100
LONG IF NumOfQ%=CorrectNumOfQ% AND NumOfD%=        CorrectNumOfD% AND
NumOfN%=  CorrectNumOfN% AND NumOfP%= CorrectNumOfP%
A\$(1)=”TA-DA!  You Did it!”
A\$(2)=”Select ‘New Amount’ to start again”
A\$(3)=””
A\$(4)=””
CALL PARAMTEXT(A\$(1),A\$(2),A\$(3),A\$(4))
XELSE
A\$(1)=”Nice Try!”
A\$(2)=”You have too many coins!”
A\$(3)=”You should have: “+ STR\$(CorrectNumOfQ%)+ “ Quarters, “ +STR\$(CorrectNumOfD%)+
“ Dimes,”
A\$(4)=STR\$(CorrectNumOfN%)+” Nickels, “+   STR\$(CorrectNumOfP%)+” Pennies”
CALL PARAMTEXT(A\$(1),A\$(2),A\$(3),A\$(4))
END IF
Amount!=0
BUTTON 1,0
BUTTON 2,0
RETURN

“TooMuchDialog”
A\$(1)=”Adding that coin will give you “+ USING  “\$#.##”;Total!
A\$(2)=”Try a different coin!”
A\$(3)=” “
A\$(4)=” “
CALL PARAMTEXT(A\$(1),A\$(2),A\$(3),A\$(4))
RETURN

“No More Coins”
A\$(1)=”Sorry, You don’t have any more “+Coin\$
A\$(2)=” “
A\$(3)=” “
A\$(4)=” “
CALL PARAMTEXT(A\$(1),A\$(2),A\$(3),A\$(4))
RETURN

“Get Coin Resources”
QHndl&=FN GETNAMEDRESOURCE(  CVI(“PICT”),”Quarter”)
DHndl&=FN GETNAMEDRESOURCE(  CVI(“PICT”),”Dime”)
NHndl&=FN GETNAMEDRESOURCE(  CVI(“PICT”),”Nickel”)
PHndl&=FN GETNAMEDRESOURCE(  CVI(“PICT”),”Penny”)
THndl&=FN GETNAMEDRESOURCE(  CVI(“PICT”),”Tag”)
MHndl&=FN GETNAMEDRESOURCE(  CVI(“PICT”),”Professor Mac”)
RETURN

“Draw Page”
PICTURE (400,0),QHndl&
PICTURE (406,78),DHndl&
PICTURE (400,138),NHndl&
PICTURE (406,220),PHndl&
CALL MOVETO(385,0)
CALL PENSIZE(2,2)
CALL LINETO(385,340)
CALL MOVETO(0,135)
CALL LINETO(385,135)
CALL PENNORMAL
PICTURE (0,0),MHndl&
CALL MOVETO(60,40)
TEXT 2,18,0,0
PRINT “Professor Mac’s Coin Game”
“Draw Display”
CALL ERASERECT(Displayrect(0))
IF NumOfQ>0 THEN PICTURE (0,140),QHndl&
IF NumOfD>0 THEN PICTURE (100,140),DHndl&
IF NumOfN>0 THEN PICTURE (200,140),NHndl&
IF NumOfP>0 THEN PICTURE (300,140),PHndl&
RETURN

“MouseEvent”
IF Amount!=0 THEN FLUSHEVENTS:RETURN
CALL GETMOUSE(Mousy)
LONG IF (FN PTINRECT(Mousy,Qrect%(0)))
Total!=Total!+.25
NumOfQ=NumOfQ+1
GOSUB “Draw Display”
XELSE
LONG IF NumOfQ-1<0
Coin\$=”Quarters!”
GOSUB “No More Coins”
XELSE
NumOfQ=NumOfQ-1
Total!=Total!-.25
IF Total!<0 THEN Total!=Total!+.25
GOSUB “Draw Display”
END IF
END IF
LONG IF Total!>Amount!
GOSUB “TooMuchDialog”
Total!=Total!-.25
NumOfQ=NumOfQ-1
END IF
GOSUB “Display Total”
END IF
LONG IF FN PTINRECT(Mousy,Drect(0))
Total!=Total!+.1
NumOfD=NumOfD+1
GOSUB “Draw Display”
XELSE
LONG IF NumOfD-1<0
Coin\$=”Dimes!”
GOSUB “No More Coins”
XELSE
NumOfD=NumOfD-1
Total!=Total!-.1
IF Total!<0 THEN Total!=Total!+.1
GOSUB “Draw Display”
END IF
END IF
LONG IF Total!>Amount!
GOSUB “TooMuchDialog”
Total!=Total!-.1
NumOfD=NumOfD-1
END IF
GOSUB “Display Total”
END IF
LONG IF FN PTINRECT(Mousy,Nrect(0))
Total!=Total!+.05
NumOfN=NumOfN+1
GOSUB “Draw Display”
XELSE
LONG IF NumOfN-1<0
Coin\$=”Nickels!”
GOSUB “No More Coins”
XELSE
NumOfN=NumOfN-1
Total!=Total!-.05
IF Total!<0 THEN Total!=Total!+.05
GOSUB “Draw Display”
END IF
END IF
LONG IF Total!>Amount!
GOSUB “TooMuchDialog”
Total!=Total!-.05
NumOfN=NumOfN-1
END IF
GOSUB “Display Total”
END IF
LONG IF FN PTINRECT(Mousy,Prect(0))
Total!=Total!+.01
NumOfP=NumOfP+1
GOSUB “Draw Display”
XELSE
LONG IF NumOfP-1<0
Coin\$=”Pennies!”
GOSUB “No More Coins”
XELSE
NumOfP=NumOfP-1
Total!=Total!-.01
IF Total!<0 THEN Total!=Total!+.01
GOSUB “Draw Display”
END IF
END IF
LONG IF Total!>Amount!
GOSUB “TooMuchDialog”
Total!=Total!-.01
NumOfP=NumOfP-1
END IF
GOSUB “Display Total”
END IF
DO:UNTIL NOT (FN BUTTON)
FLUSHEVENTS
RETURN
```

Community Search:
MacTech Search:

VOX 3.2.1 - Music player that supports m...
VOX just sounds better! The beauty is in its simplicity, yet behind the minimal exterior lies a powerful music player with a ton of features and support for all audio formats you should ever need.... Read more
Evernote 7.0 - Create searchable notes a...
Evernote allows you to easily capture information in any environment using whatever device or platform you find most convenient, and makes this information accessible and searchable at anytime, from... Read more
Hopper Disassembler 4.3.16- - Binary dis...
Hopper Disassembler is a binary disassembler, decompiler, and debugger for 32- and 64-bit executables. It will let you disassemble any binary you want, and provide you all the information about its... Read more
VOX 3.2.1 - Music player that supports m...
VOX just sounds better! The beauty is in its simplicity, yet behind the minimal exterior lies a powerful music player with a ton of features and support for all audio formats you should ever need.... Read more
Evernote 7.0 - Create searchable notes a...
Evernote allows you to easily capture information in any environment using whatever device or platform you find most convenient, and makes this information accessible and searchable at anytime, from... Read more
Hopper Disassembler 4.3.16- - Binary dis...
Hopper Disassembler is a binary disassembler, decompiler, and debugger for 32- and 64-bit executables. It will let you disassemble any binary you want, and provide you all the information about its... Read more
Default Folder X 5.2.2 - Enhances Open a...
Default Folder X attaches a toolbar to the right side of the Open and Save dialogs in any OS X-native application. The toolbar gives you fast access to various folders and commands. You just click on... Read more
EtreCheck 4.0.1 - For troubleshooting yo...
EtreCheck is an app that displays the important details of your system configuration and allow you to copy that information to the Clipboard. It is meant to be used with Apple Support Communities to... Read more
Carbon Copy Cloner 5.0.9 - Easy-to-use b...
Carbon Copy Cloner backups are better than ordinary backups. Suppose the unthinkable happens while you're under deadline to finish a project: your Mac is unresponsive and all you hear is an ominous,... Read more
QuickBooks 17.2.25.638 R26 - Financial m...
QuickBooks helps you manage your business easily and efficiently. Organize your finances all in one place, track money going in and out of your business, and spot areas where you can save. Built for... Read more

## Latest Forum Discussions

Our top 5 characters from casual RPG Cre...
Creature Quest definitely lives up to its name with a host of collectible creatures based on fantasy tales and world mythologies. To celebrate Creature Quest’s first birthday, we’re going to lay out what we think are the five best characters in the... | Read more »
Around the Empire: What have you missed...
Did you know that Steel Media has a whole swathe of other sites dedicated to all aspects of mobile gaming? Sure you'll get the very best iPhone news, reviews, and opinions right here at 148Apps, but we don't want you missing out on a single piece... | Read more »
All the best games on sale for iPhone an...
Oh hi there, and welcome to our round-up of the best games that are currently on sale for iPhone and iPad. You thought I didn't see you there, did you, skulking behind the bushes? Trust me though, the bushes aren't where the best deals are. The... | Read more »
The Battle of Polytopia Guide - How to H...
A new update just released for The Battle of Polytopia (formerly Super Tribes), which introduces online multiplayer. For all the fans of Midjiwan’s lite take on Civilization, this is certainly welcome news, but playing online isn’t as easy and... | Read more »
Here are the very best mobile games to p...
It's Valentine's Day! Did you get loads of cards and chocolates and other tacky, simple expressions of human affection? Did you send out tat because you find it almost impossible to express emotion unless there's a section dedicated to it at your... | Read more »
Florence (Games)
Florence 1.0 Device: iOS Universal Category: Games Price: \$2.99, Version: 1.0 (iTunes) Description: Florence is an interactive storybook from the award-winning lead designer of Monument Valley about the heart-racing highs and... | Read more »
Purrfect Date (Games)
Purrfect Date 1.0 Device: iOS Universal Category: Games Price: \$4.99, Version: 1.0 (iTunes) Description: Cats are a lil’ like marmite. Either you absolutely head-over-heels love’ em, or… nahhh, who are we kidding?! Everyone... | Read more »
More monsters to collect and evolve in C...
A laid-back mix of RPG and TCG, Creature Quest is all about building your deck, evolving your creatures and winning in battle. It’s the creation of VC Mobile, set up by Might and Magic producer Jon Van Caneghem. There are elements of that classic... | Read more »
Check out this awesome hands-on with the...
Well, PlayerUnknown's Battlegrounds has come out on mobile. This isn't a clone, this isn't a riff on the battleroyale mechanics of the game, it's the official mobile port by Tencent. But there's a little bit of a hitch. [Read more] | Read more »
Hostage Negotiator (Entertainment)
Hostage Negotiator 1.1.0 Device: iOS Universal Category: Entertainment Price: \$3.99, Version: 1.1.0 (iTunes) Description: Official app of the board game by AJ Porfirio and Van Ryder Games. In Hostage Negotiator, you play the part of... | Read more »

## Price Scanner via MacPrices.net

Saturday Sale: Amazon offers 13″ 1.8GHz/256GB...
Amazon has the 13″ 1.8GHz/256B Apple MacBook Air on sale today for \$250 off MSRP including free shipping: – 13″ 1.8GHz/256GB MacBook Air (MQD42LL/A): \$949.99, \$250 off MSRP Their price is the lowest... Read more
Roundup of Apple Certified Refurbished 12″ Ma...
Apple has Certified Refurbished 2017 12″ Retina MacBooks available for \$200-\$240 off the cost of new models. Apple will include a standard one-year warranty with each MacBook, and shipping is free.... Read more
Apple offers Certified Refurbished 10″ and 12...
Apple is now offering Certified Refurbished 2017 10″ and 12″ iPad Pros for \$100-\$190 off MSRP, depending on the model. An Apple one-year warranty is included with each model, and shipping is free: –... Read more
Apple Canada offers Certified Refurbished Mac...
Canadian shoppers can save up to \$560 on the purchase of a 2017 current-generation MacBook Pro, MacBook, or MacBook Air with Certified Refurbished models at Apple Canada. Apple’s refurbished prices... Read more
Sale! 13″ MacBook Airs for up to \$180 off MSR...
B&H Photo has 13″ MacBook Airs on sale for \$50-\$120 off MSRP. Shipping is free, and B&H charges sales tax for NY & NJ residents only: – 13″ 1.8GHz/128GB MacBook Air (MQD32LL/A): \$899, \$... Read more
Sale! New 8-core iMac Pro for \$4799, \$200 off...
Adorama has the 8-core iMac Pro on sale for \$4799 including free shipping plus NY & NJ sales tax only. Their price is \$200 off MSRP, and it’s the currently lowest price available for an iMac Pro. Read more
Sale! Walmart lowers prices even more on 9″ i...
Walmart has lowered their sale price on 9.7″ Apple iPads to \$80 off MSRP for a limited time. Sale prices are for online orders only, in-store prices may vary: – 9″ 32GB iPad: \$249.99 \$80 off – 9″... Read more
Roundup of 13″ MacBook Pro sales, models avai...
B&H Photo has 13″ MacBook Pros on sale for up to \$200 off MSRP. Shipping is free, and B&H charges sales tax for NY & NJ residents only. Their prices are the lowest available for these... Read more
Roundup of 15″ MacBook Pros sale, models up t...
B&H Photo has 15″ MacBook Pros on sale for up to \$200 off MSRP. Shipping is free, and B&H charges sales tax for NY & NJ residents only: – 15″ 2.8GHz Touch Bar MacBook Pro Space Gray (... Read more
How to save up to \$350 on the purchase of a 2...
B&H Photo has iMacs on sale for up to \$150 off MSRP. Shipping is free, and B&H charges sales tax for NY & NJ residents only: – 27″ 3.8GHz iMac (MNED2LL/A): \$2149 \$150 off MSRP – 27″ 3.... Read more

## Jobs Board

*Apple* Retail - Multiple Positions - Apple,...
Job Description: Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
*Apple* Retail - Multiple Positions - Apple,...
Job Description:SalesSpecialist - Retail Customer Service and SalesTransform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
*Apple* Retail - Multiple Positions - Apple,...
Job Description: Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
*Apple* Solutions Consultant - Apple (United...
# Apple Solutions Consultant Job Number: 113501424 Norman, Oklahoma, United States Posted: 15-Feb-2018 Weekly Hours: 40.00 **Job Summary** Are you passionate about Read more
Senior Program Manager - *Apple* Music - Ap...
# Senior Program Manager - Apple Music Job Number: 113393020 Seattle, Washington, United States Posted: 02-Feb-2018 Weekly Hours: 40.00 **Job Summary** Apple is Read more