Published on

Published in: Technology, Business
  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide


  1. 1. Akihiro Minegishi CS491b 12/10/2004 Small Game on Mobile Appliances with J2ME Abstract The numbers of wireless and mobile appliances have been dramatically increased. At the same time, the processing powers of the mobile appliances also have been strengthened. Thus, building applications for mobile platforms is becoming more and more attractive. Also, those are tremendous opportunities to the software developers too. This project is intended to learn new technology for my future work. 1. Introduction Today, we are facing wireless revolution. People are more connected wirelessly. The number of wirelessly connected information appliances is increasing dramatically all over the world. The article of www.3G.co.uk reports that the EMC researched that there are over 1.5 billion cell phone users worldwide, and the number is highly expected to increase especially in populated developing countries such as India and China (www.3G.co.uk, 2004). Also, one of IDC’s reports shows that “mobile phone makers are expected to sell 670 million handsets to distributors this year, up from around 530 million units in 2003 (www.itfacts.biz, 2004).” Also, CNET reports another IDC’s research that explains that “worldwide PC unit shipments in 2003‘s 154.5 million units. IDC predicted shipments of 170 million units in 2004 (CNET, 2004).” These two statistics shows us that the more people uses wireless appliances rather than wired personal computers.
  2. 2. Today’s consumer targeted cell phones have capabilities of connecting internet, checking e-mails, play music and even taking photos. One another important function is that those cell phones also have capability of running applications. Some consumers purchase computers for some “killer” applications, but they would be able to run those applications on cell phones or wirelessly connected PDAs with one hand in the future. The project is intended to learn and experience those new wireless technologies. SunMicrosystem’s Java 2 Platform Micro Edition is one of the most popular and advanced mobile application platforms, so that this platform is appropriate to the project. Also, a small game is suitable to learn programming in new application platform, because it is not too large to build by single person in a short period of time. Another reason for this project is that the growing demands for the small games that run on mobile appliances. One of other reports from IDC shows that “the wireless gaming market in Asia-Pacific, excluding Japan, is expected to grow at a compound annual growth rate (CAGR) of 40%, from $237.4 mln last year to $1.3 bln in 2008” (www.itfact.biz, 2004). 2. Technological Background SunMicrosystems provides Java platform for small devices. The Java 2 Platform, Micro Edition (J2ME) provides environment for applications running on mobile phones, PDAs, and TV set-top boxes, or other embedded devices. Their Java 2 Platform Micro Edition is one of the most popular and advanced mobile application platforms for developing those small applications such as game and personal information managers. This technology is supported by more than 20 major wireless appliance hardware makers such as Nokia, Motorola, Samsung, and SonyEricsson. SunMicrosystems explains
  3. 3. that their Java 2 Platform Micro Edition the best solution for an extremely wide range situations, and it is also Java based (SunMicrosystems explains there are over three million Java developers). Also, there is a strong portability across the widest range of devices and supported by major phone vendors major carriers. J2ME has 3 layers, Configuration, Profile and Optional Package and those works on the Java virtual machine for mobile platforms. It is called KVM. The KVM (also known as the K Virtual Machine) is a compact, portable Java virtual machine intended for small, resource constrained devices such as cellular phones, pagers, personal organizers, mobile Internet devices, point-of sale terminals, home appliances, or other embedded devices. Configurations comprise a virtual machine and a minimal set of class libraries. They provide the base functionality for a particular range of devices that share similar characteristics, such as network connectivity and memory footprint. A configuration, for example, might be designed for devices that have less than 512 KB of memory and an intermittent network connection. Currently, there are two J2ME configurations: the Connected Limited Device Configuration (CLDC) and the Connected Device Configuration (CDC). Connected, Limited Device Configuration (CLDC) targets at devices with   160KB to 512KB total memory available for Java technology, limited power (battery), connectivity (often intermittent) and UI (small screen). To provide a complete runtime environment for a specific device category a configuration must be combined with a profile, a set of higher-level APIs example is to combine CLDC with the Mobile Information Device Profile (MIDP) to provide a complete Java application environment for cell phones. So, J2ME Mobile Information Device Profile (MIDP) provides application runtime environment for wireless devices based upon CLDC. J2ME Foundation Profile is base profile for non-GUI networked devices based upon CDC. These are fined through Java Community Process initiative.
  4. 4. The following explains some of the important interfaces. Those are the basic architectures that are used in the project. These are from SunMicrosystems’s API reference of MIDP 1.0. • Application model (life-cycle, packaging) javax.microedition.midlet The MIDlet package defines Mobile Information Device Profile applications and the interactions between the application and the environment in which the application runs. An application of the Mobile Information Device Profile is a MIDlet. • User interface (high and low level APIs) javax.microedition.lcdui The UI API provides a set of features for implementation of user interfaces for MIDP applications. • IO and utility packages from CLDC java.lang java.io java.util Java.lang MID Profile Language Classes included from Java 2 Standard Edition. Java.io Provides for system input and output through data streams. Java.util MID Profile Utility Classes included from Java 2 Standard Edition.
  5. 5. 3. Design: Game Rules The rule of the game is simple. It is designed as simple because the game should be played without reading manuals or any effort to learn and start the game. The left picture show the moment just after the game is started. The player can control single ball, which is called my ball and it is colored in red. On the screen, there are other balls that are called target balls, colored in blue. The target ball is does not move and cannot be controlled by the player. If my ball hit the wall, then my ball will bounce off the wall. As the left picture show, when my ball hit the target balls, then The target ball disappears and breaks into two green balls. Those are called piece balls and they moves and player does not have controls of moving piece balls. After a while, approximately ten seconds, those piece balls will disappear from the screen and player will get the score.
  6. 6. The goal of this game is to dodge the piece balls and remove all the target balls and piece balls from the screen. If player successfully removed all the balls then the player wins the game and the program will be stopped. If player want to try another game, pushing the stop talking button in red on left will let player return the launcher menu. The final score of player will be displayed on the top of the screen. In the case of left picture, the score is at 2400 points. If the player is failed to dodge the piece balls and any one of the piece balls hit the player’s my ball, then the player looses. If the player looses the game, the program will stop and the final score of player will be displayed on the top of the screen. If player want to try another game, pushing the stop talking button in red on left will let player return the launcher menu.
  7. 7. The basic idea of this game came from an old DOS game. I played this game more than 10 years ago with PC with Intel 80286 processors. This game is ASCII character based and pieces only move up, down, right, and left. It does not have two pieces if my memory is correct. I designed my own scoring system, interfaces, graphics and such, so that even though the idea came from this game, the game is created without intention of restore or imitate the old DOS game. 4. Development The project started with comparing different platforms for developing application on mobile appliances. There are many, but I choose J2ME because I am familiar with JAVA and many devices supports MIDP. The MIDP 2.0 is released this year and I was planning to use MIDP 2.0, but later, I found that there are not many devices that support MIDP 2.0 because it is new. So, I decide to follow the MIDP 1.0. After some more research about the J2ME, I found that even though there is a standard for programming, the result of the program could be different because of the huge difference between different hardware. Carriers and makers has own additional libraries that would reduce the low level works to code the game, but that would loose the compatibility. I decided to code in pure MIDP 1.0 and CDLC so that the program would have more compatibility. I spent few weeks to design the game and installing the development environment. I did not know anything about programming in J2ME, so I started with reading a book.
  8. 8. Environment:  Language: Java  Platform: J2ME (MIDP1.0 + CLDC)  Developing Environment: J2ME wireless tool kit 1.0.3 + Forte CE v3.0  Running Environment: KVM Following list shows the usual mobile application development process by using Java 2 Platform Micro Edition. 1) Write a Java application 2) Compile it 3) Pre-verify it 4) Package it into a JAR file 5) Create the application descriptor 6) Publish the MIDlet suite 7) Install on the device or emulator SunMicrosystems provides development kit for the J2ME that takes care of those steps in single environment. The project is build with this toolkit. It is called The Java 2 Platform, Micro Edition (J2ME) Wireless Toolkit. It is for developing wireless applications that are based on J2ME’s Connected Limited Device Configuration (CLDC) and Mobile Information Device Profile (MIDP). The toolkit includes the emulation environments. 5. Implementation The list below shows the behavior of the program based on the game rules. I implemented each functions step by step. Some of them were easy and finished in 30 minutes, but some other are difficult and spent few weeks until it works without problems.
  9. 9. o When the program starts, my ball will be displayed. o Initially, my ball move at constant speed in one direction. o My ball will change moving direction when a keypad is pressed. o When my ball hit the wall, then my ball will bounce. o When the game starts, the target ball appears. o When my ball hit a target, then the target ball disappears. o When my ball hit a target, then the target will break down into piece ball. o Piece ball moves at constant speed in a direction. o When a piece ball hit the wall, then piece ball will bounce. o Afar a while, piece disappears. o When you hit moving pieces, then the program ends. o When all the target balls and piece balls disappear, then the program ends. The top level flow of the program is simple. The flow chart of the game is the right picture.
  10. 10. Classes that are used in the program is following  Ball: It is the class that controls basic flow of lifecycle of the MIDlet of the program, that includes,  Ball()//Ball constructor  startApp()//This method is called when MIDlet Starts,  pauseApp()//This method is called when MIDlet pauses  destroyApp()//This method is called when MiDlet ends  doExit()//Destroys MIDlet and exit  BallCanvas: This class is the canvas of the program. So this Ball canvas extends canvas class. Also, it implements command listener and it is runnable because the program uses threads. Includes,  BallCanvas()//constructor for the ballcanvas  start()//when start method is called, this method will create the new thread and start the thread  stop()//this method is called when the thread is stopped  run()//run method for the thread as long as the program is running, it will repaint the graphics  paint()//paint method will draw the graphics on the canvas  keyPressed()// this method is called when the key is pressed  MyBall: MyBall is a ball that you can control my ball moves four ways by using key pad. My ball will bounce when it hit the wall.  MyBall()//constructor for my ball  Accessor methods for position and moving direction  Paint()//this method will actually draw the graphics
  11. 11.  TargetBall : Target ball is a ball that is stationed  TargetBall()////constructor of the targetball  Accessor methods for position and moving direction  Paint()//this method will actually draw the graphics  PieceBall: piece ball appears after the target ball is hit by my ball. When the target ball is hit, the piece ball will breaks into two piece balls. Both piece balls’ directions are defined by the moving direction of my ball.  PieceBall()//constructor for my ball  Accessor methods for position and moving direction  Paint()//this method will actually draw the graphics 6. Algorithm Collisions between target balls and my ball: Depending on the direction of my ball, the direction of piece ball will be set. Even number indexed object in array of piece ball’s direction will be set to the 45 degree left of direction of my ball and odd number indexed object in array piece ball’s direction is set to the 45 degree right of direction of my ball. Score: The score is 100 for one ball. There is a bonus for the number of the moving ball at the same time. Although there is no stages in the game, the player have to choose their own play level. Ether the player takes risk and have chance to get higher point or remove balls safely with lower scores. Below formula calculate the points, and the “point” parameter represents the number of currently moving ball and that number times 200 for bonus addition to 100. point--;
  12. 12. score=score+100+point*200; 7. Poject Evaluation The project is tested on emulator and there cannot be observed any performance issue during the development. The program should have small memory footprint and processor time, because it is a simple program and it is used threading technology to display the graphics that reduces amount of processes that CPU and graphics processors have to process. Following shows the result of the execution in emulator of wireless tool kit. Execution completed successfully 369383 bytecodes executed 120 thread switches 317 classes in the system (including system classes) 1447 dynamic objects allocated (184612 bytes) 6 garbage collections (116496 bytes collected) Total heap size 500000 bytes (currently 419596 bytes free) 8. Conclusion and Future Work The project uses Java 2 Platform Micro Edition, and this is the most powerful technology to develop applications for mobile appliances. The project is a simple program but it includes basic processes to develop typical applications. So, the future work will be extending this project or making new applications such as a scheduler for mobile devices by using the knowledge that came from the first step experience. Most of the time for the project had spent on starting the project. One of the most difficult parts was to learn about the technology and to setup new development environment. If a developer knows about the technology and already has environment to develop, then the effort that the developer takes can be reduced dramatically. One of the success of the project is that the opportunity to know new technology (that is not taught in
  13. 13. schools). However, as a drawback, because it is no taught in school, self learning of new technology takes much longer time and actual coding time would be sacrificed. Works Sited CNET “IDC expects increase in 2004's PC shipments” http://news.com.com/IDC+expects+increase+in+2004s+PC+shipmen ts/2110-1003_3-5172134.html www.3g.co.uk “Mobile Subscriber Numbers Exceed 1.5 Billion” http://www.3g.co.uk/PR/June2004/7947.htm www.itfacts.biz “Mobile phone sales up 25% in Q3 2004” http://www.itfacts.biz/index.php?id=P1870 “Asia-Pacific mobile gaming market to generate $1.3 bln in2008” http://www.itfacts.biz/index.php?id=P1681