Tuesday 6 October 2009

Chessboard Tutorial

Some of you may have noticed the time of this post ( 10 hours before your class for some of you) but regardless....I cast aside my beer and my personal life and hacked up a very quick tutorial for you. Before I go any further I should say a big thank you to Scott Macaulay who not only gave me the idea for this tutorial but also part of the code!

There are three files to this tutorial. You can find them here but please read below before downloading.

The MIDlet is the ChessBoardMidlet.java file. When creating a new project make sure that you create a new Midlet before copying and pasting the code into it. The other 2 files are POJO's (Plain Old Java Objects) and should be created just as Java Class files.

The result should be a chessboard that has a green box that reacts to user input using the down button only. To carry on with this tutorial you should add code for the UP, LEFT and RIGHT key.

There is no real objective to the tutorial. The program starts off with a form asking for a username and an age (which does not need to be filled in) there are two or three buttons depending on which emulator you are using and all you need to do is click on the "Start Game" button to load the chess set. If you see any button that say qwerty please do not click on it as it is well outside the scope of your module. I hope it might give some of you a starter for your coursework or, at least, a better understanding of J2ME programming. There are plenty of comments but please feel free to ask for more info on anything. Please note that this is NOT a substitute for Geoff Lund's Tutorials and this should be considered as an additional but important extra.

For those that are interested in this tutorial, think about the following

1) Make the green cursor move down one square at a time, not 3/4 of a square.
2) Add methods for MoveRight(), MoveLeft(), MoveUp() to get the green "selection" square moving around the whole chessboard.
3) Think about different ways (perhaps even write them down) that you could visualise different chess pieces...text, sprites etc.

Cheers

Chris