コード例 #1
0
ファイル: Bear.java プロジェクト: Wekker/Vossen-en-Konijnen
  /**
   * Look for foxes and wolfs adjacent to the current location. Only the first live foxes or wolf is
   * eaten.
   *
   * @return Where food was found, or null if it wasn't.
   */
  private Location findFood() {
    Field field = getField();
    List<Location> adjacent = field.adjacentLocations(getLocation());
    Iterator<Location> it = adjacent.iterator();
    while (it.hasNext()) {
      Location where = it.next();
      Object animal = field.getObjectAt(where);
      if (animal instanceof Wolf) {
        Wolf wolf = (Wolf) animal;
        if (wolf.isAlive()) {
          wolf.setDead();
          setFoodLevel(WOLFS_FOOD_VALUE);
          return where;
        }
      } else if (animal instanceof Fox) {
        Fox fox = (Fox) animal;
        if (fox.isAlive()) {
          fox.setDead();
          setFoodLevel(FOX_FOOD_VALUE);
          return where;
        }

      } else if (animal instanceof Rabbit) {
        Rabbit rabbit = (Rabbit) animal;
        if (rabbit.isAlive()) {
          rabbit.setDead();
          setFoodLevel(RABBIT_FOOD_VALUE);
          return where;
        }
      }
    }
    return null;
  }
コード例 #2
0
 public Animal getElement(int index) {
   Animal ani = animals.get(index);
   switch (ani.getSort()) {
     case DEER:
       Deer deer = (Deer) ani;
       return (Deer) deer.clone();
     case DOG:
       Dog dog = (Dog) ani;
       return (Dog) dog.clone();
     case GIFRAFFE:
       Gifraffe gifraffe = (Gifraffe) ani;
       return (Gifraffe) gifraffe.clone();
     case HORSE:
       Horse horse = (Horse) ani;
       return (Horse) horse.clone();
     case LION:
       Lion lion = (Lion) ani;
       return (Lion) lion.clone();
     case WOLF:
       Wolf wolf = (Wolf) ani;
       return (Wolf) wolf.clone();
     case CHEETAH:
       Cheetah cheetah = (Cheetah) ani;
       return (Cheetah) cheetah.clone();
     default:
       // Don't know that type of creature.
       return (Animal) ani.clone();
   }
 }
コード例 #3
0
ファイル: AlterSpell.java プロジェクト: S-Toad/MagicPlugin
  protected SpellResult alterEntity(Entity entity) {
    EntityType entityType = entity.getType();
    switch (entityType) {
      case PAINTING:
        registerModified(entity);
        Painting painting = (Painting) entity;
        Art[] artValues = Art.values();
        Art oldArt = painting.getArt();
        Art newArt = oldArt;
        int ordinal = (oldArt.ordinal() + 1);
        for (int i = 0; i < artValues.length; i++) {
          newArt = artValues[ordinal++ % artValues.length];
          painting.setArt(newArt);
          newArt = painting.getArt();
          if (oldArt != newArt) {
            break;
          }
        }
        if (oldArt == newArt) {
          return SpellResult.FAIL;
        }
        mage.sendDebugMessage("Altering art from " + oldArt + " to " + newArt);
        break;
      case ITEM_FRAME:
        ItemFrame itemFrame = (ItemFrame) entity;
        ItemStack frameItem = itemFrame.getItem();
        if (frameItem == null || frameItem.getType() != Material.MAP) {
          return SpellResult.NO_TARGET;
        }
        short data = frameItem.getDurability();
        data++;
        MapView mapView = DeprecatedUtils.getMap(data);
        if (mapView == null) {
          data = 0;
          mapView = DeprecatedUtils.getMap(data);
          if (mapView == null) {
            return SpellResult.NO_TARGET;
          }
        }
        registerModified(entity);
        frameItem.setDurability(data);
        itemFrame.setItem(frameItem);
        break;
      case HORSE:
        registerModified(entity);
        Horse horse = (Horse) entity;

        Color color = horse.getColor();
        Color[] colorValues = Color.values();
        color = colorValues[(color.ordinal() + 1) % colorValues.length];

        Variant variant = horse.getVariant();
        Variant[] variantValues = Variant.values();
        variant = variantValues[(variant.ordinal() + 1) % variantValues.length];

        Style horseStyle = horse.getStyle();
        Style[] styleValues = Style.values();
        horseStyle = styleValues[(horseStyle.ordinal() + 1) % styleValues.length];

        horse.setStyle(horseStyle);
        horse.setColor(color);
        horse.setVariant(variant);
        break;
      case OCELOT:
        registerModified(entity);
        Ocelot ocelot = (Ocelot) entity;
        Type catType = ocelot.getCatType();
        Type[] typeValues = Type.values();
        catType = typeValues[(catType.ordinal() + 1) % typeValues.length];
        ocelot.setCatType(catType);
        break;
      case VILLAGER:
        registerModified(entity);
        Villager villager = (Villager) entity;
        Profession profession = villager.getProfession();
        Profession[] professionValues = Profession.values();
        profession = professionValues[(profession.ordinal() + 1) % professionValues.length];
        villager.setProfession(profession);
        break;
      case WOLF:
        registerModified(entity);
        Wolf wolf = (Wolf) entity;
        DyeColor wolfColor = wolf.getCollarColor();
        DyeColor[] wolfColorValues = DyeColor.values();
        wolfColor = wolfColorValues[(wolfColor.ordinal() + 1) % wolfColorValues.length];
        wolf.setCollarColor(wolfColor);
        break;
      case SHEEP:
        registerModified(entity);
        Sheep sheep = (Sheep) entity;
        DyeColor dyeColor = sheep.getColor();
        DyeColor[] dyeColorValues = DyeColor.values();
        dyeColor = dyeColorValues[(dyeColor.ordinal() + 1) % dyeColorValues.length];
        sheep.setColor(dyeColor);
        break;
      case SKELETON:
        registerModified(entity);
        Skeleton skeleton = (Skeleton) entity;
        SkeletonType skeletonType = skeleton.getSkeletonType();
        SkeletonType[] skeletonTypeValues = SkeletonType.values();
        skeletonType = skeletonTypeValues[(skeletonType.ordinal() + 1) % skeletonTypeValues.length];
        skeleton.setSkeletonType(skeletonType);
        break;
      default:
        return SpellResult.NO_TARGET;
    }
    ;
    registerForUndo();
    return SpellResult.CAST;
  }