Esempio n. 1
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);
 }
Esempio n. 2
0
 public Command parseSay() {
   Avatar avatar = null;
   if (getTokens()[1] instanceof Word) {
     if (getTokens()[2] instanceof Quote) {
       avatar = (Avatar) avatars.get(getTokens()[++searchindex].getToken().toLowerCase());
     } else {
       System.out.println(
           "ERROR! 3rd argument in command SAY should be a Quote. You provided type "
               + getTokens()[2].getClass().getName().substring(9)
               + ".");
     }
   } else {
     System.out.println(
         "ERROR! 2nd argument in command SAY should be a Word. You provided type "
             + getTokens()[1].getClass().getName().substring(9)
             + ".");
   }
   return new ACommandObjectSay(avatar, getTokens()[++searchindex].getToken(), canvas);
 }