public static void display(Iterator<Pet> it) {
   while (it.hasNext()) {
     Pet p = it.next();
     System.out.print(p.id() + ":" + p + " ");
   }
   System.out.println();
 }
예제 #2
0
 private void resetPetsPosition() {
   Pet child;
   for (int i = 0; i < mChildren.size(); i++) {
     float x = getXByIndex(i);
     child = (Pet) mChildren.get(i);
     child.setPosition(x, -5f);
   }
 }
 @Override
 public Pet load(String name) {
   for (Pet p : list()) {
     if (p.getName().equalsIgnoreCase(name)) {
       return p;
     }
   }
   return null;
 }
예제 #4
0
 public void seePatient() {
   try {
     Appointment<Pet> appointment = this.appointments.take();
     Pet patient = appointment.getPatient();
     patient.examine();
   } catch (InterruptedException e) {
     shutdown = true;
   }
 }
예제 #5
0
파일: PetCount3.java 프로젝트: jnjeG/tjava
 public static void main(String[] args) {
   PetCounter petCount = new PetCounter();
   for (Pet pet : Pets.createArray(20)) {
     printnb(pet.getClass().getSimpleName() + " ");
     petCount.count(pet);
   }
   print();
   print(petCount);
 }
예제 #6
0
 public void testHasPet() {
   Owner owner = new Owner();
   Pet fido = new Pet();
   fido.setName("Fido");
   assertNull(owner.getPet("Fido"));
   assertNull(owner.getPet("fido"));
   owner.addPet(fido);
   assertEquals(fido, owner.getPet("Fido"));
   assertEquals(fido, owner.getPet("fido"));
 }
예제 #7
0
 /**
  * Precondition: startIndex is a valid index of the ArrayList petList. Returns the index of the
  * pet whose name comes first in alphabetic order.
  */
 private static int getIndex(int startIndex, ArrayList<Pet> petList) {
   Pet start = petList.get(startIndex);
   int comeBefore = startIndex;
   for (int i = startIndex + 1; i < petList.size(); i++) {
     if (petList.get(i).getName().compareTo(start.getName()) < 0) {
       start = petList.get(i);
       comeBefore = i;
     }
   }
   return comeBefore;
 }
예제 #8
0
 /**
  * печать всех животных по имени клиента
  *
  * @param client имя клиента
  */
 public void printPetsByClient(final String client) {
   SimpleLinkedList<Pet> foundedPets = findPetsByClient(client);
   int j = 0;
   for (Pet pet : foundedPets) {
     if (pet != null) {
       System.out.println(pet.getName() + "   " + pet.getClass().getSimpleName());
       j = j + 1;
     }
   }
   if (j == 0) {
     System.out.println("Client with that pet's name didn't find");
   }
 }
예제 #9
0
 @Override
 public void run() {
   for (Pet cosmetic : this.module.getParent().getApi().getAllCosmetics(Pet.class)) {
     Creature entity = cosmetic.getEntity();
     Player p = cosmetic.getPlayer();
     if (!entity.getWorld().getName().equalsIgnoreCase(p.getWorld().getName())
         || entity.getLocation().distance(p.getLocation())
             >= this.module.getConfig().getTeleportDistance()) {
       entity.teleport(p);
       entity.setTarget(p);
     }
   }
 }
예제 #10
0
 /**
  * Return the Pet with the given name, or null if none found for this Owner.
  *
  * @param name to test
  * @return true if pet name is already in use
  */
 public Pet getPet(String name, boolean ignoreNew) {
   name = name.toLowerCase();
   for (Pet pet : getPetsInternal()) {
     if (!ignoreNew || !pet.isNew()) {
       String compName = pet.getName();
       compName = compName.toLowerCase();
       if (compName.equals(name)) {
         return pet;
       }
     }
   }
   return null;
 }
예제 #11
0
 /**
  * Return the Pet with the given name, or null if none found for this Owner.
  *
  * @param name to test
  * @return true if pet name is already in use
  */
 public Pet getPet(String name, boolean ignoreNew) {
   name = name.toLowerCase();
   for (Iterator it = getPetsInternal().iterator(); it.hasNext(); ) {
     Pet pet = (Pet) it.next();
     if (!ignoreNew || !pet.isNew()) {
       String compName = pet.getName();
       compName = compName.toLowerCase();
       if (compName.equals(name)) {
         return pet;
       }
     }
   }
   return null;
 }
예제 #12
0
 public boolean onLongPressEvent(PointF point, MotionEvent event) {
   int id = pointerAt(point.x, point.y);
   /* The first one is elf, ignore it */
   for (int i = 1; i < mChildren.size(); i++) {
     Pet child = (Pet) mChildren.get(i);
     if (id == child.getId()) {
       Pet pet = removePet(i);
       Poster poster = pet.getPoster();
       pet.clear();
       ViewManager.getInstance().editPoster(poster);
       return true;
     }
   }
   return false;
 }
예제 #13
0
 @Override
 public boolean equals(Object obj) {
   if (this == obj) return true;
   if (obj == null) return false;
   if (getClass() != obj.getClass()) return false;
   Person other = (Person) obj;
   if (age != other.age) return false;
   if (cal == null) {
     if (other.cal != null) return false;
   } else if (!cal.equals(other.cal)) return false;
   if (map == null) {
     if (other.map != null) return false;
   } else if (!map.equals(other.map)) return false;
   if (name == null) {
     if (other.name != null) return false;
   } else if (!name.equals(other.name)) return false;
   if (nullTest == null) {
     if (other.nullTest != null) return false;
   } else if (!nullTest.equals(other.nullTest)) return false;
   if (pet == null) {
     if (other.pet != null) return false;
   } else if (!pet.equals(other.pet)) return false;
   if (someDate == null) {
     if (other.someDate != null) return false;
   } else if (!someDate.equals(other.someDate)) return false;
   return true;
 }
예제 #14
0
  private Object getData() {
    Pet pet = new Pet();
    pet.setName("rover");
    pet.setAge(7);
    List list = new ArrayList();
    list.add("a");
    list.add(12);
    list.add(
        new SomeNumers(
            10.02f,
            22.02,
            5,
            100l,
            new BigDecimal(23.0234d, MathContext.DECIMAL128),
            new BigInteger("1001")));
    list.add(new Date());
    // list.add( 'b' ); // generates ok but breaks round trip equals
    list.add(new Cheese("cheddar", 6));

    pet.setList(list);
    pet.setArray(new int[] {1, 2, 3});

    Map map = new HashMap();
    // map.put( new Date(), new Cheese( "stilton", 11) ); // TODO why doesn't this work
    map.put("key1", 13);
    map.put("key3", "value3");
    map.put("key2", 15);
    map.put("key4", new Cheese("stilton", 11));
    Calendar cal = Calendar.getInstance();
    //        cal.setTime( new Date() );
    //        map.put( "key5",
    //                 cal ); // TODO why doesn't this work.
    // map.put( "key4", new String[] { "a", "b" } ); // TODO why doesn't this work

    Person person = new Person();
    person.setName("mark");
    person.setAge(33);
    person.setPet(pet);
    person.setSomeDate(new Date());
    person.setMap(map);
    cal = Calendar.getInstance();
    cal.setTime(new Date());
    person.setCal(cal);

    return person;
  }
예제 #15
0
 public EntityPet(World world, Pet pet) {
   super(world);
   try {
     pet.setCraftPet(new CraftPet(world.getServer(), this));
     // pet.setCraftPet(pet.getPetType().getNewCraftInstance(this));
     // setPet(pet);
     this.pet = pet;
     ((LivingEntity) this.getBukkitEntity()).setMaxHealth(pet.getPetType().getMaxHealth());
     this.setHealth(pet.getPetType().getMaxHealth());
     this.jumpHeight =
         EchoPet.getPluginInstance().DO.getRideJumpHeight(this.getPet().getPetType());
     this.rideSpeed = EchoPet.getPluginInstance().DO.getRideSpeed(this.getPet().getPetType());
     this.jump = EntityLiving.class.getDeclaredField("bd");
     this.jump.setAccessible(true);
     setPathfinding();
   } catch (Exception e) {
     EchoPet.getPluginInstance().severe(e, "Error creating new pet entity.");
     this.remove();
   }
 }
예제 #16
0
 public void getPet() {
   Session session = HibernateUtils.getSessionFactory().getCurrentSession();
   Transaction tx = null;
   try {
     tx = session.beginTransaction();
     // Cat cat = (Cat) session.get(Cat.class, 1);
     // System.out.println(cat.getCatProperty());
     /**
      * 当使用pet来查找的时候, 虽然一个id肯定只能时对应于一个cat, 或者时一个dog但是它此时会连接所以 的pet dog cat表进行查找,
      * 因为此时它并不知道为1的pet到底是一个dog还是一个cat, 所以它会全部 都查找出来, 再根据结果来创建dog或者是cat。如果此时什么也不是, 那么此时的对象为一个pet。
      */
     Pet pet = (Pet) session.get(Pet.class, 1);
     System.out.println(pet.getClass());
     tx.rollback();
   } catch (Exception e) {
     if (tx != null) {
       tx.rollback();
     }
     throw new RuntimeException(e);
   }
 }
예제 #17
0
  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    Pet pet = (Pet) o;

    if (getAge() != pet.getAge()) return false;
    if (getNick() != null ? !getNick().equals(pet.getNick()) : pet.getNick() != null) return false;
    if (getSex() != null ? !getSex().equals(pet.getSex()) : pet.getSex() != null) return false;
    return !(getPetClass() != null
        ? !getPetClass().equals(pet.getPetClass())
        : pet.getPetClass() != null);
  }
예제 #18
0
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + age;
   result = prime * result + ((cal == null) ? 0 : cal.hashCode());
   result = prime * result + ((map == null) ? 0 : map.hashCode());
   result = prime * result + ((name == null) ? 0 : name.hashCode());
   result = prime * result + ((nullTest == null) ? 0 : nullTest.hashCode());
   result = prime * result + ((pet == null) ? 0 : pet.hashCode());
   result = prime * result + ((someDate == null) ? 0 : someDate.hashCode());
   return result;
 }
예제 #19
0
 public PetCharacter(Pet self, String name, String type, Growth growth, int level) {
   super(name, 1);
   this.ownerType = self.owner().getType();
   this.self = self;
   this.type = type;
   this.setGrowth(growth);
   for (int i = 1; i < level; i++) {
     this.level += 1;
     getGrowth().levelUp(this);
   }
   distributePoints(Arrays.asList());
   if (self.owner().has(Trait.inspirational)) {
     for (Trait t : INSPIRABLE_TRAITS) {
       if (self.owner().has(t) && !has(t)) {
         add(t);
       }
     }
   }
   this.getSkills().clear();
   this.mojo.setMax(100);
   this.mojo.empty();
   this.arousal.empty();
   this.stamina.fill();
 }
예제 #20
0
  public static void main(String[] args) {
    Pet pet = new Cat();
    pet.setName("Я - пушистик");

    System.out.println(pet.getName());
  }
 @Override
 public String speak(Pet pet) {
   return pet.speak();
 }
  @Override
  public void create() {

    super.create();

    Music.INSTANCE.play(Assets.HAPPY, true);
    Music.INSTANCE.volume(ShatteredPixelDungeon.musicVol() / 10f);

    uiCamera.visible = false;

    int w = Camera.main.width;
    int h = Camera.main.height;

    Archs archs = new Archs();
    archs.reversed = true;
    archs.setSize(w, h);
    add(archs);

    float vx = align((w - SKY_WIDTH) / 2);
    float vy = align((h - SKY_HEIGHT - BUTTON_HEIGHT) / 2);

    Point s = Camera.main.cameraToScreen(vx, vy);
    viewport = new Camera(s.x, s.y, SKY_WIDTH, SKY_HEIGHT, defaultZoom);
    Camera.add(viewport);

    Group window = new Group();
    window.camera = viewport;
    add(window);

    boolean dayTime = Calendar.getInstance().get(Calendar.HOUR_OF_DAY) >= 7;

    Sky sky = new Sky(dayTime);
    sky.scale.set(SKY_WIDTH, SKY_HEIGHT);
    window.add(sky);

    if (!dayTime) {
      for (int i = 0; i < NSTARS; i++) {
        float size = Random.Float();
        ColorBlock star = new ColorBlock(size, size, 0xFFFFFFFF);
        star.x = Random.Float(SKY_WIDTH) - size / 2;
        star.y = Random.Float(SKY_HEIGHT) - size / 2;
        star.am = size * (1 - star.y / SKY_HEIGHT);
        window.add(star);
      }
    }

    float range = SKY_HEIGHT * 2 / 3;
    for (int i = 0; i < NCLOUDS; i++) {
      Cloud cloud =
          new Cloud((NCLOUDS - 1 - i) * (range / NCLOUDS) + Random.Float(range / NCLOUDS), dayTime);
      window.add(cloud);
    }

    int nPatches = (int) (sky.width() / GrassPatch.WIDTH + 1);

    for (int i = 0; i < nPatches * 4; i++) {
      GrassPatch patch =
          new GrassPatch((i - 0.75f) * GrassPatch.WIDTH / 4, SKY_HEIGHT + 1, dayTime);
      patch.brightness(dayTime ? 0.7f : 0.4f);
      window.add(patch);
    }

    Avatar a = new Avatar(Dungeon.hero.heroClass);
    // Removing semitransparent contour
    a.am = 2;
    a.aa = -1;
    a.x = PixelScene.align((SKY_WIDTH - a.width) / 2);
    a.y = SKY_HEIGHT - a.height;
    window.add(a);

    final Pet pet = new Pet();
    pet.rm = pet.gm = pet.bm = 1.2f;
    pet.x = SKY_WIDTH / 2 + 2;
    pet.y = SKY_HEIGHT - pet.height;
    window.add(pet);

    window.add(
        new TouchArea(sky) {
          protected void onClick(Touch touch) {
            pet.jump();
          };
        });

    for (int i = 0; i < nPatches; i++) {
      GrassPatch patch = new GrassPatch((i - 0.5f) * GrassPatch.WIDTH, SKY_HEIGHT, dayTime);
      patch.brightness(dayTime ? 1.0f : 0.8f);
      window.add(patch);
    }

    Image frame = new Image(Assets.SURFACE);

    frame.frame(0, 0, FRAME_WIDTH, FRAME_HEIGHT);
    frame.x = vx - FRAME_MARGIN_X;
    frame.y = vy - FRAME_MARGIN_TOP;
    add(frame);

    if (dayTime) {
      a.brightness(1.2f);
      pet.brightness(1.2f);
    } else {
      frame.hardlight(0xDDEEFF);
    }

    RedButton gameOver =
        new RedButton("Game Over") {
          protected void onClick() {
            Game.switchScene(TitleScene.class);
          }
        };
    gameOver.setSize(SKY_WIDTH - FRAME_MARGIN_X * 2, BUTTON_HEIGHT);
    gameOver.setPos(frame.x + FRAME_MARGIN_X * 2, frame.y + frame.height + 4);
    add(gameOver);

    Badges.validateHappyEnd();

    fadeIn();
  }
예제 #23
0
 public void addPet(Pet pet) {
   getPetsInternal().add(pet);
   pet.setOwner(this);
 }
예제 #24
0
 public static void display(Collection<Pet> pets) {
   for (Pet p : pets) System.out.print(p.id() + ":" + p + " ");
   System.out.println();
 }
예제 #25
0
 protected void setPetSize(Pet elf) {
   float ratio = PET_WIDTH / elf.getWidth();
   float finalWidth = PET_WIDTH;
   float finalHeight = ratio * elf.getHeight();
   elf.setSize(PET_WIDTH, PET_HEIGHT);
 }
예제 #26
0
 public Player getOwner() {
   return pet.getOwner();
 }
예제 #27
0
 public void addPet(Pet pet) {
   pets.add(pet);
   pet.setOwner(this);
 }
예제 #28
0
  public void act(Combat c, Character target) {
    List<Skill> allowedEnemySkills =
        new ArrayList<>(
            getSkills()
                .stream()
                .filter(
                    skill ->
                        Skill.skillIsUsable(c, skill, target)
                            && Collections.disjoint(skill.getTags(c), PET_UNUSABLE_TAG))
                .collect(Collectors.toList()));
    Skill.filterAllowedSkills(c, allowedEnemySkills, this, target);

    List<Skill> possibleMasterSkills = new ArrayList<>(getSkills());
    possibleMasterSkills.addAll(Combat.WORSHIP_SKILLS);
    List<Skill> allowedMasterSkills =
        new ArrayList<>(
            getSkills()
                .stream()
                .filter(
                    skill ->
                        Skill.skillIsUsable(c, skill, getSelf().owner)
                            && (skill.getTags(c).contains(SkillTag.helping)
                                || (getSelf().owner.has(Trait.showmanship)
                                    && skill.getTags(c).contains(SkillTag.worship)))
                            && Collections.disjoint(skill.getTags(c), PET_UNUSABLE_TAG))
                .collect(Collectors.toList()));
    Skill.filterAllowedSkills(c, allowedMasterSkills, this, getSelf().owner);
    WeightedSkill bestEnemySkill = Decider.prioritizePet(this, target, allowedEnemySkills, c);
    WeightedSkill bestMasterSkill =
        Decider.prioritizePet(this, getSelf().owner, allowedMasterSkills, c);

    if (Global.isDebugOn(DebugFlags.DEBUG_PET)) {
      System.out.println("Available Enemy Skills " + allowedEnemySkills);
      System.out.println("Available Master Skills " + allowedMasterSkills);
    }

    // don't let the ratings be negative.
    double masterSkillRating = Math.max(.001, bestMasterSkill.rating);
    double enemySkillRating = Math.max(.001, bestEnemySkill.rating);

    double roll = Global.randomdouble(masterSkillRating + enemySkillRating) - masterSkillRating;
    if (Global.isDebugOn(DebugFlags.DEBUG_PET)) {
      System.out.printf(
          "Rolled %s for master skill: %s [%.2f] and %s [%.2f]\n",
          roll,
          bestMasterSkill.skill.getLabel(c),
          -masterSkillRating,
          bestEnemySkill.skill.getLabel(c),
          enemySkillRating);
    }
    if (roll >= 0) {
      if (Global.isDebugOn(DebugFlags.DEBUG_PET)) {
        System.out.println("Using enemy skill " + bestEnemySkill.skill.getLabel(c));
      }
      Skill.resolve(bestEnemySkill.skill, c, target);
    } else {
      if (Global.isDebugOn(DebugFlags.DEBUG_PET)) {
        System.out.println("Using master skill " + bestMasterSkill.skill.getLabel(c));
      }
      Skill.resolve(bestMasterSkill.skill, c, self.owner());
    }
  }