GameProgramming 20060901
GameProgramming 20060901
Mobile Game
Programming on the
A1200 Handset
TECHNICAL ARTICLE
A Simple Demo of Mobile Game Programming on the A1200 Handset
By
MOTODEV Staff
obile phone gaming has become one of the most important parts of the mobile market. In this
M document, we will introduce basic concepts of mobile game development using simple demo code
for the A1200 Ming handset.
Before beginning development of a mobile game, a developer should understand the market.
Specifically:
• Multi-player games
• Content-based games
• Video games with good high graphic quality
Although there are many different types, many of the most successful mobile games share the following
basic characteristics:
1. Easy to Learn/Easy to Play: Most customers aren’t interested in spending hours learning to play a
mobile game. Successful games are designed for the general consumer, not expert gamers.
2. Can be interrupted: Multitasking is at the heart of the mobile phone experience. Users often play
games in the short time between tasks (such as waiting for an email), and interruptions to answer
incoming calls or messages may be frequent. So a good mobile game will provide short-term
entertainment and allow the user to easily switch modes between the game and work.
3. Subscription-Based: The profit margin of a successful mobile game with high usage times may be
enhanced by a subscription-based model.
4. Interactive: No matter how well a game is designed, once the central puzzle is solved or all the levels
are completed, the novelty can wear off. A highly interactive game will hold a user’s interest longer than
a less interactive one.
5. Takes advantage of mobility: Cutting-edge games can utilize a device’s GPS, SMS, or MMS
capabilities to become true mobile experiences.
6. Suitable for a wide audience: A game that is suitable for all ages or interesting for many types of
users will have a larger potential
In this article, we will create a simple number-puzzle game. We will walk through the basics of
designing a game and defining basic functions. We will also discuss ways to improve the game with
background pictures and music.
The complete sample code for this game is available for download from the MOTODEV Web site at
http://developer.motorola.com/?path=1.873.
Key Mapping
1. Game rules
Here, we are going to implement a number puzzle game. The rules are very simple:
1. Fill in the numbers 1-9 in the grid squares. Each number can be used only once.
2. The sums of the numbers on the lines through the center square (horizontally and vertically)
should be the same.
3. The sum of the four numbers at the corners should be equal to the sum of the four numbers in the
center of each side.
People like games with simple rules so that they can start easily. The best games are simple and also fun.
Our number puzzle is not very much fun, but that’s okay; it’s just a demo.
2. Basic Functions
Most games will have several options, but don’t add so many options that your game becomes difficult
to play. And don’t forget to offer your users a help function: it is easy to implement and useful, and it
can make your game more friendly.
Options Panel:
Start playing
New game
Level Selection
Music On/Off
About (Help Info)
--------------------------------------
Options: Option Panel
--------------------------------------
package com.carol.gridGame;
import javax.microedition.lcdui.*;
boolean easy;
boolean normal;
boolean hard;
boolean expert;
Command ok;
Command cancel;
Display dpy;
Displayable prev;
ChoiceGroup cg;
boolean[] scratch;
dpy = dpy_;
prev = prev_;
easy = false;
normal = true;
hard = false;
expert = false;
loadUI();
addCommand(ok);
addCommand(cancel);
setCommandListener(this);
}
void loadUI() {
cg.setSelectedIndex(0, easy);
cg.setSelectedIndex(1, normal);
cg.setSelectedIndex(2, hard);
cg.setSelectedIndex(3, expert);
}
void readUI() {
easy = cg.isSelected(0);
normal = cg.isSelected(1);
hard = cg.isSelected(2);
expert = cg.isSelected(3);
}
}
---------------------------------------------------------
About: About box giving the rules
---------------------------------------------------------
/**
* Show the play method
* @author Carol Wu
* @since 2005.09.20
* @version 1.0
*/
package com.carol.gridGame;
import javax.microedition.lcdui.*;
/**
* Typical about box giving the rules
*/
/**
* Do not allow anyone to create this class
*/
private About() {};
/**
* Put up the About box and when the user click ok return
* to the previous screen.
* @param display The <code>Display</code> to return to when the
* about screen is dismissed.
*/
public static void showAbout(Display display,String strLanguage) {
Alert alert;
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert);
}
}
Figure 3 Options Panel
3. Design Pattern
You can use the Image class to draw a background for you game as below.
try{
bgImage = Image.createImage("/Background.png");
}catch(Exception e){
test("file doesn’t exist");
}
g.drawImage(bgImage,0,0,Graphics.TOP | Graphics.LEFT);
There are several ways to play sound with MIDP 2.0 Media API:
1. Use the Manager class to get a player for a selected media type;
2. Use the Player API to play media on the specific player;
3. Use the Control interface to control the playback of the media.
---------------------------------------------------------
MyResourceBundle: for Language Selection
---------------------------------------------------------
package com.carol.gridGame;
// constructor
public MyResourceBundle(String strLanguage_){
strLanguage=strLanguage_;
if (strLanguage=="CN"){
objs = new Res_zh_CN().getContents();
}
else if (strLanguage=="US"){
objs = new Res_en_US().getContents();
}
}
}
--------------------------------------
Res_en_US: English
--------------------------------------
package com.carol.gridGame;
--------------------------------------
Res_zh_CN: Chinese
--------------------------------------
package com.carol.gridGame;
5. Running Effect
The images below show the completed application running on an A1200 Ming handset: