ballwar.model.strategy
Class Change2Strategy
java.lang.Object
ballwar.model.strategy.AUpdateStrategy
ballwar.model.strategy.Change2Strategy
- All Implemented Interfaces:
- IUpdateStrategy
public class Change2Strategy
- extends AUpdateStrategy
Similar self-modifying behavior to Change1Strategy. After a period of time, replaces itself with a new Change1Strategy.
Randomly changes its color when updateState is called.
Based on AUpdateStrategy, so it randomly initializes the ball.
Field Summary |
private int |
i
Counter that determines the number of updates before this strategy replaces itself. |
private IRandomizer |
rand
Randomizer to generate random colors |
Method Summary |
void |
updateState(Ball context)
Sets the context's color to a random color. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
rand
private IRandomizer rand
- Randomizer to generate random colors
i
private int i
- Counter that determines the number of updates before this strategy replaces itself.
Change2Strategy
public Change2Strategy()
updateState
public void updateState(Ball context)
- Sets the context's color to a random color.
If the count is zero, sets the context's strategy to a new Change1Strategy.
otherwise, decrements the counter.
- Specified by:
updateState
in interface IUpdateStrategy
- Specified by:
updateState
in class AUpdateStrategy
- Parameters:
context
- The strategy's context.