Пример #1
0
 // Explicit implementation of readObject, but called implicitly as a result of recursive calls to
 // readObject() based on Serializable interface
 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
   name = new SimpleStringProperty((String) in.readObject());
   strength = new SimpleDoubleProperty(in.readDouble());
   health = new SimpleDoubleProperty(in.readDouble());
   speed = new SimpleDoubleProperty(in.readDouble());
   createAvatar();
   getAvatar().setTranslateX(in.readDouble());
   getAvatar().setTranslateY(in.readDouble());
   tooltip = new Tooltip(toString());
   Tooltip.install(getAvatar(), tooltip);
   resetAvatarAttributes();
 } // end readObject() to support serialization
Пример #2
0
 /**
  * <i>Actor</i> constructor is used when building <i>Actor</i> objects automatically:
  * <i>strength</i>, <i>health</i>, <i>speed</i> fields are given randomly generated values within
  * their range; <i>name</i> is given a sequentially numbered name: <i>Auto:<b>n</b></i> where
  * <i><b>n</b></i> is the sequence number. The <i>name</i> can be edited to create an unique
  * <i>Actor</i>.
  *
  * @param subclassCount used to support automatic naming (which includes a unique serial number).
  * @param armyAllegiance used to support the <i>Army</i>-specific <i>DropShadow</i> glow around
  *     this Actor object.
  */
 public Actor(int subclassCount, Army armyAllegiance) {
   this.armyAllegiance = armyAllegiance;
   ++actorSerialNumber; // static class-oriented variable. There is one-and-only-one instance of
                        // this variable regardless of the number of Actor objects in existence
                        // (from none to infinity).
   setName(
       String.format(
           "%d:%s:%d:",
           actorSerialNumber,
           getClass().getSimpleName(),
           subclassCount)); // An alternate way to assemble a String to use as a name. Because of
                            // polymorphism "getClass().getName()" will return the subclass name
                            // when they exist.
   setStrength(SingletonRandom.instance.getNormalDistribution(MIN_STRENGTH, MAX_STRENGTH, 2.0));
   setHealth(SingletonRandom.instance.getNormalDistribution(MIN_HEALTH, MAX_HEALTH, 2.0));
   setSpeed(SingletonRandom.instance.getNormalDistribution(MIN_SPEED, MAX_SPEED, 2.0));
   createAvatar();
   tooltip = new Tooltip(toString());
   Tooltip.install(getAvatar(), tooltip);
   tt = new TranslateTransition();
   tt.setNode(getAvatar()); // reuse
 } // end Actor constructor
Пример #3
0
 public void resetAvatarAttributes() {
   tooltip.setText(toString());
 } // Note: This updates the text in the Tooltip that was installed earlier. We re-use the