Writing Cool Games for Cellular Devices
Added 31 Jul 2008
One of the main usages of J2ME is game programming. In this article, I'll explain this by way of a standalone game that I developed. This application is a simple basketball game, in which the player plays against a computer opponent. Each game lasts exactly two minutes. The aim of the game is to shoot as many baskets as you can and to prevent the computer opponent from doing the same.
Main Functions
A typical game in J2ME environment might consist of the following:
- A welcome screen that redirects automatically to the main menu.
- The main menu.
- The main screen. This is where the game is actually played.
- Level menu (set the game difficulty, etc.).
- Instruction screen.
- About screen.
The main screen and the welcome screen are executed by classes
that are extends from the
Canvas. This class is defined as being in the
low-level API, meaning that it allows full control of the
display at the pixel level. All the other screens are executed by
high-level API classes that use J2ME standard controls.
When we program apps for J2ME, we must also consider how to handle unique system events such as call interrupts. When we deal with this event, we might want to freeze the current game state or even be able to save this game state after we exit the application.
In order to get started, we'll have to download the J2ME wireless toolkit. This is the most elementary SDK for this environment. The main objective of this toolkit is to compile the Java source files and to produce two deployment files: a JAR file that encapsulate all of the class files and a JAD (Java Application Descriptor) file. The JAD file provides data about the application such as vendor, JAR size, version number, etc. This SDK can be integrated with more advanced IDEs such as Eclipse or NetBeans. You can learn more about getting started with the wireless toolkit in the article " Wireless Development Tutorial Part I."