Category Archives: Programming

Mr. Smith’s Game 2.0

Gee, that was fast wasn’t it? A whole new version complete with a new, huge level in what, minutes? Well, no it didn’t really happen that fast. I’ve had version 2 done for a while but this is its big Internet debut! In fact, some of my students found a few programming errors here and there so I’ve actually had to update it three times to version 2.03.

Without revealing too much, if you still have a save file from version 1.0 just copy that file into the 2.0 folder and you should be good to go. A few things have changed from 1.0 (like the bats have been replaced by owls), but nothing major (the bats are still included in the game…). Anyway, for those of you who don’t remember where you left off here’s a clue: go to the Trapper’s hut in the center of the forest. The next level starts there. Oh, and I’d stock up on some Bread and especially Antidotes while I was there…

Anyway, have fun! I certainly did in making it. This new area that’s now open to you is pretty big. You might want to make a map to help you navigate around. It can be a bit tricky. Oh, and there are a total of three ways “out” besides the exit. You’ll know what I mean.

Version 3 is already in the works. I already have my maps sketched out and plans made for what it will be like. So far, I’m pleased, but you’ll have to wait a while for it as it contains probably 12-15 maps and only one is close to complete. There’s never enough time to do all the things you want!

Enjoy and leave me comments here about your conquests! Be sure to check back periodically for updated versions. Oh, at a minimum to play it you’ll need to install the Runtime Package (RTP) on your computer. You only need to install this once, so if you already have it, you’re good to go!

Mr. Smith’s Game 1.0

In my spare time I have dabbled with the RPG Maker series from EnterBrain. My favorite iteration was RPG Maker XP which I liked so much that I purchased it.

Well, I made a game of sorts several years back. Now, it has basically no story and no true ending, but the first two levels are more or less complete. And I’m proud of it. I had a lot of fun making it and my students have had a lot of fun playing their way through it too. I guess it would take about 45 minutes to work your way through the entire story getting all the items if you don’t escape from very many battles. And you shouldn’t, anyway. The boss in the forest really requires a certain amount of leveling up (and a certain equipped item doesn’t hurt) to beat.

So, without further adieu I present Mr. Smith’s Game 1.0! (I’ve got to come up with a better title later.) Oh, at a minimum to play it you’ll need to install the Runtime Package (RTP) on your computer.

Enjoy and leave me comments here about your conquests! Also, be on the lookout for updated versions in the future.

The Document Object Model (DOM)

This is a simplified view of the Document Object Model (DOM). Each box represents an object in the DOM tree structure. There are additional objects in the DOM that are not listed here. I hope to add them to an expanded image later.

The Document Object Model (DOM)

The Document Object Model (DOM)

HTML Event Handlers

This is a brief listing of HTML Event Handlers which are used to trigger JavaScript code in web pages:

onAbort The loading of an image has been canceled
onBlur A page element loses focus
onChange The user changes the content of a form field
onClick The user uses the mouse to click on a page element
onDblClick The user uses the mouse to double-click on a page element
onError An error occurs when loading a page or an image
onFocus A page element gets focus (selected)
onKeyDown The user presses a keyboard key
onKeyPress The user presses or holds down a keyboard key
onKeyUp The user releases a previously pressed keyboard key
onLoad A page or an image finishes loading
onMouseDown The user presses a mouse button
onMouseMove The mouse cursor moves
onMouseOut The mouse cursor moves off of a page element
onMouseOver The mouse cursor moves over a page element
onMouseUp The user releases a previously pressed mouse button
onReset The form is reset; the reset button is clicked
onResize A window or frame is resized
onSelect The user selects some text on the page
onSubmit The form is submitted; the submit button is clicked or the enter key is pressed
onUnload The user leaves the current page

Note: Event Handlers that are device-non-specific are preferred to those that are device-specific. So, for example, use onFocus and onBlur instead of onMouseUp and onMouseDown since the latter are triggered specifically by using the mouse. Keyboard presses will not trigger such an event. Using onFocus and onBlur will make the event device neutral and will be triggered by both the keyboard and the mouse.

Remember, the above event handlers are actually part of XHTML (since HTML 4) not JavaScript. JavaScript now boasts an extended list of event handlers. See for details.

Principles for Good Programming Code

I have been teaching computer programming for a while now and I have come up with several principles that help students make better coding choices. The goal is for the students to learn how to write efficient code that is also resistant to breakage. Here are my findings:

  • Chekhov’s Gun – A ‘Chekhov’s gun’ is a literary technique made famous by the great playwrite, Anton Chekhov himself. He said “that any object introduced in a story must be used later on, else it ought not to feature in the first place.” It means “do not include any unnecessary elements in a story” or, in our case, in our code. Every line of code, object, and class that is included should be used leaving no loose ends.
  • DRY – DRY stands for Don’t Repeat Yourself and was made popular by the people at The Pragmatic Programmers. In practical terms it means do not include redundant code. Write your code in such a way that there is no duplication of anything. This prevents errors when programs are edited later and not every instance of a needed change was implemented.
  • Occam’s Razor – Occam’s Razor (or KISS – Keep It Simple, Stupid) “is a principle attributed to the 14th-century English logician and Franciscan friar William of Ockham.” The principle states that “the explanation of any phenomenon should make as few assumptions as possible.” It means that, all other things being equal, the simplest solution is usually best. So, attempt to keep your code as simple as possible. Search out the simplest solution since complex code is always inferior to simpler code that accomplishes the same task.
  • The Mayonnaise Jar and Two Cups of Coffee – This simple principle comes from a popular story circulating on the Internet. Although the story speaks about life, it can be applied to programming. Basically, you should implement big features before smaller features. Big features include decision structures and looping structures – complex programming code that exists on multiple lines as opposed to one-liners.

And there are many more, but this list is a decent start. I will likely be adding to this list from time to time so check back in the future. If you just can’t wait, then browse the List of Tips posted with the The Pragmatic Programmer book by Andrew Hunt and David Thomas and read Getting Real by the people at 37signals. Until then, happy coding!