Session #6Muhamad Hesham
Day in Programmer`s Life
Agenda
State vs Strategy Day in Programmer Life GOF visit Project Description
Pattern’s Challenge Are they Twin patterns?
What are the differences between State and Strategy Pattern?
Our Target Game
Learning through Game Programming
Why Game Programming ?
2. Resource intensive software
3. Interactions till death
1.Fun & Interesting
4. Coding non-stopOOD & Design patterns in action
Our Target Game Platformer Skeleton
Main Actors • Level• Player• Enemy• Gem
Call for new requirement
Once the player collects a gem I want: Enemy increases its speed. Other gems change its color
to a random color.
First try for implementation
1. We need find the place in code where the gem is tested for being collected.
2. We need modify enemy speed.
3. We need modify gem color.
1. We expose private members to the public.
2. We are dependant on certain members.
3. Each time we need modify the level code.
Without correct pattern Our code smells bad!
Call for new requirement
Once the player die I want: Enemies speed is reset. Other gems change its color
to black.
Call for new requirement
Each level can be in one of two styles: Pharonic Aztec
First level is Aztec. Second and third levels are
Pharonic.
First try for implementation
1. We need find where we decide which image we load.
2. Categorize images to 2 sets, Pharonic an Aztec.
Each time we add a new theme
we add piles of if-else statements.
Our class do more than its job
(SCSR).
Without correct pattern Our code smells bad!
Call for new requirement
My nephew has another opinion First level is Pharonic. Second level is Aztec Third level is random.
Call for new requirement
I want the enemy turn crazy when you collect a gem.
If you touch the enemy while it is crazy, you die and it turns idle again.
Increase crazy enemy speed by 4 times.
First try for implementation
What do you think we need do this time ?
Violates Open Closed Principle.
Further additions will cause bugs.
State transitions are buried between if-else.
Without correct pattern Our code smells bad!
Original Enemy State Machine
Running Idle
reach cliff
after a while
Updated Enemy State Machine
Running Idle
reach cliff
after a while
Crazy
gem collectedgem
collected
player died
Call for new requirement
I want …
Go to HELL !!!
GOF Visit: Authors
GOF Visit: Organization
Let`s ask the
authors
It is Project Time!
Thank you ...