ballwar.model.strategy
Class MoveStrategy
java.lang.Object
ballwar.model.strategy.ANoOpStrategy
ballwar.model.strategy.MoveStrategy
- All Implemented Interfaces:
- IUpdateStrategy
public class MoveStrategy
- extends ANoOpStrategy
An ANoOpStrategy-based strategy that modifies the velocity of the context ball through user key presses.
Field Summary |
private int |
_delta
The amount the ball's velocity is changed in the requested
direction each time a key press is registered. |
Method Summary |
void |
init(Ball context)
Initializes the context such that the movement keys of the currently selected
player are registered with the environment. |
void |
updateState(Ball context)
If the increment value (delta) is greater than 1, decrement the increment value. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
_delta
private int _delta
- The amount the ball's velocity is changed in the requested
direction each time a key press is registered.
MoveStrategy
public MoveStrategy()
updateState
public void updateState(Ball context)
- If the increment value (delta) is greater than 1, decrement the increment value.
This will slowly return the sensitivity of the keyboard control back to its beginning value (1).
- Specified by:
updateState
in interface IUpdateStrategy
- Overrides:
updateState
in class ANoOpStrategy
- Parameters:
context
- This strategy's context.
init
public void init(Ball context)
- Initializes the context such that the movement keys of the currently selected
player are registered with the environment. The movement keys will increment
the velocity in the appropriate direction by the set amount (delta) when the respective
key is pressed. The stop key will cause the velocity to become zero. Every time
a key is pressed, the velocity increment is incremented. This causes the keys to
appear to become more sensitivee the longer and more often the keys are pressed.
- Specified by:
init
in interface IUpdateStrategy
- Overrides:
init
in class ANoOpStrategy
- Parameters:
context
- This strategy's context.