thufir

ActionGenerator cannot get actions from Flag Enum

Sep 11th, 2013
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 KB | None | 0 0
  1. package telnet.player;
  2.  
  3. import java.util.ArrayDeque;
  4. import java.util.Deque;
  5. import java.util.Map.Entry;
  6. import java.util.logging.Logger;
  7.  
  8. public class ActionGenerator {
  9.  
  10.     private final static Logger log = Logger.getLogger(PLayerController.class.getName());
  11.  
  12.     public ActionGenerator() {
  13.     }
  14.  
  15.  
  16.     public Deque<Action> generateActions() {
  17.         log.fine("trying actions...");
  18.         Deque<Action> actions = new ArrayDeque<>();
  19.         for (Entry<Flag, Boolean> entry : Player.INSTANCE.getFlags().entrySet()) {
  20.             if (entry.getValue()) {
  21.                 //if this flag is true, then get the actions
  22.                 //from Flag.getActionsForState sending the entry key
  23.                 //and add to actions Deque.
  24.                
  25.                 //example:
  26.                
  27.                 actions.add(Action.DRAW);   //   **get** the specific action **from** Flag enum
  28.                 actions.add(Action.PROCESS);
  29.                
  30.                 //add those actions when the entry key is Flag.CORPSE and
  31.                 //the entry val is true
  32.                
  33.                
  34.                 //the actions, themselves, actually come *from* the Flag
  35.                 //enum through the getActionsForState the
  36.                 //constant-specific method implementations
  37.                 //from item 30 in effective java, 2nd edition
  38.                 //strategy enum pattern, I believe.
  39.             }
  40.         }
  41.         return actions;
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment