SlideShare a Scribd company logo
1 of 26
Tank battle
Farzad Nozarian - Vahid Ranaei
Amirkabir university of technology
References
Problem Definition
Tank Movement
Android Devices
 Orientation Sensors
Desktops
 ‘WASD’ Control Keys
VS.
Problem Definition
Tank Movement/Android Devices
public void onSensorChanged(SensorEvent sensorEvent) {
if (sensorEvent.sensor.getType() == Sensor.TYPE_ORIENTATION) {
float headingAngle = sensorEvent.values[0];
float pitchAngle = sensorEvent.values[1];
float rollAngle = sensorEvent.values[2];
// TODO Apply the orientation
changes to your application.
}
}
Problem Definition
Tank Movement/Desktop Devices
inputManager.addMapping("Lefts", new KeyTrigger(KeyInput.KEY_H));
inputManager.addMapping("Rights", new KeyTrigger(KeyInput.KEY_K));
inputManager.addMapping("Ups", new KeyTrigger(KeyInput.KEY_U));
inputManager.addMapping("Downs", new KeyTrigger(KeyInput.KEY_J));
inputManager.addListener(this, "Lefts");
inputManager.addListener(this, "Rights");
Problem Definition
Tank Movement/Desktop Devices
onAction
handler
if (binding.equals("Ups")) {
if (value) {
accelerationValue -= 800;
} else {
accelerationValue += 800;
}
player.accelerate(accelerationValue); }
else if (binding.equals("Rights")) {
if (value) {
steeringValue += -.5f;
} else {
steeringValue += .5f;
}
player.steer(steeringValue);
}
Problem Definition
Tank Movement
Some Abstractions
Fire
Move Forward (Accelerate)
Move Around (Steer)
…
Problem Definition
Tank Movement
vehicle.steer(steeringValue)
vehicle.accelerate(accelerationValue)
applyImpulse
resetSuspension
setPhysicsLocation
setPhysicsRotation
setLinearVelocity
Pattern Definition
• Decouple an abstraction from its implementation so that
the two can vary independently
• When abstractions and implementations should
be extensible through subclassing
Bridge!
Pattern Definition
Pattern Solution
Bridge
Problem Definition
Tank Shooting
Shooting In Real World !
Burst mode
Selective fire
Automatic firearm
Bump firing
Same ‘Fire’ Different Behaviors ?!
Pattern Definition
Tank Shooting
• Many related classes differ only in their behavior
• We need different variant of algorithm
• We need run-time shooting variation
Pattern Solution
Strategy
Problem Definition
World of Complexity!
Geometry
polygon mesh
material
specifying its shape
color
texture
opacity/transparency
Problem Definition
World of Complexity!
Spatial
Purpose:
Abstract data structure that stores user data and transformations
(= translation, rotation, scale) of elements of the 3D
Geometry Node
Visibility: visible 3D object
invisible "handle" for a group of
Spatials
Purpose: represent an object's look
structure and group Geometries
and other Nodes
Examples:
Box, sphere, player, building, terrain,
vehicle, missiles …
rootNode, audioNode, vehicleNode
or shipNode with passengers
attached, etc.
Pattern Definition
World of Complexity!
• Compose objects into tree structures to represent part-
whole hierarchies
• Clients treat individual objects and compositions of
objects uniformly
• We want clients to be able to ignore the difference
between compositions of objects and individual objects
Pattern Solution
World of Complexity!
Problem Definition
Family of Game Entities
Problem Definition
game configuration
Bunch of configurations !!
:
Problem Definition
game configuration
public static class UserBuilder {
private final String firstName;
private final String lastName;
..
public UserBuilder(String firstName, String
lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
public UserBuilder age(int age) {
this.age = age;
return this;
}
..
public User build() {
return new User(this);
}
}
}
public class User {
private final String firstName; // required
private final String lastName; // required
private final int age; // optional
private final String phone; // optional
private final String address; // optional
private User(UserBuilder builder) {
this.firstName = builder.firstName;
this.lastName = builder.lastName;
..
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public user getUser(){
return new
User.UserBuilder(‘John’,’Doe’)
.age(30)
.phone(‘3235345)
.address(‘’Fake address 33)
.build();
Problem Definition
game configuration
public class Configuration {
private int displayResolution;// display resolution
private int displayMode;// full screen?
private int soundVolume;//Sound volume
private int musicVolume; //Music volume
//....
private Configuration(ConfigBuilder builder) {
this.displayResolution = builder.displayResolution;
this.displayMode = builder.displayMode;
..
}
public int getDisplayResolution() {
return displayResolution;
}
public int getDisplayMode() {
return displayMode;
}
..
public static class ConfigBuilder{
private int displayResolution=0;// display resolution
private int displayMode=0;// full screen?
private int soundVolume=0;//Sound volume
private int musicVolume=0; //Music volume
//....
public ConfigBuilder displayResolution(int dr)
{
this.displayResolution = dr;
return this;
}
public ConfigBuilder displayMode(int dm)
{
this.displayMode = dm;
return this;
}
..
public Configuration build(){
return new Configuration(this);
}
}
}
Problem Definition
game configuration
But it is not all of it ..
Problem Definition
game configuration
Builderton pattern !? :o
Problem Definition
game configuration
public class Configuration {
private static Configuration c;
private int displayResolution; // display resolution
private int displayMode; // full screen?
private int soundVolume; //Sound volume
private int musicVolume; //Music volume
//....
private Configuration(ConfigBuilder builder) {
this.displayResolution = builder.displayResolution;
this.displayMode = builder.displayMode;
this.soundVolume = builder.soundVolume;
this.musicVolume = builder.soundVolume;
}
public int getDisplayResolution() {
return displayResolution;
}
public int getDisplayMode() {
return displayMode;
}
…
public static class ConfigBuilder{
private int displayResolution=0;
private int displayMode=0;
private int soundVolume=0;
private int musicVolume=0;
//....
public ConfigBuilder displayResolution(int dr)
{
this.displayResolution = dr;
return this;
}
public ConfigBuilder displayMode(int dm)
{
this.displayMode = dm;
return this;
}
…
public Configuration build(){
if (c == null)
{ c=new Configuration(this);
return c;
}
else return c;
}
}
}
To Be Continue …

More Related Content

Similar to Tank Battle - A simple game powered by JMonkey engine

assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docxassignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
ssuser562afc1
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxCodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
mary772
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxCodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
mccormicknadine86
 
PROGRAM 2 – Fraction Class Problem For this programming as.pdf
PROGRAM 2 – Fraction Class Problem For this programming as.pdfPROGRAM 2 – Fraction Class Problem For this programming as.pdf
PROGRAM 2 – Fraction Class Problem For this programming as.pdf
ezonesolutions
 
Please help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdfPlease help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdf
JUSTSTYLISH3B2MOHALI
 
I wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdfI wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdf
feelinggifts
 

Similar to Tank Battle - A simple game powered by JMonkey engine (20)

assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docxassignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
 
Design patterns
Design patternsDesign patterns
Design patterns
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxCodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxCodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
 
Ali.pptx
Ali.pptxAli.pptx
Ali.pptx
 
Ali.pptx
Ali.pptxAli.pptx
Ali.pptx
 
Type script by Howard
Type script by HowardType script by Howard
Type script by Howard
 
Architecture components - IT Talk
Architecture components - IT TalkArchitecture components - IT Talk
Architecture components - IT Talk
 
Architecture Components
Architecture Components Architecture Components
Architecture Components
 
TypeScript by Howard
TypeScript by HowardTypeScript by Howard
TypeScript by Howard
 
Howard type script
Howard   type scriptHoward   type script
Howard type script
 
Reloj en java
Reloj en javaReloj en java
Reloj en java
 
PROGRAM 2 – Fraction Class Problem For this programming as.pdf
PROGRAM 2 – Fraction Class Problem For this programming as.pdfPROGRAM 2 – Fraction Class Problem For this programming as.pdf
PROGRAM 2 – Fraction Class Problem For this programming as.pdf
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 
Please help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdfPlease help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdf
 
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
 
Kotlin Overview (PT-BR)
Kotlin Overview (PT-BR)Kotlin Overview (PT-BR)
Kotlin Overview (PT-BR)
 
Meetup di GDG Italia - Leonardo Pirro - Codemotion Rome 2018
Meetup di GDG Italia - Leonardo Pirro -  Codemotion Rome 2018 Meetup di GDG Italia - Leonardo Pirro -  Codemotion Rome 2018
Meetup di GDG Italia - Leonardo Pirro - Codemotion Rome 2018
 
Griffon @ Svwjug
Griffon @ SvwjugGriffon @ Svwjug
Griffon @ Svwjug
 
I wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdfI wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdf
 

More from Farzad Nozarian

Big Data and Cloud Computing
Big Data and Cloud ComputingBig Data and Cloud Computing
Big Data and Cloud Computing
Farzad Nozarian
 

More from Farzad Nozarian (14)

SHARE Interface in Flash Storage for Relational and NoSQL Databases
SHARE Interface in Flash Storage for Relational and NoSQL DatabasesSHARE Interface in Flash Storage for Relational and NoSQL Databases
SHARE Interface in Flash Storage for Relational and NoSQL Databases
 
Object Based Databases
Object Based DatabasesObject Based Databases
Object Based Databases
 
Ultimate Goals In Robotics
Ultimate Goals In RoboticsUltimate Goals In Robotics
Ultimate Goals In Robotics
 
The Continuous Distributed Monitoring Model
The Continuous Distributed Monitoring ModelThe Continuous Distributed Monitoring Model
The Continuous Distributed Monitoring Model
 
Big data Clustering Algorithms And Strategies
Big data Clustering Algorithms And StrategiesBig data Clustering Algorithms And Strategies
Big data Clustering Algorithms And Strategies
 
Shark - Lab Assignment
Shark - Lab AssignmentShark - Lab Assignment
Shark - Lab Assignment
 
Apache HBase - Lab Assignment
Apache HBase - Lab AssignmentApache HBase - Lab Assignment
Apache HBase - Lab Assignment
 
Apache HDFS - Lab Assignment
Apache HDFS - Lab AssignmentApache HDFS - Lab Assignment
Apache HDFS - Lab Assignment
 
Apache Hadoop MapReduce Tutorial
Apache Hadoop MapReduce TutorialApache Hadoop MapReduce Tutorial
Apache Hadoop MapReduce Tutorial
 
Apache Spark Tutorial
Apache Spark TutorialApache Spark Tutorial
Apache Spark Tutorial
 
Apache Storm Tutorial
Apache Storm TutorialApache Storm Tutorial
Apache Storm Tutorial
 
Big Data and Cloud Computing
Big Data and Cloud ComputingBig Data and Cloud Computing
Big Data and Cloud Computing
 
Big Data Processing in Cloud Computing Environments
Big Data Processing in Cloud Computing EnvironmentsBig Data Processing in Cloud Computing Environments
Big Data Processing in Cloud Computing Environments
 
S4: Distributed Stream Computing Platform
S4: Distributed Stream Computing PlatformS4: Distributed Stream Computing Platform
S4: Distributed Stream Computing Platform
 

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Recently uploaded (20)

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 

Tank Battle - A simple game powered by JMonkey engine

  • 1. Tank battle Farzad Nozarian - Vahid Ranaei Amirkabir university of technology
  • 3. Problem Definition Tank Movement Android Devices  Orientation Sensors Desktops  ‘WASD’ Control Keys VS.
  • 4. Problem Definition Tank Movement/Android Devices public void onSensorChanged(SensorEvent sensorEvent) { if (sensorEvent.sensor.getType() == Sensor.TYPE_ORIENTATION) { float headingAngle = sensorEvent.values[0]; float pitchAngle = sensorEvent.values[1]; float rollAngle = sensorEvent.values[2]; // TODO Apply the orientation changes to your application. } }
  • 5. Problem Definition Tank Movement/Desktop Devices inputManager.addMapping("Lefts", new KeyTrigger(KeyInput.KEY_H)); inputManager.addMapping("Rights", new KeyTrigger(KeyInput.KEY_K)); inputManager.addMapping("Ups", new KeyTrigger(KeyInput.KEY_U)); inputManager.addMapping("Downs", new KeyTrigger(KeyInput.KEY_J)); inputManager.addListener(this, "Lefts"); inputManager.addListener(this, "Rights");
  • 6. Problem Definition Tank Movement/Desktop Devices onAction handler if (binding.equals("Ups")) { if (value) { accelerationValue -= 800; } else { accelerationValue += 800; } player.accelerate(accelerationValue); } else if (binding.equals("Rights")) { if (value) { steeringValue += -.5f; } else { steeringValue += .5f; } player.steer(steeringValue); }
  • 7. Problem Definition Tank Movement Some Abstractions Fire Move Forward (Accelerate) Move Around (Steer) …
  • 9. Pattern Definition • Decouple an abstraction from its implementation so that the two can vary independently • When abstractions and implementations should be extensible through subclassing Bridge!
  • 12. Problem Definition Tank Shooting Shooting In Real World ! Burst mode Selective fire Automatic firearm Bump firing Same ‘Fire’ Different Behaviors ?!
  • 13. Pattern Definition Tank Shooting • Many related classes differ only in their behavior • We need different variant of algorithm • We need run-time shooting variation
  • 15. Problem Definition World of Complexity! Geometry polygon mesh material specifying its shape color texture opacity/transparency
  • 16. Problem Definition World of Complexity! Spatial Purpose: Abstract data structure that stores user data and transformations (= translation, rotation, scale) of elements of the 3D Geometry Node Visibility: visible 3D object invisible "handle" for a group of Spatials Purpose: represent an object's look structure and group Geometries and other Nodes Examples: Box, sphere, player, building, terrain, vehicle, missiles … rootNode, audioNode, vehicleNode or shipNode with passengers attached, etc.
  • 17. Pattern Definition World of Complexity! • Compose objects into tree structures to represent part- whole hierarchies • Clients treat individual objects and compositions of objects uniformly • We want clients to be able to ignore the difference between compositions of objects and individual objects
  • 21. Problem Definition game configuration public static class UserBuilder { private final String firstName; private final String lastName; .. public UserBuilder(String firstName, String lastName) { this.firstName = firstName; this.lastName = lastName; } public UserBuilder age(int age) { this.age = age; return this; } .. public User build() { return new User(this); } } } public class User { private final String firstName; // required private final String lastName; // required private final int age; // optional private final String phone; // optional private final String address; // optional private User(UserBuilder builder) { this.firstName = builder.firstName; this.lastName = builder.lastName; .. } public String getFirstName() { return firstName; } public String getLastName() { return lastName; } public user getUser(){ return new User.UserBuilder(‘John’,’Doe’) .age(30) .phone(‘3235345) .address(‘’Fake address 33) .build();
  • 22. Problem Definition game configuration public class Configuration { private int displayResolution;// display resolution private int displayMode;// full screen? private int soundVolume;//Sound volume private int musicVolume; //Music volume //.... private Configuration(ConfigBuilder builder) { this.displayResolution = builder.displayResolution; this.displayMode = builder.displayMode; .. } public int getDisplayResolution() { return displayResolution; } public int getDisplayMode() { return displayMode; } .. public static class ConfigBuilder{ private int displayResolution=0;// display resolution private int displayMode=0;// full screen? private int soundVolume=0;//Sound volume private int musicVolume=0; //Music volume //.... public ConfigBuilder displayResolution(int dr) { this.displayResolution = dr; return this; } public ConfigBuilder displayMode(int dm) { this.displayMode = dm; return this; } .. public Configuration build(){ return new Configuration(this); } } }
  • 25. Problem Definition game configuration public class Configuration { private static Configuration c; private int displayResolution; // display resolution private int displayMode; // full screen? private int soundVolume; //Sound volume private int musicVolume; //Music volume //.... private Configuration(ConfigBuilder builder) { this.displayResolution = builder.displayResolution; this.displayMode = builder.displayMode; this.soundVolume = builder.soundVolume; this.musicVolume = builder.soundVolume; } public int getDisplayResolution() { return displayResolution; } public int getDisplayMode() { return displayMode; } … public static class ConfigBuilder{ private int displayResolution=0; private int displayMode=0; private int soundVolume=0; private int musicVolume=0; //.... public ConfigBuilder displayResolution(int dr) { this.displayResolution = dr; return this; } public ConfigBuilder displayMode(int dm) { this.displayMode = dm; return this; } … public Configuration build(){ if (c == null) { c=new Configuration(this); return c; } else return c; } } }