Happy Farm an Online Game for Mobile Phone | SpringerLink

Happy Farm an Online Game for Mobile Phone
Quanyin Zhu, Hong Zhou, Yunyang Yan, and Chuanchun Yu
Faculty of Computer Engineering,
Huaiyin Institute of Technology,
Huaian, Jiangsu Province, China
[email protected]
Abstract. This paper illustrates the game Structure, the file hierarchies, the
whole game classes designed and methods to develop the mobile game Happy
Farm which is widely welcomed in China recently. Game API in the Mobile
Information Device Profile MIDP 2.0 is used to build the game engine; And
components designs and implementation steps of the game are introduced in
detail. Various techniques, such as object pool, multi-threaded, socket
connection, Maps etc., are applied in Happy Farm's development. Experiment
demonstrates its performance and proves that this case is meaningful and useful
to develop other online mobile games. In addition, some propositions for further
research are also suggested.
(
)
Keywords: Happy Farm, mobile phone game, game structure, MIDP.
1 Introduction
Internet on mobile terminals is developing at an astonishing speed, which indicates the
mobile service in China possesses a tremendous market value in the future [1]. Online
mobile games have been progressed very quickly recently, and some researchers
focused on transforming the internet game to the online mobile game [2,3,4]. Mobile
games of graphics class which are suitable for different people of all ages are
widespread now. An Activity Theory (AT) model using modern digital technology, AT
components and example are given [5]. A method for customization of all aspects of
game (contents, graphics, game style, rules, victory conditions) with a wide possibility
is researched [6]. Some interesting and useful ideas are experimented such as rating the
descriptiveness of images in a system as well as some methods to improve position [7],
estimating and detecting various hand gestures and postures of a user with a two-axis
accelerometer [8], and a plausible physically based model for animating and rendering
fire and smoke on a mobile platform [9]. Some applications of mobile phone games for
the future experience are researched. For example, applying the human ability to
control a video game on a mobile device, electroencephalographic (EEG) Mu rhythms
are used which depends on the signals obtained using a specially designed electrode
cap and equipment, and be sent through a Bluetooth connection to a PC which
processes it in a real time [10], using an input data from slide on-off and microphone
interface on the mobile phone which is based on pop-up function of wipi platform and
uses traditional materials [11].
Y. Wu (Ed.): ICCIC 2011, Part IV, CCIS 234, pp. 120–128, 2011.
© Springer-Verlag Berlin Heidelberg 2011
Happy Farm an Online Game for Mobile Phone
121
Online games of mobile phone are welcomed by everyone because it can be played
every time and everywhere. The game Happy Farm which is widely welcomed in China
recently can be played by children and senior citizen. However, it only can be played
on internet. The case study is a main approach which are very useful to develop the
mobile phone games and was reported on some papers [2,3,12,13].
This paper focused on an interested game Happy Farm which is widely played. The
online mobile games’ client architecture, depended on the jQuery framework, and
server architecture, depended on the Struts and Hibernate framework, are introduced.
Communications between the client and the server apply the middleware platform
which is developed on the Socket API.
2 Game Class and Frameworks
A. Class Design
The process of the game development is based on the idea of object-oriented, so that the
function of each module should be as independently as possible. There are a total of 8
classes designed for the game depend on Java game class:
1) GameMIDlet
GameMIDlet Class inherits from javax.microedition.midlet. MIDlet, it should
implements three means at least that are startApp(), pauseApp() and destroyApp().The
MIDlet will be on the start which is transferred from startApp() through Java
Application Manager (JAM), that means the game can be start. The MIDlet will be
paused when JAM implements pauseApp(), and make it to wind up by using the
destroyApp().
GameMIDlet is a kind of entry class for game development. It can build a new object
employed hereafter for each game class. Some new methods commonly used to
facilitate other classes for called. For example, public Image loadImage(String path),
by referring to the method, and others can easily import images.
2) GameMenuCanvas
GameMenuCanvas Class inherits from javax. microedition.lcdui.Canva, and it can
achieve the interface of java.lang.Runnable this is mainly responsible for the handling
of the menu interface and buttons. It affirms that a variable in which GameStatus used
to determine the state of the game, when the game is set up state, the display settings
screen; and when the game is to help state, display help screen.
3) GameRegister
GameRegister Class carry out the interface of javax. microedition.lcdui.
CommandListener and javax.microedition. lcdui.Runnable, they login and registration
for user interface processing by getting user input relevant information to the user's
login or register.
122
Q. Zhu et al.
4) Connection
Connection Class accomplishes the communication between the server and the client.
The server has two for each client connection object to complete the data to send and
receive. Each client will be automatically activated after start-up connection and
establish the conversation with the server.
5) GameRMS
GameRMS Class which encapsulates the method to complete the relevant function will
be implement when each user logs need to be storage and retrieval information in the
user's mobile phone.
6) MainMenu
MainCanvas Class inherits from javax.microedition.lcdui. Canvas. It is responsible for
the main game interface display.
7) ThreadCrop
ThreadCrop Class realize the interface of javax. microedition.lcdui.Runnable. It is
primarily responsible for the growth of vegetables.
8) TransformStr
TransformStr class encapsulates methods to achieve a number of uncertainties related
to the length of characters in vertical display which does this by passing a string and
brush; you can return a string with a vertical transparent image. The relationship
between the whole projects is shown in Figure 1.
GameMIDlet
GameRegister
MainMenu
GameRMS
Connection
GameMenuCanvas
TransformStr
ThreadCrop
Fig. 1. Class Relationship Diagram
B. File Hierarchies
The File Hierarchies of the game show in Figure 2.
a) code for the source code belongs to package which process all the classes in this
package under it.
b) iamge is the picture of resources which is only for .png format. It will be used
throughout the game, including the images stored resources, and named according to
their purpose.
Happy Farm an Online Game for Mobile Phone
123
Fig. 2. File Hierarchies Diagram
C. Game Frameworks
The framework of the game is divided into three kinds of states: Wait for the status,
operation status (running state is divided into multiple sub-states), the end of the state,
they run the game in the whole world. The game structure is based on the state machine
to run the game a variety of different forms of run-time is divided into a one state, at any
time there will be a state to be executed. Taking into account the game state nested
problems, all of the state of each area separated from the main thread in the game
constantly judgments in order to achieve the transition between states. The game
structure is shown in Figure 3.
Fig. 3. Game structure
3 Game Designs
A. Game Startup
The final form of the game is .Jar format. it is reality a zip compressed format. It is the
only difference is that with the zip which a META-INF directory, including a
MANIFEST.MF file for the description of the project, meet the format standards of the
content can be the automatic identification, and running the program can also be used
Midlet.getAppProperty ( "xxxx") method to get the file in the property value.
124
Q. Zhu et al.
The content of document MANIFEST.MF is as follows:
Manifest-Version: 1.0
MIDlet-Vendor: HYIT
MIDlet-Version: 1.0.0
MicroEdition-Configuration: CLDC-1.1
MIDlet-Name: QQ Happy Farm(Mobile version)
MicroEdition-Profile: MIDP-2.0
MIDlet-1: GameMIDlet,/images/icon.png,src.code.GameMIDlet
B. Game Main Menu
1) Logo interface
Logo interface is used to display the game copyright. It is encapsulated in the
GameMenuCanvas class. The Logo screen can be drawn by calling GameMenuCanvas
of drawLogo (Graphics g) method when the game is in Logo state. The rolling screen
background is achieved by calling GameMenu- Canvas the drawRect (Graphics g)
methods which should to start a thread, and constantly changing draw a small square of
the X and Y coordinates to achieve the scrolling effect.
(a) Logo Interface
(b) Main Menu (c) Setting Menu
Fig. 4. Game Logo Interface, Main Menu and Setting Menu
2) Main Menu
GameMIDlet class is the game entrance class which should be set the current display of
GameMenuCanvas class first,
public void startApp() {
display.setCurrent(menuCanvas);
}
showMenu() is used to initialize the menu, loadImage (String) is used for image
loading, setColor (Graphics, int) is used to set the brush color, setColor(Graphics,int),
thread run() is used for the network connection to the network, drawMenu
Back(Graphics) used to draw the menu background, in the drawMenu(Graphics) and
Happy Farm an Online Game for Mobile Phone
125
drawRect(Graphics) call drawMenu Back(Graphics) method to draw the whole menu,
drawSeting (Graphics) drawing settings information, drawHelp(Graphics) drawing
help information, paint(Graphics) by calling drawMenu(Graphics) methods to drawing
the menu which is a logical hub for the entire game etc., thread run() is mainly used to
redraw the screen and changing the background of the coordinates of the sun and the
clouds to achieve dynamic effects, and . keyPressed (int) is the key approach
throughout the game. The game logo interface, main menu and setting menu are show
in figure 4.
3) Implementation Logic of the Main Menu
The game starts from GameMIDlet class. GameMIDlet class as the entrance of the
game class, it should to set the current display category as GameMenuCanvas class at
first. Eight static constants (GAME_MENU, GAME_START, GAME_REGISTER,
GAME_SETING,
GAME_HELP,
GAME_EXIT,
GAME_LOGO,
and
GAME_LOGIN) are defined used to identify in which the state of the menu is in
MenuCanvas class.
In the initial state of the game GameMenuCanvas status Logo, when the players
from the Logo screen press any key to enter the menu interface, through the keyPressed
(int) method call initMenu () method, set the state of the game for the menu state
(GAME_MENU), by detecting the left and right key of the mobile phone to display the
game menu options (for example, start the game, user registration, etc.), MenuIndex
value plus one for right-click, and minus one for left-click. The state of games will be
determined and the relevant picture will be drawn depending on the value of
MenuIndex when the user presses the OK button.
C. Game Implementations
1) The Methods of the Main Menu Class
The game main menu is processed by MainMenu class. The methods are used in the
class, as shown in Figure 5.
Fig. 5. The methods used in the class of Main Menu
MainMenu (Display, GameMIDlet) is a kind of constructor which is used to pass the
entrance classes and brushes come in convenient for later on, and some variables are also
initialized in the constructor. initMainMenu (Graphics) is used to initialize the main
126
Q. Zhu et al.
interface, through which the method call paint (Graphics) method to draw the game main
menu, and drawGameBack (Graphics) method draw the game's background using paint
(Graphics) method. drawShop (Graphics) method is used to painting shop. drawStorage
(Graphics) is used to the painting warehouse. drawAddone (Graphics) for the painting
stores to buy goods +1 dynamic effects. drawMyseed (Grahpics) method is used to
painting whom purchased the seeds. keyPressed (int) method is used to key processing.
2) Running Game
Five static constants (LAND, MESSAGE, MENU, TOOL, and FRIEND) are defined in
the MainMenu class which is used to identify the selected state. When the players enter
the game from the login window of the main interface, the initial state (SelectStatus) is
land (LAND) which can also be selected by press ‘3’ key. Press ‘1’ key for information
widow, press ‘9’ key for menus widow, press ‘7’ key for tools widow, and press ‘0’ key
for friends widow. The land and friends widows are show as Figure 6.
(a) Land
(b) Friends Widow
Fig. 6. Land and Friends Widows
In the menu bar, players can buy in a store seeds and the start is 400 gold coins. Once
purchased, you can buy in the tool bar to select the seed planted in the land. The
vegetables can be a single removal or remove all by the player after mature. Players can
use the tool bar, shovel to eradicate leaves when removal is completed. In the
warehouse will be shown the fruits after removal is completed, you can sell the fruits of
your own. Further more, player's experience and gold has also increased. Warehouse,
planting and harvest are show as Figure 7.
(a) Warehouse
(b) Planting
(c) Harvest
Fig. 7. Warehouse, Planting and Harvest
Happy Farm an Online Game for Mobile Phone
127
D. Conclusions and Future Works
Along with the progress of 3G and 4G technology, the market for mobile phone games
will have a huge prospect. Mobile phone games are welcoming for numerous mobile
ISP. The currently popular game for mobile phone Happy Farm has been attempted in
this article. JAVA-based games can be implemented on all intelligent mobile phones,
and own a better portability. The ubiquitous mobile phone games offer players a great
convenience to enrich their spare time.
This paper describes the farm game’s development platform based on MIDP2.0. The
development of the game Happy Farm for mobile phones has been described; the game
framework, game classes design and methods are given as well. Due to the restrictions
on the mobile processor performance, many technical issues such as the map
algorithms, game performance and network performance need to be optimized and
researched.
References
[1] Li, J., Alexandra, P., Sanxing, C., Yajing, C.: Trends on Interactive Platforms for Social
Media through Web2.0. In: International Conference on MASS 2009, September 20-22, pp.
1–2 (2009)
[2] Zhu, Q., Zhao, L., Cao, S., Shen, J., Zhang, S.: A BnB Mobile Game Online Based on
J2ME and J2EE. In: 7th ACIS International Conference on Software Engineering Research,
Management and Applications, SERA 2009, December 2-4, pp. 19–24 (2009)
[3] Zhu, Q.-Y., Zhang, H., Sun, W.-J.: Research of key technologies of mobile network games
based on J2ME and J2EE. Computer Engineering and Design 29(20), 5218–5221 (2008)
[4] Xu, C.-w.: A Software Framework for Online Mobile Games. In: International Conference
on Computer Science and Software Engineering, CSSE 2008, vol. 1412, pp. 558–561
(2008)
[5] Sedano, C.I., Botha, A., Pawlowski, J.M.: A conceptual framework for ubiquitous mobile
environments. In: Portable Information Devices, and the 2008 7th IEEE Conference on
Polymers and Adhesives in Microelectronics and Photonics, 2nd IEEE International
Interdisciplinary Conference, August 17-20, pp. 1–6 (2008)
[6] Mininel, S., Vatta, F., Gaion, S., Ukovich, W., Fanti, M.P.: A customizable game engine for
mobile game-based learning. In: IEEE International Conference on Systems, Man and
Cybernetics, SMC 2009, October 11-14, pp. 2445–2450 (2009)
[7] Hu, X., Stalnacke, M., Minde, T.B., Carlsson, R., Larsson, S.: A Mobile Game to Collect
and Improve Position of Images. In: Third International Conference on Next Generation
Mobile Applications, Services and Technologies, NGMAST 2009, September 15-18, pp.
70–73 (2009); DOI: 10.1109/NGMAST.2009.64
[8] Baek, J., Yun, B.-J.: A sequence-action recognition applying state machine for user
interface. IEEE Transactions on Consumer Electronics 54(2), 719–726 (2008)
[9] Park, D., Woo, S., Jo, M., Lee, D.: An Interactive Fire Animation on a Mobile
Environment. In: International Conference on Multimedia and Ubiquitous Engineering,
MUE 2008, April 4-26, pp. 170–175 (2008)
[10] Pour, P.A., Gulrez, T., AlZoubi, O., Gargiulo, G., Calvo, R.A.: Brain-computer interface:
Next generation thought controlled distributed video game development platform. In: IEEE
Symposium on Computational Intelligence and Games, CIG 2009, December 15-18, pp.
251–257 (2008)
128
Q. Zhu et al.
[11] Kim, M., Park, S.-R., Song, S.-K.: Mobile interface for physical interactive games applied.
In: IEEE 13th International Symposium on Consumer Electronics, ISCE 2009, May 5-28,
pp. 1024–1028 (2009)
[12] Nascimento, L.M., de Almeida1, E.S., de Lemos Meira, S.R.: A Case Study in Software
Product Lines - The Case of the Mobile Game Domain. In: 34th Euromicro Conference
Software Engineering and Advanced Applications (SEAA), pp. 43–50 (2008)
[13] Cho, H., Yang, J.-S.: Architecture Patterns for Mobile Games Product Lines. In: ICACT
2008, pp. 118–122 (February 2008)