TweetFollow Us on Twitter

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
‘ ©MacTutor, DEC.1987
‘ 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 1,0,”Add Coins”,(300,80)-(375,100),2
BUTTON 2,0,”Subtract”,(300,110)-(375,130),2
APPLE MENU “About Professor Mac’s Coins ”
MENU 1,0,1,”File”
MENU 1,1,1,”New Amount/N”
MENU 1,2,1,”Quit/Q”
EDIT MENU 2
Amount!=0
GOSUB “Get Coin Resources”
GOSUB “Draw Page”
ON MENU GOSUB “MenuEvent”
ON DIALOG GOSUB “DialogEvent”
ON MOUSE GOSUB “MouseEvent”
MENU ON:DIALOG ON:MOUSE ON
DO
UNTIL TheEnd
MENU OFF:DIALOG OFF:MOUSE OFF
END

“MenuEvent”
Menunumber=MENU(0)
Menuitem=MENU(1)
MENU
SELECT Menunumber
 CASE 255
 GOSUB “AppleMenu”
 GOSUB “Display Amount”
 GOSUB “Draw Page”
 CASE 1
 GOSUB “FileMenu”
 CASE 2
END SELECT
RETURN

“AppleMenu”
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,4)”©MacTutor, 1987"
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”
PRINT @(3,14)”about money.”
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

“FileMenu”
SELECT Menuitem
 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
Add=True
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
 Add=True
 XELSE
 BUTTON 1,1
 Add=False
 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))
 Response%=FN ALERT(1,0)
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))
 Response%=FN ALERT(1,0)
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))
 Response%=FN ALERT(1,0)
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))
 Response%=FN ALERT(1,0)
RETURN

“Get Coin Resources”
 QHndl&=FN GETNAMEDRESOURCE(  CVI(“PICT”),”Quarter”)
 CALL LOADRESOURCE(QHndl&)
 DHndl&=FN GETNAMEDRESOURCE(  CVI(“PICT”),”Dime”)
 CALL LOADRESOURCE(DHndl&)
 NHndl&=FN GETNAMEDRESOURCE(  CVI(“PICT”),”Nickel”)
 CALL LOADRESOURCE(NHndl&)
 PHndl&=FN GETNAMEDRESOURCE(  CVI(“PICT”),”Penny”)
 CALL LOADRESOURCE(PHndl&)
 THndl&=FN GETNAMEDRESOURCE(  CVI(“PICT”),”Tag”)
 CALL LOADRESOURCE(THndl&)
 MHndl&=FN GETNAMEDRESOURCE(  CVI(“PICT”),”Professor Mac”)
 CALL LOADRESOURCE(MHndl&)
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)))
 LONG IF Add=True
 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))
 LONG IF Add=True
 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))
 LONG IF Add=True
 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))
 LONG IF Add=True
 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:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Fresh From the Land Down Under – The Tou...
After a two week hiatus, we are back with another episode of The TouchArcade Show. Eli is fresh off his trip to Australia, which according to him is very similar to America but more upside down. Also kangaroos all over. Other topics this week... | Read more »
TouchArcade Game of the Week: ‘Dungeon T...
I’m a little conflicted on this week’s pick. Pretty much everyone knows the legend of Dungeon Raid, the match-3 RPG hybrid that took the world by storm way back in 2011. Everyone at the time was obsessed with it, but for whatever reason the... | Read more »
SwitchArcade Round-Up: Reviews Featuring...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for July 19th, 2024. In today’s article, we finish up the week with the unusual appearance of a review. I’ve spent my time with Hot Lap Racing, and I’m ready to give my verdict. After... | Read more »
Draknek Interview: Alan Hazelden on Thin...
Ever since I played my first release from Draknek & Friends years ago, I knew I wanted to sit down with Alan Hazelden and chat about the team, puzzle games, and much more. | Read more »
The Latest ‘Marvel Snap’ OTA Update Buff...
I don’t know about all of you, my fellow Marvel Snap (Free) players, but these days when I see a balance update I find myself clenching my… teeth and bracing for the impact to my decks. They’ve been pretty spicy of late, after all. How will the... | Read more »
‘Honkai Star Rail’ Version 2.4 “Finest D...
HoYoverse just announced the Honkai Star Rail (Free) version 2.4 “Finest Duel Under the Pristine Blue" update alongside a surprising collaboration. Honkai Star Rail 2.4 follows the 2.3 “Farewell, Penacony" update. Read about that here. | Read more »
‘Vampire Survivors+’ on Apple Arcade Wil...
Earlier this month, Apple revealed that poncle’s excellent Vampire Survivors+ () would be heading to Apple Arcade as a new App Store Great. I reached out to poncle to check in on the DLC for Vampire Survivors+ because only the first two DLCs were... | Read more »
Homerun Clash 2: Legends Derby opens for...
Since launching in 2018, Homerun Clash has performed admirably for HAEGIN, racking up 12 million players all eager to prove they could be the next baseball champions. Well, the title will soon be up for grabs again, as Homerun Clash 2: Legends... | Read more »
‘Neverness to Everness’ Is a Free To Pla...
Perfect World Games and Hotta Studio (Tower of Fantasy) announced a new free to play open world RPG in the form of Neverness to Everness a few days ago (via Gematsu). Neverness to Everness has an urban setting, and the two reveal trailers for it... | Read more »
Meditative Puzzler ‘Ouros’ Coming to iOS...
Ouros is a mediative puzzle game from developer Michael Kamm that launched on PC just a couple of months back, and today it has been revealed that the title is now heading to iOS and Android devices next month. Which is good news I say because this... | Read more »

Price Scanner via MacPrices.net

Amazon is still selling 16-inch MacBook Pros...
Prime Day in July is over, but Amazon is still selling 16-inch Apple MacBook Pros for $500-$600 off MSRP. Shipping is free. These are the lowest prices available this weekend for new 16″ Apple... Read more
Walmart continues to sell clearance 13-inch M...
Walmart continues to offer clearance, but new, Apple 13″ M1 MacBook Airs (8GB RAM, 256GB SSD) online for $699, $300 off original MSRP, in Space Gray, Silver, and Gold colors. These are new MacBooks... Read more
Apple is offering steep discounts, up to $600...
Apple has standard-configuration 16″ M3 Max MacBook Pros available, Certified Refurbished, starting at $2969 and ranging up to $600 off MSRP. Each model features a new outer case, shipping is free,... Read more
Save up to $480 with these 14-inch M3 Pro/M3...
Apple has 14″ M3 Pro and M3 Max MacBook Pros in stock today and available, Certified Refurbished, starting at $1699 and ranging up to $480 off MSRP. Each model features a new outer case, shipping is... Read more
Amazon has clearance 9th-generation WiFi iPad...
Amazon has Apple’s 9th generation 10.2″ WiFi iPads on sale for $80-$100 off MSRP, starting only $249. Their prices are the lowest available for new iPads anywhere: – 10″ 64GB WiFi iPad (Space Gray or... Read more
Apple is offering a $50 discount on 2nd-gener...
Apple has Certified Refurbished White and Midnight HomePods available for $249, Certified Refurbished. That’s $50 off MSRP and the lowest price currently available for a full-size Apple HomePod today... Read more
The latest MacBook Pro sale at Amazon: 16-inc...
Amazon is offering instant discounts on 16″ M3 Pro and 16″ M3 Max MacBook Pros ranging up to $400 off MSRP as part of their early July 4th sale. Shipping is free. These are the lowest prices... Read more
14-inch M3 Pro MacBook Pros with 36GB of RAM...
B&H Photo has 14″ M3 Pro MacBook Pros with 36GB of RAM and 512GB or 1TB SSDs in stock today and on sale for $200 off Apple’s MSRP, each including free 1-2 day shipping: – 14″ M3 Pro MacBook Pro (... Read more
14-inch M3 MacBook Pros with 16GB of RAM on s...
B&H Photo has 14″ M3 MacBook Pros with 16GB of RAM and 512GB or 1TB SSDs in stock today and on sale for $150-$200 off Apple’s MSRP, each including free 1-2 day shipping: – 14″ M3 MacBook Pro (... Read more
Amazon is offering $170-$200 discounts on new...
Amazon is offering a $170-$200 discount on every configuration and color of Apple’s M3-powered 15″ MacBook Airs. Prices start at $1129 for models with 8GB of RAM and 256GB of storage: – 15″ M3... Read more

Jobs Board

*Apple* Systems Engineer - Chenega Corporati...
…LLC,** a **Chenega Professional Services** ' company, is looking for a ** Apple Systems Engineer** to support the Information Technology Operations and Maintenance Read more
Solutions Engineer - *Apple* - SHI (United...
**Job Summary** An Apple Solution Engineer's primary role is tosupport SHI customers in their efforts to select, deploy, and manage Apple operating systems and Read more
*Apple* / Mac Administrator - JAMF Pro - Ame...
Amentum is seeking an ** Apple / Mac Administrator - JAMF Pro** to provide support with the Apple Ecosystem to include hardware and software to join our team and Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.