ballwar.model.strategy
Class Change1Strategy
java.lang.Object
ballwar.model.strategy.AUpdateStrategy
ballwar.model.strategy.Change1Strategy
- All Implemented Interfaces:
- IUpdateStrategy
public class Change1Strategy
- extends AUpdateStrategy
A strategy that demonstrates self-modifying behavior by replacing itself with another strategy after a certain length of time.
Based on AUpdateStrategy, so it randomly initializes the ball.
Field Summary |
private int |
i
The counter that deternines the number of updates before this strategy replaces itself in its context. |
Method Summary |
void |
updateState(Ball context)
If the counter is zero, sets the context's strategy to a new Change2Strategy. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
i
private int i
- The counter that deternines the number of updates before this strategy replaces itself in its context.
Change1Strategy
public Change1Strategy()
updateState
public void updateState(Ball context)
- If the counter is zero, sets the context's strategy to a new Change2Strategy.
Otherwise, decrements the counter.
- Specified by:
updateState
in interface IUpdateStrategy
- Specified by:
updateState
in class AUpdateStrategy
- Parameters:
context
- The strategy's context.