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:

SketchUp 19.1.174 - Create 3D design con...
SketchUp is an easy-to-learn 3D modeling program that enables you to explore the world in 3D. With just a few simple tools, you can create 3D models of houses, sheds, decks, home additions,... Read more
ClamXav 3.0.12 - Virus checker based on...
ClamXav is a popular virus checker for OS X. Time to take control ClamXAV keeps threats at bay and puts you firmly in charge of your Mac’s security. Scan a specific file or your entire hard drive.... Read more
BetterTouchTool 3.151 - Customize multi-...
BetterTouchTool adds many new, fully customizable gestures to the Magic Mouse, Multi-Touch MacBook trackpad, and Magic Trackpad. These gestures are customizable: Magic Mouse: Pinch in / out (zoom)... Read more
FontExplorer X Pro 6.0.9 - Font manageme...
FontExplorer X Pro is optimized for professional use; it's the solution that gives you the power you need to manage all your fonts. Now you can more easily manage, activate and organize your... Read more
Dropbox 77.4.131 - Cloud backup and sync...
Dropbox is an application that creates a special Finder folder that automatically syncs online and between your computers. It allows you to both backup files and keeps them up-to-date between systems... Read more
DiskCatalogMaker 7.5.3 - Catalog your di...
DiskCatalogMaker is a simple disk management tool which catalogs disks. Simple, light-weight, and fast Finder-like intuitive look and feel Super-fast search algorithm Can compress catalog data for... Read more
Notion 1.0.7 - A unified workspace for m...
Notion is the unified workspace for modern teams. Notion Features: Integration with Slack Documents Wikis Tasks Note: This application contains in-app and/or external module purchases. Version 1.0... Read more
Microsoft Office 2016 16.16.12 - Popular...
Microsoft Office 2016 - Unmistakably Office, designed for Mac. The new versions of Word, Excel, PowerPoint, Outlook, and OneNote provide the best of both worlds for Mac users - the familiar Office... Read more
Little Snitch gives you control over your private outgoing data. Track background activity As soon as your computer connects to the Internet, applications often have permission to send any... Read more
MainStage 3 3.4.3 - Live performance too...
Apple MainStage makes it easy to bring to the stage all the same instruments and effects that you love in your recording. Everything from the Sound Library and Smart Controls you're familiar with... Read more

## Latest Forum Discussions

Upcoming visual novel Arranged shines a...
If you’re in the market for a new type of visual novel designed to inform and make you think deeply about its subject matter, then Arranged by Kabuk Games could be exactly what you’re looking for. It’s a wholly unique take on marital traditions in... | Read more »
TEPPEN guide - The three best decks in T...
TEPPEN’s unique take on the collectible card game genre is exciting. It’s just over a week old, but that isn’t stopping lots of folks from speculating about the long-term viability of the game, as well as changes and additions that will happen over... | Read more »
Intergalactic puzzler Silly Memory serve...
Recently released matching puzzler Silly Memory is helping its fans with their intergalactic journeys this month with some very special offers on in-app purchases. In case you missed it, Silly Memory is the debut title of French based indie... | Read more »
TEPPEN guide - Tips and tricks for new p...
TEPPEN is a wild game that nobody asked for, but I’m sure glad it exists. Who would’ve thought that a CCG featuring Capcom characters could be so cool and weird? In case you’re not completely sure what TEPPEN is, make sure to check out our review... | Read more »
Dr. Mario World guide - Other games that...
We now live in a post-Dr. Mario World world, and I gotta say, things don’t feel too different. Nintendo continues to squirt out bad games on phones, causing all but the most stalwart fans of mobile games to question why they even bother... | Read more »
Strategy RPG Brown Dust introduces its b...
Epic turn-based RPG Brown Dust is set to turn 500 days old next week, and to celebrate, Neowiz has just unveiled its biggest and most exciting update yet, offering a host of new rewards, increased gacha rates, and a brand new feature that will... | Read more »
Dr. Mario World is yet another disappoin...
As soon as I booted up Dr. Mario World, I knew I wasn’t going to have fun with it. Nintendo’s record on phones thus far has been pretty spotty, with things trending downward as of late. [Read more] | Read more »
Retro Space Shooter P.3 is now available...
Shoot-em-ups tend to be a dime a dozen on the App Store, but every so often you come across one gem that aims to shake up the genre in a unique way. Developer Devjgame’s P.3 is the latest game seeking to do so this, working as a love letter to the... | Read more »
Void Tyrant guide - Guildins guide
I’ve still been putting a lot of time into Void Tyrant since it officially released last week, and it’s surprising how much stuff there is to uncover in such a simple-looking game. Just toray, I finished spending my Guildins on all available... | Read more »
Tactical RPG Brown Dust celebrates the s...
Neowiz is set to celebrate the summer by launching a 2-month long festival in its smash-hit RPG Brown Dust. The event kicks off today, and it’s divided into 4 parts, each of which will last two weeks. Brown Dust is all about collecting, upgrading,... | Read more »

## Price Scanner via MacPrices.net

Clearance 12″ 1.2GHz MacBook on sale for \$899...
Focus Camera has clearance 12″ 1.2GHz Space Gray MacBooks available for \$899.99 shipped. That’s \$400 off Apple’s original MSRP. Focus charges sales tax for NY & NJ residents only. Read more
Get a new 2019 13″ 2.4GHz 4-Core MacBook Pro...
B&H Photo has new 2019 13″ 2.4GHz MacBook Pros on sale for up to \$150 off Apple’s MSRP. Overnight shipping is free to many addresses in the US: – 2019 13″ 2.4GHz/256GB 6-Core MacBook Pro Silver... Read more
AirPods with Wireless Charging Case now on sa...
Amazon has extended their Prime Day savings on Apple AirPods by offering AirPods with the Wireless Charging case for \$169.99. That’s \$30 off Apple’s MSRP, and it’s the cheapest price available for... Read more
New 2019 15″ MacBook Pros on sale for \$200 of...
B&H Photo has the new 2019 15″ 6-Core and 8-Core MacBook Pros on sale for \$200 off Apple’s MSRP. Overnight shipping is free to many addresses in the US: – 2019 15″ 2.6GHz 6-Core MacBook Pro Space... Read more
Amazon drops prices, now offers clearance 13″...
Amazon has new dropped prices on clearance 13″ 2.3GHz Dual-Core non-Touch Bar MacBook Pros by \$200 off Apple’s original MSRP, with prices now available starting at \$1099. Shipping is free. Be sure to... Read more
2018 15″ MacBook Pros now on sale for \$500 of...
Amazon has dropped prices on select clearance 2018 15″ 6-Core MacBook Pros to \$500 off Apple’s original MSRP. Prices now start at \$1899 shipped: – 2018 15″ 2.2GHz Touch Bar MacBook Pro Silver: \$1899.... Read more
Price drop! Clearance 12″ 1.2GHz Silver MacBo...
Amazon has dropped their price on the recently-discontinued 12″ 1.2GHz Silver MacBook to \$849.99 shipped. That’s \$450 off Apple’s original MSRP for this model, and it’s the cheapest price available... Read more
Apple’s 21″ 3.0GHz 4K iMac drops to only \$936...
Abt Electronics has dropped their price on clearance, previous-generation 21″ 3.0GHz 4K iMacs to only \$936 shipped. That’s \$363 off Apple’s original MSRP, and it’s the cheapest price we’ve seen so... Read more
Amazon’s Prime Day savings on Apple 11″ iPad...
Amazon has new 2018 Apple 11″ iPad Pros in stock today and on sale for up to \$250 off Apple’s MSRP as part of their Prime Day sale (but Prime membership is NOT required for these savings). These are... Read more
Prime Day Apple iPhone deal: \$100 off all iPh...
Boost Mobile is offering Apple’s new 2018 iPhone Xr, iPhone Xs, and Xs Max for \$100 off MSRP. Their discount reduces the cost of an Xs to \$899 for the 64GB models and \$999 for the 64GB Xs Max. Price... Read more

## Jobs Board

*Apple* IOS Systems Engineer - Randstad (Uni...
Apple IOS Systems Engineer **job details:** + location:Irvine, CA + salary:\$45 - \$55 per hour + date posted:Tuesday, July 16, 2019 + job type:Temp to Perm + Read more