Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sd3cw1;
- public interface Strategy {
- boolean CheckSpace(int SpaceNum);
- }
- package sd3cw1;
- public class PassiveStrategy implements Strategy {
- import sd3cw1.Strategy;
- @Override
- public boolean CheckSpace(int SpaceNum) {
- //insert code for passive encounters
- }
- }
- package sd3cw1;
- import sd3cw1.Strategy;
- public class AggressiveStrategy implements Strategy {
- @Override
- public boolean CheckSpace(int SpaceNum) {
- //insert code for aggressive encounters
- }
- }
- }
- package sd3cw1;
- import sd3cw1.Strategy;
- public class Context {
- int SpaceNum;
- Strategy strategy;
- public Context(int SpaceNum, Strategy strategy) {
- this.SpaceNum = SpaceNum;
- this.strategy = strategy;
- }
- public void setStrategy(Strategy strategy) {
- this.strategy = strategy;
- }
- public int getSpaceNum() {
- return SpaceNum;
- }
- public boolean getResult() {
- return strategy.CheckSpace(SpaceNum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement