Esempio n. 1
0
 /**
  * The method invoked by the mouse adapter on mouse clicked event. Delegates to the user to define
  * a new state of the world.
  *
  * @param mouse the location of the mouse when clicked
  * @return <code>{@link World World}</code> after the mouse event
  */
 protected World processMouseClicked(Posn mouse) {
   try {
     if (this.worldExists) {
       World bw = this.onMouseClicked(mouse);
       if (!this.lastWorld.worldEnds) return resetWorld(bw);
       else return this;
     } else return this;
   } catch (RuntimeException re) {
     re.printStackTrace();
     this.drawWorld("");
     // throw re;
     Runtime.getRuntime().halt(1);
   }
   return this;
 }
Esempio n. 2
0
  /**
   * The method invoked by the key adapter on selected key events. Delegates to the user to define a
   * new state of the world, then resets the canvas and event handlers for the new world to those
   * currently used.
   *
   * @return <code>{@link World World}</code> after the key event
   */
  protected synchronized World processKeyEvent(String ke) {
    try {
      if (this.worldExists) {
        World bw = this.onKeyEvent(ke);
        if (!this.lastWorld.worldEnds) return resetWorld(bw);
        else return this;
      } else return this;

    } catch (RuntimeException re) {
      re.printStackTrace();
      this.drawWorld("");
      // throw re;
      Runtime.getRuntime().halt(1);
    }
    return this;
  }
Esempio n. 3
0
 /**
  * The method invoked by the timer on each tick. Delegates to the user to define a new state of
  * the world, then resets the canvas and event handlers for the new world to those currently used.
  *
  * @return <code>{@link World World}</code> after the tick event
  */
 protected synchronized World processTick() {
   try {
     if (this.worldExists && !this.stopTimer) {
       this.lastWorld = this.worldEnds();
       if (this.lastWorld.worldEnds) {
         this.stopWorld();
       } else {
         World bw = this.onTick();
         return resetWorld(bw);
       }
     } else return this;
   } catch (RuntimeException re) {
     re.printStackTrace();
     this.drawWorld("");
     // throw re;
     Runtime.getRuntime().halt(1);
   }
   return this;
 }