Categories > IT Management



How to design an object-oriented game? (Case Study: Save My Water – available on iTunes)

Posted on April 7th, 2013 By Danial Javanmardi


According to Software Engineering, a design specifies the structure of how a software system will be written and function, without actually writing the complete implementation. It is a transition from “what” the system must do, to “how” the system will do it.

The Unified Modeling Language (UML) is a standard language for modelling
the design of object-oriented software systems. UML defines several models for representing systems:

  • The use case model describes the requirements of the user.
  • The class model captures the static structure.
  • The interaction model represents the scenarios and messages flows.
Use Case Model

It contains fairly complete description of all activities that occur in response to a trigger event. The basic information of a Use Case consists of a name, a sequence number and description.

Class Model

It specified from the project specifications and requirements. Nouns are potential classes, objects and attributes, while verbs are potential methods or responsibilities of a class.

  • What classes will be needed to implement a system that meets project requirements?
  • What attributes and methods will be needed for each class?
  • How will the classes interact with each other?
Interaction Model

It is used to describe some type of interactions among the different elements in the model. This interactive behavior is represented in UML by two diagrams known as Sequence diagram and Collaboration diagram. The basic purposes of both the diagrams are similar. A sequence diagram models the collaboration of classes based on a time sequence. It shows how the classes interact with others in a particular scenario of a use case.


On the following, I am going to explain briefly a case study of how to design on object-oriented way for an iPhone game.

Case Study – iTunes: Save My Water

Figure 1: The start page of the game

Game Description

The game starts with a simple one-touch mechanism, which guides the user on different ways to save water with each level and the user is rewarded if he does well. The first installation of the game spreads across 30 levels and 9 backdrops. As the user progresses to the other levels, more game mechanisms and game items will be included to make the game more challenging and interesting. All the game interfaces and functions are based on one touch mechanism. The player’s objective is to save as much water as they can in each level. The player will be rewarded with credits based on the amount of water they save in each level. The credits can be used to purchase or upgrade items to be used in the subsequent level.

Games Mechanism
Mechanism Description Steps
One Inconsiderate kids turn on the water taps and leave them running. Player taps on the water source to turn off the tap to prevent water wastage.
Two Item: Container to hold water temporarily. Player gains credits when they win a level. These credits can be used to buy items to help them in their quest. A container can be used to hold the water leaks. Once the container is full, the water will be returned as saved water.
Three Condition: Severity of water wastage. Some water sources lose water more rapidly than others. The rate of water loss is indicated by red, yellow, or green. The player has to prioritize to save more water.
Four Item: ‘Educator’ that teaches the kids not to waste water The player can drag ‘Educator’ items to educate the kids. The player can catch the kids and educate them to turn off the tap before they waste the water.
Five Condition: Leakages found
Item: Black tape
As the player progresses to the next levels, the challenge increases with the introduction of leakages on top of the running tap. The users have to fix the leaks temporarily using the item black tape, which they need to exchange with the credits earned by leveling up.
Six Condition : Missing Tap In the levels, we will introduce missing taps. The player has to find the tap and install it quickly to prevent a large amount of wasted water.
Seven Item : Pipe Wrench In the levels, we will introduce Pipe Wrench. The player can use Pipe Wrench to fix leakages permanently rather than temporarily.
Eight Condition : reuse rain water. In the levels, we will introduce periodic rain. During the rain, the player can put their container outdoors to collect rainwater. The rainwater can be used in specific areas (i.e. Flush toilet, wash floor, water plant. Etc) The rainwater collected contributes to their water saved.
Functional Requirement
Section Description
Player
  • The Player must have the ability to quit the game at any time.
  • The Player must have the ability to pause the game at any time.
  • The game must be able to display the rules of the game to the Player.
  • Guide and Tutorial should be provided for the Player.
  • The game must provide a push notification to attract dormant player to come back to the game.
  • The Player rate of each level at the end of each level is shown to the player.
Artificial Intelligence (AI)
  • AI is added to make each level more attractive and each time player plays a level the sequence of the events will be different from previous ones.
Non-Functional Requirement
Section Description
Operational
  • The system should be developed for iPhone and iPad application.
Performance
  • Any interaction between the user and the system should not exceed more than 7 seconds.
  • The game must start up less that 90sec.
Security
  • No personal information is stored by the system; hence, no specific security requirements need to be defined.




Figure 2: The user case diagrams of the game

Use Case Scenario

The next step is to define the use case at a low level of detail by writing Use Case Scenario. A Use Case Scenario exposes step by step of how a user is intending to use a system, essentially capturing the system behaviour from the user’s point of view.

A. Star Water Conversation Actor: Player
A.1. The player runs the game and direct to the Start Page
A.2. The Player could go to the High Score page
A.3. The Player could go to the Save Water Page
A.4. The Player chooses the Start and direct to the Location Select Page
A.5. The Player selects one location and direct to the Level Select Page
B. Choose Level Play Option Actor: Player
Pre-Request Scenario : A.5
B.1. The Player could go to the Store Page and buy Resolving Leaking Tools by her/his own in-game credit
B.2. The Player has to go to the Inventory Page and choose only three Resolving Inventory Tools that could play in the game
B.3. The Player selects a level on the Level Select Page
B.4. The Senario page of that location is shown to the Player
B.5. The Tutorial Page of that location is shown to the Player
B.6. The Player starts to play the game
B.7. The Player could pause the game
C. Pause Game Actor: Player
Pre-Request Scenario : B.7
C.1. The Player could adjust the voice
C.2. The Player could close the voice
C.3. The Player could restart the game
C.4. The Player could continue the game
D. Play Save Container Actor: Player
Pre-Request Scenario : B.6
D.1. A kid coming into the scene and going toward a Leaking Source
D.2. The Kid opens the Leaking Source
D.3. The kid leaves the Leaking Source half closed, and is leaving the scene
D.4. The Leaking Source gets out y (red, yellow, green) liter of water out of it in leaving half closed condition
D.5. The Player puts a Water Save Container under the Leaking Source to prevent water wastage
D.6. The Player taps on the Leaking Source source to close the Leaking Source
D.7. The Water Save Container is going to level to the maximum capacity
D.8. The Water Save Container becomes full, it automatically returns back Saved Water and releases the Water Save Container
D.9. The Leaking Source is closed by the Player and automatically the Saved Container returns back Saved Water and releases it for further
use
D.10. The amount of saved water is summed up with the Total Saved Water
E. Play Educator Actor: Player
Pre-Request Scenario : B.6
E.1. A kid coming into the scene and going toward a Leaking Source
E.2. The Kid opens the Leaking Source
E.3. The Kid uses water at the Leaking Source within x limited time limited
E.4. The Player places an Educator on the opened Leaking Source during x time duration
E.5. The Educator starts to educate the kid to do not leave the Leaking Source open
E.6. The Educated Kid closes the leaking source completely and leaves the scene
F. Play Black Tape Actor: Player
Pre-Request Scenario : B.6
F.1. The Leaking Source is leaking water
F.2. The Leaking Source gets out y (red, yellow, green) liter of water out
F.3. The Player places Black Tape on Leaking Source
F.4. The Player taps on the Leaking Source to proceed installing the Black Tape over it
F.5. The Leaking Source is closed temporarily within a time duration of Black Tape*
F.6. The Leaking Source is open as the time duration has been passed
F.7. Continues on F.1.
H. Play Missing Pipe Actor: Player
Pre-Request Scenario : B.6
G.1. The Player drags the scene to the Leaking Source of Missing Pipe
G.2. The Leaking Source is leaking water
G.3. The Leaking Source gets out y liter of water out
G.4. The Leaking Source displays a warning Regards a Missing Pipe
G.5. The Missing Pipe becomes visible to the Player
G.6. The Player is looking for the Missing Pipe
G.7. The Missing Pipe is found by the Player
G.8. The player picks up the Missing pipe
G.9. The Player places the Missing Pipe on the Leaking Source
G.10. The Player taps on the Leaking Source to proceed installing of the Missing Pipe
G. Play Pipe Wrench Actor: Player
Pre-Request Scenario : B.6
H.1. The Leaking Source is leaking water
H.2. The Leaking Source gets out y liter of water out
H.3. The Player places Pipe Wrench on Leaking Source
H.4. The Player taps on the Leaking Source to proceed using the Pipe Wrench to close permanently the Leaking Source
H.5. The Leaking Source is closed
From Use Case Scenario to Class Diagram
  1. Identify classes of objects in the Use Case Scenario
    • Nouns may be classes
    • does Class have attributes and does it have operations
  2. Identify attributes of each class
    • What characteristics are important to keep track of?
    • What data must be remembered during object’s life?
  3. Identify methods of each class
    • What actions must the class be able to perform?
    • What actions can be done to the object (e.g., to change the attribute of the object)?
  4. Identify parameters and return types of methods
    • What input does a method need from caller?
    • Does the method generate a result value?
    • The return type must match the data type of data to be returned.




Figure 3: Class Diagram of Save My Water




Figure 4: iTunes Preview of Save My Water

Tags:

,

Next Article: