示例#1
0
  public void checkBetWeenTwoMarkers() {
    if (alive) // check if the object alive
    {
      DeepSpace myDeepSpace = (DeepSpace) getWorld(); // get referance to the DeepSpace Class

      if (getX() == 799
          && getY() > myDeepSpace.getExitMarkerTop()
          && myDeepSpace.getExitMarkerBottom()
              > getY()) // check that if we are right side of the world and between two markers than
                        // do following
      {
        setImage("balloon2.png"); // set the baloon image
        baloonCount--; // start counting. we do these because it simulates the baloon picture for
                       // little time for the user.

        if (baloonCount
            < 1) // if little time passed over than remove the object from the world and call the
                 // greenfooot stop method.
        {
          getWorld().removeObject(this);
          return;
          // Greenfoot.stop();
        }
      }

      if ((getX() == 799 && 0 < getY() && getY() < myDeepSpace.getExitMarkerTop())
          || (getX() == 799 && 600 > getY() && getY() > myDeepSpace.getExitMarkerBottom()))
      // if the ship between top of the right corner and top marker than do fallowing  OR if the
      // ship between bottom of the right corner and bottom marker than do fallowing
      {
        setImage(
            "explosion.gif"); // set the image as Explosion in order to simulate explosion for the
                              // user.
        baloonCount--; // increase the baloonCount variable in order to slowly remove the object
                       // from the world

        if (baloonCount < 1) // if little time has passed than remove the obejct.
        {

          getWorld().removeObject(this);
          return; // leave the function.
          // Greenfoot.stop();
        }
      }
    }
  }