SlideShare a Scribd company logo
An Introducton to Game
Programming with Flash
3: Design Patterns
Design Patterns
Characteristc
● Universal solutons of common, repeatng problems
● Descripton of a soluton, not an implementaton
● Mainly depends on OOP paradigm
Pros
● Standardises nomenclature
● Standardises structure
● Independent from programming language
Design Patterns
● Creatonal
● Builder
● Abstract Factory
● Factory Method
● Singleton
● Object Pool
● Structural
● Decorator
● Adapter
● Bridge
● Behavioural
● Command
● Mediator
● Strategy
● Architectural
● Model-View-Controller
Singleton Pattern
● Guarantees creatng only single instance of a class
● Doesn't pollute global namespace
● Overused and treated as new global
● Often used to store configuraton
● Alternatve: Dependency Injecton
Singleton Pattern
package foo
{
public class Singleton
{
private static var instance:Singleton;
public function Singleton()
{
}
public static function getInstance():Singleton
{
if (!instance)
{
instance = new Singleton();
}
return instance;
}
}
}
1
2
3
Singleton Pattern
import foo.Singleton;
var singleton:Singleton = Singleton.getInstance();1
Singleton Pattern
Object Pool Pattern
● Creates set of objects ready to use rather then
creatng/removing objects
● Used when creatng new objects is expensive
● You must remember about pool's limit
Object Pool Pattern
package foo
{
public class EnemyPool
{
private var enemies:Vector.<Enemy>;
public function EnemyPool(count:int)
{
enemies = new Vector.<Enemy>();
while(--count >= 0)
{
enemies.push(new Enemy());
}
}
public function getEnemy():Enemy
{
return enemies.pop();
}
public function returnEnemy(enemy:Enemy):void
{
enemies.push(enemy)
}
}
}
2
3
Object Pool Pattern
1
import foo.EnemyPool;
var pool:EnemyPool = new EnemyPool(20);
var enemy:Enemy = pool.getEnemy();
//when we don't need this enemy anymore
pool.returnEnemy(enemy);
2
3
Object Pool Pattern
1
Strategy Pattern
● Defines a group of algorithms ready to use
● Allows to change algorithms on runtme
● Helps in proper encapsulaton
Strategy Pattern
package foo
{
public class Enemy
{
private var moveStrategy:IMoveStrategy;
public function Enemy(movingStrategy:IMoveStrategy)
{
this.moveStrategy = moveStrategy
}
public function update():void
{
moveStrategy.execute(this);
}
}
}
1
Strategy Pattern
3
2
var enemy:Enemy = new Enemy(new FastMoveStrategy());
enemy.move();
1
Strategy Pattern
Command Pattern
● Encapsulates all data needed to method invocaton later on
● Single Responsibility Principle
● Fire and Forget
● Commonly used for mult-level undo
Command Pattern
package foo
{
public class CreateEnemyCommand implements ICommand
{
public function execute():void
{
//add enemy & play sound here
}
}
}
1
Command Pattern
import foo.CreateNewEnemyCommand;
var command:ICommand = new CreateEnemyCommand();
command.execute();1
Command Pattern
Jet&Giant
git clone git://github.com/krzysztof-o/epi-
wdpg.git
Jet&Giant
Task 1
Game model:
● Create GameModel singleton class responsible for
storing game data:
● Enemies and bullets
● Game object reference
● Giant object reference
enemies bullets game
lives
giant
Task 2
Bullet Pool:
● Create pool of 50 bullets using Object Pool Pattern
BulletPool
Task 3
Enemies' movement:
● Create strategies FastMoveStrategy and SineWaveMoveStrategy
responsible for moving enemies
enemy_1 enemy_2
Task 4
Explosion animaton:
● Create command PlayBoomCommand
● Invoke command with dispatched Event

More Related Content

PDF
Profile all the things! - Capital Go 2017
PDF
Game Programming Pattern by Restya
PPT
Design Patterns Java
PPT
Lesson12 other behavioural patterns
PDF
Java design patterns
PDF
Design patterns in javascript
PPT
10-design-patterns1.ppt.software engineering
PDF
Design patterns - Common Solutions to Common Problems - Brad Wood
Profile all the things! - Capital Go 2017
Game Programming Pattern by Restya
Design Patterns Java
Lesson12 other behavioural patterns
Java design patterns
Design patterns in javascript
10-design-patterns1.ppt.software engineering
Design patterns - Common Solutions to Common Problems - Brad Wood

Similar to An Introduction to Game Programming with Flash: Design Patterns (20)

PDF
Gradle For Beginners (Serbian Developer Conference 2013 english)
PDF
cf.Objective() 2017 - Design patterns - Brad Wood
PDF
Java Presentation For Syntax
PPT
Generic Synchronization Policies in C++
PDF
Advanced Dagger talk from 360andev
PDF
20120308 droid4me-paug presentation
PPTX
Evolution of Patterns
PDF
Design patterns
PPT
N Unit Presentation
PDF
Design patterns in java script, jquery, angularjs
PPT
Introduction to design_patterns
PDF
Design patterns in Java - Monitis 2017
PDF
Drools & jBPM Workshop London 2013
PPT
Design_Patterns_Dr.CM.ppt
PDF
Twins: OOP and FP
PDF
quelques-patterns- patrons de conception
PDF
PPTX
Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023
PDF
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
PPTX
6-Fragments_081836.pptx
Gradle For Beginners (Serbian Developer Conference 2013 english)
cf.Objective() 2017 - Design patterns - Brad Wood
Java Presentation For Syntax
Generic Synchronization Policies in C++
Advanced Dagger talk from 360andev
20120308 droid4me-paug presentation
Evolution of Patterns
Design patterns
N Unit Presentation
Design patterns in java script, jquery, angularjs
Introduction to design_patterns
Design patterns in Java - Monitis 2017
Drools & jBPM Workshop London 2013
Design_Patterns_Dr.CM.ppt
Twins: OOP and FP
quelques-patterns- patrons de conception
Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
6-Fragments_081836.pptx
Ad

Recently uploaded (20)

PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Encapsulation theory and applications.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Cloud computing and distributed systems.
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Spectroscopy.pptx food analysis technology
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
cuic standard and advanced reporting.pdf
PDF
Approach and Philosophy of On baking technology
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Unlocking AI with Model Context Protocol (MCP)
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Encapsulation theory and applications.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Cloud computing and distributed systems.
20250228 LYD VKU AI Blended-Learning.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Network Security Unit 5.pdf for BCA BBA.
Spectroscopy.pptx food analysis technology
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Encapsulation_ Review paper, used for researhc scholars
cuic standard and advanced reporting.pdf
Approach and Philosophy of On baking technology
MIND Revenue Release Quarter 2 2025 Press Release
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Ad

An Introduction to Game Programming with Flash: Design Patterns