The Strategy Pattern - Changing Behavior
The Strategy Pattern is used to change behavior. In this example, you change the behavior the weapon by swapping in and out weapons (and the projectiles they fire).
When looking through the code, focus on the weapons (Gun, MissleLauncher, and DartBlower) and the “fire()” function in “ShooterBasicView.as”. You’ll notice that ShooterBasicView only cares that the weapon is an “IFireable and then it’s just going to fire it.
The weapons are swapped in the document class, “ShooterMain” in the Keyboard handler.
*If you’d like to challenge yourself, try adding a fourth weapon that uses Planes as ammo.
3 Comments to The Strategy Pattern - Changing Behavior
clike which key to fire?
December 2, 2008
Keyboard.SPACE!
Great job spreading the design patterns and the benefits of it use on real life situations!
Nice example!
Leave a comment
Search
Subscribe
Recent Posts
- AS3DMod Twist
- Looking around the inside of a Sphere
- Tweening the Camera and Tweening lookAt()
- Cube Inside Faces and Outside Faces
- Happy New Year!
- Slerp Explorer
- Quaternion Explorer
- Click then Tween Camera to Plane
- Switching a MovieMaterial on the face of a Cube - replaceMaterialByName
- Merry Christmas!
- Flint Pixels 2 - Random Drift and Rotate Emitter
- Papervision3D with Box2DFlash Part 4 - Distance Joint
- Flint Pixels
- Papervision3D with AS3Dmod Hello World Example
- .swc and .zip updated to revision 851

December 2, 2008