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:

Apple Pro Video Formats 2.0.1 - Updates...
Apple Pro Video Formats brings updates to Apple's professional-level codes for Final Cut Pro X, Motion 5, and Compressor 4. Version 2.0.1: Support for the following professional video codecs Apple... Read more
Maya 2015 - Professional 3D modeling and...
Maya is an award-winning software and powerful, integrated 3D modeling, animation, visual effects, and rendering solution. Because Maya is based on an open architecture, all your work can be scripted... Read more
EtreCheck 2.2 - For troubleshooting your...
EtreCheck is a simple little app to display 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... Read more
OmniOutliner Pro 4.2 - Pro version of th...
OmniOutliner Pro is a flexible program for creating, collecting, and organizing information. Give your creativity a kick start by using an application that's actually designed to help you think. It's... Read more
VLC Media Player 2.2.1 - Popular multime...
VLC Media Player is a highly portable multimedia player for various audio and video formats (MPEG-1, MPEG-2, MPEG-4, DivX, MP3, OGG, ...) as well as DVDs, VCDs, and various streaming protocols. It... Read more
Nisus Writer Pro 2.1.1 - Multilingual wo...
Nisus Writer Pro is a powerful multilingual word processor, similar to its entry level products, but brings new features such as table of contents, indexing, bookmarks, widow and orphan control,... Read more
Tinderbox 6.2.0 - Store and organize you...
Tinderbox is a personal content management assistant. It stores your notes, ideas, and plans. It can help you organize and understand them. And Tinderbox helps you share ideas through Web journals... Read more
OmniOutliner 4.2 - Organize your ideas,...
OmniOutliner is a flexible program for creating, collecting, and organizing information. Give your creativity a kick start by using an application that's actually designed to help you think. It's... Read more
calibre 2.25.0 - Complete e-library mana...
Things 2.5.4 - Elegant personal task man...
Things is a task management solution that helps to organize your tasks in an elegant and intuitive way. Things combines powerful features with simplicity through the use of tags and its intelligent... Read more

Latest Forum Discussions

Lifeline... (Games)
Lifeline... 1.1 Device: iOS Universal Category: Games Price: \$2.99, Version: 1.1 (iTunes) Description: Lifeline is a playable, branching story of survival against all odds. Using your iPhone, iPad, or Apple Watch, you will help... | Read more »
Pandemic: The Board Game Has Gone Univer...
Don't let the virus win! Now you can download Pandemic: The Board Game, by F2Z Digital Media, for all of your iOS devices. The app is based on the fantastic board game by Z-man games. As employees of the CDC, you and your friends will have to work... | Read more »
Fans of Bloomberg Business will soon be able to get all their news on the Apple Watch. The app lets you get the top headlines on your main screen and bookmark stories to read later. Using the motion detection in the Apple Watch, the headlines are... | Read more »
Watch This Homerun is Batting for the Ap...
Eyes Wide Games' Watch This Homerun is purportedly the first sports game coming to the Apple Watch, where you'll be up to bat as the pitcher tries to out-manuever you with fastballs, curveballs, and changeups. Using one-touch controls you can try to... | Read more »
Field Trip Can Take You on a Guided Tour...
Field Trip, by Google’s Niantic Labs, is an exploration app that gives you details about the awesome places you can discover wherever you find yourself. The app can show you local history, delicious restraunts, the best places to shop, and places to... | Read more »
Watch Your Six - SPY_WATCH is Infiltrati...
SPY_WATCH, by Bossa Studios, is a new game designed for the Apple Watch. Runmor has it your spy agency has fallen out of favor. To save it, you'll need to train-up a spy and send them on missions to earn you a stunningly suspicious reputation and... | Read more »
Both Halo: Spartan Assault and Halo: Spa...
Halo: Spartan Assault and Halo: Spartan Strike, by Microsoft, have officially landed on the App Store. Spartan Assault pits you against the Covenant with missions geared to tell the story of the origin of Spartan Ops. In Spartan Strike you'll delve... | Read more »
The Apple Watch Could Revolutionize the...
It’s not here yet but there’s that developing sneaky feeling that the Apple Watch, despite its price tag and low battery life, might yet change quite a lot about how we conduct our lives. While I don’t think it’s going to be an overnight... | Read more »
Mad Skills Motocross 2 Version 2.0 is He...
Mad Skills Motocross 2 fans got some good news this week as Turborilla has given the game its biggest update yet. Now you'll have access to Versus mode where you can compete against your friends in timed challenges. Turborilla has implemented a... | Read more »
Kids Can Practice Healthy Living With Gr...
Bobaka is releasing a new interactive book called Green Riding Hood  in May. The app teaches kids about yoga and organic style of life through mini-games and a fun take on the classic Little Red Riding Hood fairy tale. | Read more »

Price Scanner via MacPrices.net

Sale! 15-inch Retina MacBook Pros for up to \$...
MacMall has 15″ Retina MacBook Pros on sale for up to \$255 off MSRP. Shipping is free: - 15″ 2.2GHz Retina MacBook Pro: \$1794.99 save \$205 - 15″ 2.5GHz Retina MacBook Pro: \$2244.99 save \$255 Adorama... Read more
New 2015 MacBook Airs on sale for up to \$75 o...
Save up to \$75 on the purchase of a new 2015 13″ or 11″ 1.6GHz MacBook Air at the following resellers. Shipping is free with each model: 11" 128GB MSRP \$899 11" 256GB... Read more
Clearance 13-inch Retina MacBook Pros availab...
B&H Photo has leftover 2014 13″ Retina MacBook Pros on sale for up to \$250 off original MSRP. Shipping is free, and B&H charges NY sales tax only: - 13″ 2.6GHz/128GB Retina MacBook Pro: \$1129... Read more
Clearance 2014 MacBook Airs available startin...
B&H Photo has clearance 2014 MacBook Airs available for up to \$200 off original MSRP. Shipping is free, and B&H charges NY sales tax only: - 11″ 128GB MacBook Air: \$729 \$170 off original MSRP... Read more
16GB iPad mini 3 on sale for \$349, save \$50
B&H Photo has the 16GB iPad mini 3 WiFi on sale for \$349 including free shipping plus NY sales tax only. Their price is \$50 off MSRP, and it’s the lowest price available for this model. Read more
Mac minis on sale for up to \$75 off, starting...
MacMall has Mac minis on sale for up to \$75 off MSRP including free shipping. Their prices are the lowest available for these models from any reseller: - 1.4GHz Mac mini: \$459.99 \$40 off - 2.6GHz Mac... Read more
Taichi Temple First Tai Chi Motion Sensor App...
Zhen Wu LLC has announced the official launch of Taichi Temple 1.0, the first motion sensor app for Tai Chi, offering a revolutionary new way to de-compress, relax and exercise all at the same time.... Read more
CleanExit – Erase your Hard Drive Quickly, Se...
CleanExit works on both Macs and PCs, securely and permanently deleting all files from any type of hard drive, flash-based drive or camera media card making the files permanently unrecoverable.... Read more
250 iPhone 6 Tips eBook Released for \$1.99
Bournemouth, UK based iOS Guides has released 250 iPhone 6 Tips, a new eBook available in the iBookstore that reveals a wealth of tips and tutorials for iPhone 6 and iPhone 6 Plus. Priced at \$1.99,... Read more
TigerText Introduces First Secure Enterprise...
TigerText, a provider of secure, real-time messaging for the enterprise, has announced the launch of TigerText for the Apple Watch. TigerText for the Apple Watch enables users to securely send and... Read more

Jobs Board

*Apple* Solutions Consultant - Retail Sales...
**Job Summary** As an Apple Solutions Consultant (ASC) you are the link between our customers and our products. Your role is to drive the Apple business in a retail Read more
*Apple* Solutions Consultant - Retail Sales...
**Job Summary** As an Apple Solutions Consultant (ASC) you are the link between our customers and our products. Your role is to drive the Apple business in a retail Read more
DevOps Software Engineer - *Apple* Pay, iOS...
**Job Summary** Imagine what you could do here. At Apple , great ideas have a way of becoming great products, services, and customer experiences very quickly. Bring Read more
*Apple* Pay - Site Reliability Engineer - Ap...
**Job Summary** Imagine what you could do here. At Apple , great ideas have a way of becoming great products, services, and customer experiences very quickly. Bring Read more
Sr. Technical Services Consultant, *Apple*...
**Job Summary** Apple Professional Services (APS) has an opening for a senior technical position that contributes to Apple 's efforts for strategic and transactional Read more