Advertisement
Guest User

Routine super calss

a guest
Aug 18th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. package routines;
  2.  
  3. import game.GameBoard;
  4. import game.Player;
  5.  
  6. public abstract class Routine {
  7.     public enum RoutineState { Success, Failure, Running };
  8.    
  9.     protected RoutineState state;
  10.    
  11.     protected Routine() { }
  12.    
  13.     public abstract void act(Player player, GameBoard board);
  14.    
  15.     public abstract void reset();
  16.    
  17.     public void start() {
  18.         if(this.state == null)
  19.             this.state = RoutineState.Running;
  20.         else if(this.state != null) {
  21.             this.state = null;
  22.             this.state = RoutineState.Running;
  23.         }
  24.     }
  25.    
  26.     public void succeed() {
  27.         System.out.println(">>> Routine: " + this.getClass().getSimpleName() + " SUCCEEDED");
  28.         this.state = RoutineState.Success;
  29.     }
  30.    
  31.     public void fail() {
  32.         System.out.println(">>> Routine: " + this.getClass().getSimpleName() + " FAILED");
  33.         this.state = RoutineState.Failure;
  34.     }
  35.    
  36.     public boolean isSuccess() {
  37.         return state.equals(RoutineState.Success);
  38.     }
  39.    
  40.     public boolean isFailure() {
  41.         return state.equals(RoutineState.Failure);
  42.     }
  43.    
  44.     public boolean isRunning() {
  45.         return state.equals(RoutineState.Running);
  46.     }
  47.  
  48.     public RoutineState getState() {
  49.         return state;
  50.     }
  51.  
  52.     public void setState(RoutineState state) {
  53.         this.state = state;
  54.     }
  55.  
  56.     @Override
  57.     public String toString() {
  58.         return super.getClass().getSimpleName();
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement