Software Engineering for Embedded Systems 352
[7D3A1542] Roger Lau Sin Tik
Assignment Game Of Life
Software Engineering for Embedded Systems 352
Assignment: Game Of Life
Introduction The following document provides description of an assignment of Sofware Engineering for Embedded Systems 352. Purpose of the assignment is to demonstrate understanding in programming on J2ME by designing and building an animated MIDlet, John Conway’s Game Of Life. Game Of Life is represented by a rectangular grid which simulates the world for a particular species of living organisms. In the grid each shaded cell represents a single living organism and the entire collection of shaded cells on the grid represents the entire population that is alive in a particular generation. Each new generation follows from the previous one in an accordance with two simple rules. • A live cell with exactly two or three adjacent cells stays alive. Otherwise the cell dies. • A dead cell with exactly three adjacent cells comes to life. Otherwise it remains dead. The program provide user with the following convenience. • • • • • • • •
Describing initial configuration of cells in the grid. Loading a preset initial grid (Glider, Small Exploder, Exploder). Downloading configuration from http://www.computing.edu.au/~michael/feep.pbm Setting the birth rate and death rate. Playing, stopping and stepping the animation. Setting boundary cells to be wrapped around or surrounded by dead cells. Setting speed of animation Setting size of grid
The following MIDP classes is understood and used in the program. • • • • • • • •
MIDlet Display CommandListener Command List Timer TimerTask Canvas
Attached in the same mail are Java source code (GameOfLife.java and GOLCanvas.java) and MIDlet suite that contains GameOfLife.jad, GameOfLife.jar and GameOfLife.prc. These files are tested and guaranteed to run on KToolbar of J2ME Wireless Toolkit and MIDP 1.0 environment on Palm Operating System Emulator (POSE).
Roger Lau © 2007
1/ 5
Software Engineering for Embedded Systems 352
Assignment: Game Of Life
Design Use Case Diagram The following Use Case diagram illustrates how user can interact with the program.
Create Grid
Load Preset
<<extend>>
Load Downloaded <<extend>>
Load Grid User Play <<extend>> <<extend>> Control Playback
Stop
<<extend>> Next
Set Rate <> Change Settings
Set Wrap <> <>
Set Speed
<> Set Grid Size
Roger Lau © 2007
2/ 5
Software Engineering for Embedded Systems 352
Assignment: Game Of Life
State Diagram The following state diagram illustrates transition of states during program execution. The program starts in a static screen showing one of the preset initial configuration, Glider. When play button is pressed, program continues to play state where animation is running. The running animation can be interrupted by pressing menu or stop button. In menu state, user can configure size of grid, speed of animation, birth rate, death rate, boundary handler, load new configuration or load empty grid. The program exits when exit command is selected from menu.
Next button pressed Start
Stop Menu button pressed New button pressed
Play button pressed
Stop button pressed
Play button pressed
Menu
Exit
Menu button pressed
Play
Roger Lau © 2007
3/ 5
Software Engineering for Embedded Systems 352
Assignment: Game Of Life
Class Diagram The following class diagram illustrate the relationship between classes in the program. Class GameOfLife and GOLCanvas are designed from scratch while the others are predefined in J2ME library. GameOfLife which inherits MIDlet and implement interface CommandListener aggregates Command, Timer, TimerTask, List and GOLCanvas that inherits abstract class Canvas to provide Graphical User Interface for interaction between user and the program. Timer class is responsible for animating the cell generation.
Canvas
MIDlet
GOLCanvas
GameOfLife
<>
CommandListener
List
Command
Timer
Roger Lau © 2007
TimerTask
4/ 5
Software Engineering for Embedded Systems 352
Assignment: Game Of Life
Limitation All requirements of the assignment are implemented except for saving current configuration and displaying useful information. The logic behind the program is simple but due to lack of experience in programming in J2ME make developing this program time consuming. The major difference between programming for desktop application and embedded application is having limited resource. For desktop application, primitive data type int is widely used but it is not the case when it comes to embedded programming. Every declaration of variable is thought thoroughly what type of primitive data type to be declare. byte and short are widely used in the program. byte is 8 bits, which support up to 256. short is 16 bits, which support up to 65535. They are sufficient for most cases. Another difficulty would be screen size problem. This problem occurs when the program tries to load downloaded pbm file into array. Handling program involving thread programming needs extra care. Sequence of execution may be confusing.
Roger Lau © 2007
5/ 5