image ResEx Logo
ResExcellence www : Powered by Google
Cell Phone Themes Icons Mighty Mouse Cursors Software Reviews Widgets & Widgets

Articles
   3D
   Audio
   Custom Controls
   General RB
   Graphics
   Hacks
   Mac OS X
   Menus
   Novelty
   Printing
   REALbasic 2005
   REALbasic 2006
   Registration
   Resources
   Reviews
   Serial
   Speech
   Sockets
   XML
   Video
Resource Links
News
   Current News
   February 2006
   January 2006
   December 2005
   November 2005
   October 2005
   September 2005
   August 2005
   July 2005
   June 2005
   May 2005
   April 2005
   March 2005









REALbasic for Dummies
by Erick Tejkowski


Learning REALbasic through Applications
by Clayton E., Crooks II


REALbasic for Macintosh
by Michael Swaine


REALbasic Cross-Platform Application Development
by Mark S. Choate





Older files are in Stuffit 5 or greater format. Newer files are ".Zip". Download StuffIt Expander
Tell us about a bad link. Thank You!

Merlin Simulator Part 2 by Erick Tejkowsi
01-17-02

Printer Version




Back in the late 1970's, Parker Brothers introduced a great handheld electronic game machine called Merlin. This week we continue with Part 2 of our Merlin Simulator project and begin adding functionality to the simulator.

Interface

If you'd like to start where we left off last week, download the project. Then, launch REALbasic and open Window1. Drag a NotePlayer control from the toolbar and add it to you Window1 interface. It doesn't matter where you drag it to in the interface, since it will be invisible when the application executes. Feel free to adjust the Instrument property. If you leave it set to its default value (1) it will play back as a piano. The remaining instrument numbers are displayed in the Online Reference for the NotePlayer control (press Cmd-1).

01-17_toolbar.jpg (1278bytes)

Add the Code

Before you get started writing any code, open the Code Editor for Window1 and add the following properties (by selecting Edit-New Property):

Property Declaration
CurrentNote as Integer
GameNumber as Integer
NewGame as Boolean
NoteArray(0) as Integer

Close Window1 for now. We will return to it in a second. But, first we need to make some alterations to our custom Canvas classes. Open the NumButtonClass and create two new events, by selecting Edit-New Event.

Event name Parameters: Return Type:
MouseDown x as integer, y as integer  
MouseUp    

Navigate to the MouseDown and MouseUp events of the NumButtonClass and change the code for each to look like the following:

01-10_code1.jpg (33k)

Now that you have the hang of this, open up the UtilButtonClass and do the same, creating two new events, MouseDown and MouseUp like before.

Then, navigate to the MouseDown and MouseUp events of the UtilButtonClass and change the code for each to look like the following:

01-10_code2.jpg (56k)

What we have done here is to give our Window1 controls NumButton and UtilButton the chance to override the default functionality of the class. We will use these new events to respond to actions taken during the game, all from the code of Window1.

Before we jump back to coding the games in Window1, create two new methods in the NumButtonClass by selecting Edit-New Method. Name them as follows:

Add these Methods to NumButton
ButtonOn
ButtonOff

Add the appropriate code to each method:

01-10_code3.jpg (14k)

The custom classes are now complete, so return to the Code Editor of Window1. Create two new methods, by selecting Edit-New Method.

Method Name Parameters:
MusicMachinePlayNote merlinnote as integer, lightson as boolean
MusicMachinePlaySong  

The code for the MusicMachinePlaySong method is:

01-10_code4.jpg (22k)

Since the code for the MusicMachinePlayNote method is so lengthy, I present it to you here in a text box.:

As you may have guessed, these two methods play either a note or a song (which we are storing in the NoteArray). The final step for this week is to add some code to the MouseUp events of the NumButton and UtilButton controls. Open the MouseUp for each and add the appropriate code:

These two methods tie in all the other parts we have worked on so far. The utilButton.MouseUp event sits and waits for you to start a new game. When you do, it sets a flag (newgame = TRUE). Since newgame = TRUE, the number keys respond to a new game inquiry. By pressing the "2" key, a new game called "Music Machine" begins play.

In this game, you are allowed to enter musical notes by pressing the number keys. As you play them, the notes will sound and be remembered by the Merlin Simulator. When you have completed the song, press "COMP TURN" to play the song back. For orientation purposes, the number button all the way at the top of the machine is "0", while the bottom number button is "10". The actual Merlin machine has numbers molded into the plastic adjacent to each button. Our interface is more simplistic. If you have any problems, be sure to review the Merlin manual.

Conclusion

Well, that's it for this week. Select Debug-Run to test your work. If you encounter any difficulties with the code or don't feel like entering it all, you can download the completed project and applications. See you next week!




Cell Phone Themes Icons Mighty Mouse Cursors Software Reviews Widgets & Widgets

Maintained by the Staff of ResExcellence. This entire site ©1997-2006 ResExcellence
Privacy Statement? Sure we gotta Privacy Statement. [an error occurred while processing this directive]