Пример #1
0
 @Override
 public void run() {
   Rectangle edges =
       new Rectangle(
           0 + getInsets().left,
           0 + getInsets().top,
           getSize().width - (getInsets().left + getInsets().right),
           getSize().height - (getInsets().top + getInsets().bottom));
   for (int loopIndex = 0; loopIndex < numberFish; loopIndex++) {
     fishes[loopIndex] = new Fish(fishImages[0], fishImages[1], edges, this);
     try {
       Thread.sleep(20);
     } catch (Exception exp) {
       System.out.println(exp.getMessage());
     }
   }
   Fish fish;
   while (runOK) {
     for (int loopIndex = 0; loopIndex < numberFish; loopIndex++) {
       fish = fishes[loopIndex];
       fish.swim();
     }
     try {
       Thread.sleep(sleepTime);
     } catch (Exception exp) {
       System.out.println(exp.getMessage());
     }
     repaint();
   }
 }
Пример #2
0
  public static void main(String[] args) {
    Fish myFish = new Fish(userInput);

    myFish.setAge(0);
    myFish.getAge();

    System.out.println(myFish.FishAge);
  }
 public static void main(String[] args) {
   Cat cat = new Cat();
   Dog dog = new Dog();
   Fish fish = new Fish();
   Woman woman = new Woman();
   cat.owner = woman;
   dog.owner = woman;
   fish.owner = woman;
 }
Пример #4
0
 void replaceFish(Fish fish) {
   if (time - fish.birthTime > longestLifespan) {
     longestLifespan = time - fish.birthTime;
     bestGenome = fish.network.getWeightGenome();
   }
   
   Fish f = w1.addNewFish(random(0,width),random(0,height),10,8);
   f.setRGBZ(int(random(0,255)), int(random(0,255)), int(random(0,255)), 100); 
   f.viewWidth = 80;
   f.viewDistance = 1024;
   f.numViewSensors = NUM_VIEW_SENSORS;
   f.network.setWeightGenome(bestGenome);
   removeFish(fish);
 }
Пример #5
0
  void step() {
    for (int i = 0; i < masses.length; i++) {
      pointMass current = masses[i];

      current.step();

      if (closedSystem == true) {
        if (current.position[0] < current.size/2) {
          current.prevPosition[0] = current.position[0];
          current.position[0] = current.size/2;
        }
        if (current.position[0] > width - current.size/2) {
          current.prevPosition[0] = current.position[0];
          current.position[0] = width - current.size/2;
        }
        if (current.position[1] < current.size/2) {
          current.prevPosition[1] = current.position[1];
          current.position[1] = current.size/2;
        }
        if (current.position[1] > height - current.size/2) {
          current.prevPosition[1] = current.position[1];
          current.position[1] = height - current.size/2;
        }
      }
    }
    time+=timeStep;
    for (int i = 0; i < fishes.length; i++) {
      Fish current = fishes[i];
      
      if (current.masses[0] != null) {
        current.swim();
        current.see();
        current.think();
        current.live();
      }
    }
  }
Пример #6
0
 Fish addNewFish(float initPositionX, float initPositionY, float size, float mass) {
   Fish f = new Fish(this,initPositionX,initPositionY, size, mass);
   fishes = (Fish[])append(fishes, f);
   f.id = fishes.length-1;
   return f;
 }
Пример #7
0
 void addFish(Fish f) {
   fishes = (Fish[])append(fishes, f);
   f.id = fishes.length-1;
   f.world = this;
 }