Example #1
0
 public void setString(String input) {
   searchindex = 0;
   scanner.setString(input);
   tokens = scanner.getTokens();
   history.addElement(tokens);
   interpretCommand();
   Runnable a = interpretCommand();
   a.run();
   listeners.notifyAllListeners(
       new PropertyChangeEvent(this, "history", getHistory(), getHistory()));
   listeners.notifyAllListeners(new PropertyChangeEvent(this, "tokens", getTokens(), getTokens()));
 }
Example #2
0
 public Command parseMove() {
   int x = 0, y = 0;
   Avatar avatar = null;
   if (getTokens()[1] instanceof Word) {
     avatar = (Avatar) avatars.get(getTokens()[1].getToken().toLowerCase());
     if (4 < getTokens().length - 1) {
       if (!(getTokens()[2] instanceof Number)) {
         if ((getTokens()[4] instanceof Number)) {
           x = ((Number) getTokens()[3]).getNumber();
           if (getTokens()[2] instanceof Minus) x = -x;
           y = ((Number) getTokens()[4]).getNumber();
         } else {
           x = ((Number) getTokens()[3]).getNumber();
           if (getTokens()[2] instanceof Minus) x = -x;
           y = ((Number) getTokens()[5]).getNumber();
           if (getTokens()[4] instanceof Minus) y = -y;
         }
       } else if (!(getTokens()[3] instanceof Number)) {
         x = ((Number) getTokens()[2]).getNumber();
         y = ((Number) getTokens()[4]).getNumber();
         if (getTokens()[3] instanceof Minus) y = -y;
       }
     } else {
       if (getTokens()[2] instanceof Number && getTokens()[3] instanceof Number) {
         x = ((Number) getTokens()[2]).getNumber();
         y = ((Number) getTokens()[3]).getNumber();
       } else {
         if (!(getTokens()[2] instanceof Number) && !(getTokens()[3] instanceof Number)) {
           System.out.println(
               "ERROR! 3rd and 4th arguments in command MOVE should be integers. You provided type "
                   + getTokens()[2].getClass().getName().substring(9)
                   + " and "
                   + getTokens()[3].getClass().getName().substring(9)
                   + ".");
         } else if (!(getTokens()[2] instanceof Number)) {
           System.out.println(
               "ERROR! 3rd argument in command MOVE should be an integer. You provided type "
                   + getTokens()[2].getClass().getName().substring(9)
                   + ".");
         } else if (!(getTokens()[3] instanceof Number)) {
           System.out.println(
               "ERROR! 4th argument in command MOVE should be an integer. You provided type "
                   + getTokens()[3].getClass().getName().substring(9)
                   + ".");
         }
       }
     }
     listeners.notifyAllListeners(
         new PropertyChangeEvent(this, "tokens", getTokens(), getTokens()));
   } else {
     System.out.println(
         "ERROR! 2nd argument in command MOVE should be a Word. You provided type "
             + getTokens()[1].getClass().getName().substring(10)
             + ".");
   }
   return new ACommandObjectMove(avatar, x, y, canvas);
 }
Example #3
0
 @ObserverRegisterer(ObserverTypes.PROPERTY_LISTENER)
 public void addPropertyChangeListener(PropertyChangeListener listener) {
   listeners.add(listener);
   listener.propertyChange(new PropertyChangeEvent(this, "history", 0, getHistory()));
   listener.propertyChange(new PropertyChangeEvent(this, "tokens", 0, getTokens()));
 }