Пример #1
0
  void itemHandeler(Graphics2D map) {
    boolean tmp = false;
    if (rand.nextInt((int) (300 * delta + difficulty * 40)) <= 1 && tmp) {
      int x = rand.nextInt(4) - 2;
      int y = rand.nextInt(4) - 2;
      int type = 1;
      if (x == 0 && y == 0) {
        x = 0;
        y = 1;
      }
      if (rand.nextInt(10) == 1) {
        type = 2;
      }
      if (rand.nextInt(5) == 1)
        for (int i = 0; i < player.weapon.length; i++)
          if (player.weapon[i][11] != null && (Boolean) player.weapon[i][11] == true)
            if ((Integer) player.weapon[i][10] < 5) type = 3;

      spawnItem(player.body.getCenterX() + 200 * x, player.body.getCenterY() + 200 * y, type);
    }

    for (int i = 1; i < items.length; i++) {
      if (items[i] != null) {
        if (items[i].body == null) {
          items[i] = null;
        } else {
          items[i].Runtime(map, player, delta);
        }
      }
    }
  }
  public void updatePosition() {
    Point position = new Point(spaceOccupied.x, spaceOccupied.y);

    // Insert random behavior.  During
    // each update, a sprite has about
    // one chance in 10 of making a
    // random change to its
    // motionVector.  When a change
    // occurs, the motionVector
    // coordinate values are forced to
    // fall between -7 and 7.  This
    // puts a cap on the maximum speed
    // for a sprite.
    if (rand.nextInt() % 10 == 0) {
      Point randomOffset = new Point(rand.nextInt() % 3, rand.nextInt() % 3);
      motionVector.x += randomOffset.x;
      if (motionVector.x >= 7) motionVector.x -= 7;
      if (motionVector.x <= -7) motionVector.x += 7;
      motionVector.y += randomOffset.y;
      if (motionVector.y >= 7) motionVector.y -= 7;
      if (motionVector.y <= -7) motionVector.y += 7;
    } // end if

    // Move the sprite on the screen
    position.translate(motionVector.x, motionVector.y);

    // Bounce off the walls
    boolean bounceRequired = false;
    Point tempMotionVector = new Point(motionVector.x, motionVector.y);

    // Handle walls in x-dimension
    if (position.x < bounds.x) {
      bounceRequired = true;
      position.x = bounds.x;
      // reverse direction in x
      tempMotionVector.x = -tempMotionVector.x;
    } else if ((position.x + spaceOccupied.width) > (bounds.x + bounds.width)) {
      bounceRequired = true;
      position.x = bounds.x + bounds.width - spaceOccupied.width;
      // reverse direction in x
      tempMotionVector.x = -tempMotionVector.x;
    } // end else if

    // Handle walls in y-dimension
    if (position.y < bounds.y) {
      bounceRequired = true;
      position.y = bounds.y;
      tempMotionVector.y = -tempMotionVector.y;
    } else if ((position.y + spaceOccupied.height) > (bounds.y + bounds.height)) {
      bounceRequired = true;
      position.y = bounds.y + bounds.height - spaceOccupied.height;
      tempMotionVector.y = -tempMotionVector.y;
    } // end else if

    if (bounceRequired)
      // save new motionVector
      setMotionVector(tempMotionVector);
    // update spaceOccupied
    setSpaceOccupied(position);
  } // end updatePosition()
Пример #3
0
  void generateBackground(int size) {
    backgroundWidth = 100;
    int spacing = backgroundWidth;
    int id = 0;
    for (int i = 0; i < bounds.getWidth() / spacing; i++) {
      background[id][0] = spacing * (i + 1) - bounds.getWidth() / 2;
      background[id][1] = -bounds.getHeight() / 2;
      background[id][2] = spacing * (i + 1) - bounds.getWidth() / 2;
      background[id][3] = 0;
      background[id][4] = spacing * (i + 1) - bounds.getWidth() / 2;
      background[id][5] = bounds.getHeight();

      background[id][6] = rand.nextInt(3) - 1;
      background[id][7] = rand.nextInt(3) - 1;
      background[id][8] = 1;
      id++;
    }
    for (int i = 0; i < bounds.getHeight() / spacing; i++) {
      background[id][0] = -bounds.getHeight() / 2;
      background[id][1] = spacing * (i + 1) - bounds.getHeight() / 2;
      background[id][2] = 0;
      background[id][3] = spacing * (i + 1) - bounds.getWidth() / 2;
      background[id][4] = bounds.getWidth();
      background[id][5] = spacing * (i + 1) - bounds.getHeight() / 2;

      background[id][6] = rand.nextInt(3) - 1;
      background[id][7] = rand.nextInt(3) - 1;
      background[id][8] = 1;
      id++;
    }
  }
Пример #4
0
  /*
   * @param i - accepts int i for person number
   * @return - new positions
   */
  public int[] getNewPosition(int i) {
    // logic to auto select for computer player:
    if (i != 0) {
      // while space is not selected, randomly select rooms and spaces.
      while (spaceSelected == false) {

        // generate random number
        Random generator = new Random();
        int room = generator.nextInt(10);

        // random select a room
        allRooms[room].doClick();

        // generate random space
        int space = generator.nextInt(524);

        // randomly select a space
        btn[space].doClick();
      }
    }

    // if (debugBoardPanel) { System.out.println("[526] boardPanel.getNewPosition(): Called.") ; }
    int[] newPositions = {newPositionColumn, newPositionRow};

    // if (debugBoardPanel) { System.out.println("[530] boardPanel.getNewPosition().newPositions: "
    // + newPositions[0] + ", " + newPositions[1]); }

    return newPositions;
  }
Пример #5
0
 private Card genNewCard() {
   Random rand = new Random();
   Card card = new Card(rand.nextInt(52) + 1);
   while (cardUsed.contains(card)) card = new Card(rand.nextInt(52) + 1);
   cardUsed.add(card);
   return card;
 }
  private void createTomeko() {

    materialCapacity = randy.nextInt(400) + 301;
    fuelCapacity = randy.nextInt(300) + 1;
    controlledBy = -1;
    planetType = TOMEKO;
    baseOffense = 3;
    baseDefense = 3;
  }
  private void createSarena() {

    fuelCapacity = randy.nextInt(500) + 201;
    materialCapacity = randy.nextInt(500) + 201;
    controlledBy = -1;
    planetType = SARENA;
    baseOffense = 5;
    baseDefense = 5;
  }
Пример #8
0
 // 给定范围获得随机颜色
 Color getRandColor(int fc, int bc) {
   Random random = new Random();
   if (fc > 255) fc = 255;
   if (bc > 255) bc = 255;
   int r = fc + random.nextInt(bc - fc);
   int g = fc + random.nextInt(bc - fc);
   int b = fc + random.nextInt(bc - fc);
   return new Color(r, g, b);
 }
  private void createThesban() {

    fuelCapacity = randy.nextInt(400) + 301;
    materialCapacity = randy.nextInt(300) + 1;
    controlledBy = -1;
    planetType = THESBAN;
    baseOffense = 3;
    baseDefense = 3;
  }
Пример #10
0
 int selectCycle() {
   if (t < N) {
     return generator.nextInt(5);
   } else {
     if (Rtmp > alpha) {
       currentPath = previousPath;
     } else currentPath = generator.nextInt(5);
   }
   return currentPath;
 }
  public static double runTrial(int memoryType, int probability) {
    HashMap<Point, EnergySource> energySources = new HashMap<>();
    int sources = 40, width = 200, height = 200, energy = 125;
    Point location = new Point(0, 0);
    Random generator = new Random();
    Robot<EnergySource> robot;
    EnergySource energySource;
    double amount;

    // Generate all the energy sources and the robot
    while (energySources.size() < sources) {
      location = new Point(generator.nextInt(width), generator.nextInt(height));
      if (isFarEnough(location, energySources)) {
        energySources.put(location, new EnergySource(location, energy));
      }
    }
    while (!isFarEnough(location, energySources)) {
      location = new Point(generator.nextInt(width), generator.nextInt(height));
    }
    robot = new Robot<>(location, memoryType);
    // Program loop
    while (robot.getEnergy() > 0) {
      if (robot.isCurious()) {
        robot.moveRandomly(width, height);
      } else {
        energySource = robot.retrieveEnergySource(probability);
        if (energySource != null) {
          robot.moveToLocation(energySource.getLocation());
        } else {
          robot.moveRandomly(width, height);
        }
        energySource = energySources.get(robot.getLocation());
        if (energySource != null) {
          if (robot.getMaxEnergy() - robot.getEnergy() < energySource.getEnergy()) {
            amount = robot.getMaxEnergy() - robot.getEnergy();
          } else {
            amount = energySource.getEnergy();
          }
          robot.increaseEnergy(amount);
          energySource.decreaseEnergy(amount);
          if (energySource.getEnergy() <= 0) {
            robot.forgetEnergySource(energySource);
            energySources.remove(robot.getLocation());
          }
        }
      }
      robot.detectEnergySources(energySources);
    }
    return robot.getTravelDistance();
  }
Пример #12
0
  void enemieHandeler() {
    int ran = (int) ((70 - difficulty) * delta);
    if (ran <= 0) return;
    if (rand.nextInt(ran) == 1) {
      int x = rand.nextInt(2);
      int y = rand.nextInt(2);
      int size = rand.nextInt(1000) + 50;
      if (x == 0 && y == 0)
        if (rand.nextBoolean()) x = rand.nextInt(4) + 1;
        else y = rand.nextInt(4) + 1;

      if (rand.nextBoolean()) x = -x;
      if (rand.nextBoolean()) y = -y;
      size = size * (rand.nextInt(difficulty) + 1);

      x = (int) (x * 400 + player.body.getCenterX());
      y = (int) (y * 400 + player.body.getCenterY());

      int type = 0;

      if (rand.nextInt(60 / difficulty) <= 1) type = rand.nextInt(3) + 1;

      spawnEnemie(x, y, size, type);
    }
  }
 protected static int chooseType(Random rand, int gt) {
   int type = gt;
   while (type == gt) {
     type = rand.nextInt(5);
   }
   return type + 1;
 }
  public Point getEmptyPosition(Dimension spriteSize) {
    Rectangle trialSpaceOccupied = new Rectangle(0, 0, spriteSize.width, spriteSize.height);
    Random rand = new Random(System.currentTimeMillis());
    boolean empty = false;
    int numTries = 0;

    // Search for an empty position
    while (!empty && numTries++ < 100) {
      // Get a trial position
      trialSpaceOccupied.x = Math.abs(rand.nextInt() % backgroundImage.getSize().width);
      trialSpaceOccupied.y = Math.abs(rand.nextInt() % backgroundImage.getSize().height);
      // Iterate through existing
      // sprites, checking if position
      // is empty
      boolean collision = false;
      for (int cnt = 0; cnt < size(); cnt++) {
        Rectangle testSpaceOccupied = ((Sprite) elementAt(cnt)).getSpaceOccupied();
        if (trialSpaceOccupied.intersects(testSpaceOccupied)) {
          collision = true;
        } // end if
      } // end for loop
      empty = !collision;
    } // end while loop
    return new Point(trialSpaceOccupied.x, trialSpaceOccupied.y);
  } // end getEmptyPosition()
Пример #15
0
 /**
  * roll takes no arguments and randomly generates a value between 1 and 6. 1 = thorax 2 = head 3 =
  * legs 4 = eyes 5 = antenna 6 = abdomen
  */
 public void roll() {
   Random rnd = new Random();
   int min = 1;
   int max = 6;
   int rndInt = rnd.nextInt(max - min + 1) + min;
   this.roll = rndInt;
 }
Пример #16
0
 public Star(Point loc, Color c, int alpha) {
   location = loc;
   r = c.getRed();
   b = c.getBlue();
   g = c.getGreen();
   a = alpha;
   pulseRate = rand.nextInt(155);
 }
Пример #17
0
 // Generate n components of random sizes
 public static JComponent[] generateRandomComponents(int n) {
   Random r = new Random(0);
   JComponent[] c = new JComponent[n];
   int m = n;
   while (m > 0) {
     int i = r.nextInt(n);
     if (c[i] == null) {
       c[i] = new JLabel("Component " + i, null, SwingConstants.CENTER);
       int w = 5 * (2 + r.nextInt(20));
       int h = 5 * (2 + r.nextInt(20));
       c[i].setPreferredSize(new Dimension(w, h));
       c[i].setBorder(new EtchedBorder());
       m--;
     }
   }
   return c;
 }
Пример #18
0
 public Star(Point loc, int red, int green, int blue, int alpha) {
   location = loc;
   r = red;
   b = blue;
   g = green;
   a = alpha;
   pulseRate = rand.nextInt(254);
 }
Пример #19
0
 private static String generateKey(final int size) {
   StringBuilder sb = new StringBuilder();
   for (int i = 0; i < size; i++) {
     int idx = rand.nextInt(ALPHANUMERIC.length());
     sb.append(ALPHANUMERIC.substring(idx, idx + 1));
   }
   return (sb.toString());
 }
  private void createIonis() {

    materialCapacity = randy.nextInt(1200) + 201;
    fuelCapacity = 200;
    controlledBy = -1;
    planetType = IONIS;
    baseOffense = 5;
    baseDefense = 8;
  }
  private void createPeyo() {

    fuelCapacity = randy.nextInt(1200) + 201;
    materialCapacity = 200;
    controlledBy = -1;
    planetType = PEYO;
    baseOffense = 8;
    baseDefense = 5;
  }
Пример #22
0
 public void randomize() {
   seed = new Date().getTime();
   randomGenerator.setSeed(seed);
   a = randomGenerator.nextFloat();
   b = randomGenerator.nextFloat();
   c = randomGenerator.nextFloat();
   d = randomGenerator.nextFloat();
   k = randomGenerator.nextInt() % 20 - 10;
 }
  public newPlanet() {

    initializePlanets();
    int z = 0;

    z = randy.nextInt(1000);
    System.out.println("Planet" + z);
    supplyPlanet(z);
  }
Пример #24
0
 public static Shipment randomShipment() {
   Shipment s = create(Shipment.class);
   s.setExternalReferenceId(generateKey(7));
   s.setFromAddress(randomAddress());
   s.setToAddress(randomAddress());
   s.setShippingServiceName(randomShippingService().getName());
   for (int i = 0; i < rand.nextInt(5) + 1; i++) {
     Parcel p = create(Parcel.class);
     p.setShipmentId(rand.nextInt(5000));
     p.setContents(randomize(CONTENTS));
     p.setWidth(rand.nextInt(5) + 1);
     p.setHeight(rand.nextInt(5) + 1);
     p.setLength(rand.nextInt(5) + 1);
     p.setWeight(rand.nextInt(5) + 1);
     p.setParcelStatus(randomEnum(ParcelStatus.values()));
     s.getParcels().add(p);
   }
   return (s);
 }
Пример #25
0
 @Override
 @EventHandler
 public void onChatReceived(ChatReceivedEvent event) {
   super.onChatReceived(event);
   String message = Util.stripColors(event.getMessage());
   if (message.startsWith("Please register with \"/register")) {
     String password = Util.generateRandomString(10 + random.nextInt(6));
     bot.say("/register " + password + " " + password);
   } else if (message.contains("You are not member of any faction.")
       && spamMessage != null
       && createFaction) {
     String msg = "/f create " + Util.generateRandomString(7 + random.nextInt(4));
     bot.say(msg);
   }
   for (String s : captchaList) {
     Matcher captchaMatcher = Pattern.compile(s).matcher(message);
     if (captchaMatcher.matches()) bot.say(captchaMatcher.group(1));
   }
 }
Пример #26
0
 public void nudge(int i) {
   x[i] += (double) rand.nextInt(1000) / 8756;
   y[i] += (double) rand.nextInt(1000) / 5432;
   int tmpScale = (int) (Math.abs(Math.sin(x[i])) * 10);
   scale[i] = (double) tmpScale / 10;
   int nudgeX = (int) (((double) getWidth() / 2) * .8);
   int nudgeY = (int) (((double) getHeight() / 2) * .60);
   xh[i] = (int) (Math.sin(x[i]) * nudgeX) + nudgeX;
   yh[i] = (int) (Math.sin(y[i]) * nudgeY) + nudgeY;
 }
  public DMoteModel(int id, Random rand, DDocument root) {
    this.root = root;
    this.id = id;

    x = 20 + rand.nextInt(root.canvas.getWidth() - 20);
    y = 20 + rand.nextInt(root.canvas.getHeight() - 20);

    values = new float[root.sensed_motes.size()];

    colors = new Color[root.sensed_motes.size()];
    sizes = new int[root.sensed_motes.size()];

    for (int i = 0; i < root.sensed_motes.size(); i++) {
      values[i] = rand.nextFloat() * 1000;
      colors[i] = setColor(values[i]);
      sizes[i] = setShapeSize(values[i]);
    }

    listeners = null;
  }
Пример #28
0
 void characterHandeler(Graphics2D map) {
   for (int i = 0; i < characterExplosions.length; i++) {
     if (characterExplosions[i] != null) {
       if (characterExplosions[i].render(map)) characterExplosions[i] = null;
     }
   }
   for (int i = 0; i < characters.length; i++) {
     if (characters[i] != null) {
       if (characters[i].isDead == true) {
         newCExplosion(characters[i].body.getCenterX(), characters[i].body.getCenterY());
         if (rand.nextInt(5) == 1) {
           int type = 1;
           if (rand.nextInt(10) == 1) {
             type = 2;
           }
           if (rand.nextInt(4) == 1)
             for (int j = 0; j < player.weapon.length; j++)
               if (player.weapon[j][11] != null && (Boolean) player.weapon[j][11] == true)
                 if ((Integer) player.weapon[j][10] < 5) type = 3;
           spawnItem(characters[i].body.getCenterX(), characters[i].body.getCenterY(), type);
         }
         characters[i] = null;
       } else {
         if (characters[i].id != "player") {
           characters[i].Folow(player);
           double[] pos = checkIfInsideBounds(characters[i]);
           characters[i].body.setFrame(
               pos[0], pos[1], characters[i].body.getWidth(), characters[i].body.getHeight());
           characters[i].Update(xOffset, yOffset, delta);
         }
         characters[i].Render(map, characters);
         if (Math.pow(characters[i].body.getCenterX() - characters[i].body.getCenterX(), 2)
                 + Math.pow(player.body.getCenterY() - player.body.getCenterY(), 2)
             < Math.pow(width * 1.5, 2)) {
           map.setColor(Color.darkGray);
           map.draw(characters[i].body);
         }
       }
     }
   }
 }
Пример #29
0
 public int attackDmg() {
   Random random = new Random();
   float randomInt = (float) (random.nextInt(10 + (agi * 2)) + 1);
   System.out.println(
       "PDAMAGE: "
           + this.initDmg
           + " PFINAL DAMAGE: "
           + (int) (this.initDmg + (this.initDmg * (randomInt / 100)))
           + " PRANDOM: "
           + randomInt);
   return (int) (this.initDmg + (this.initDmg * (randomInt / 100)));
 }
Пример #30
0
  @SuppressWarnings("unchecked")
  public void _addRandomSampleData(int setCount, int tempCount) throws Exception {
    long sts = this.minDateTS;
    long ets = this.maxDateTS;
    Random ran = new Random(sts);

    /* init datasets */
    if (setCount <= 0) {
      setCount = 1;
    }
    java.util.List<Data> dataSet[] = new java.util.List[setCount];
    for (int d = 0; d < dataSet.length; d++) {
      dataSet[d] = new Vector<Data>();
    }

    /* populate random temperature data */
    double rangeC = this.maxTempC - this.minTempC;
    long deltaSize = (ets - sts) / (long) tempCount;
    long deltaRangeTS = DateTime.HourSeconds(3);
    long ts = sts + (deltaSize / 2L);
    double Cs = (ran.nextDouble() * rangeC * 0.10) + (rangeC * 0.05);
    for (int t = 0; t < tempCount; t++) {
      double C[] = new double[dataSet.length];
      for (int d = 0; d < dataSet.length; d++) {
        C[d] = (ran.nextDouble() * 7.0) + ((d == 0) ? Cs : C[d - 1]) - 2.5;
        if (C[d] < this.minTempC) {
          C[d] = this.minTempC;
        }
        if (C[d] > this.maxTempC) {
          C[d] = this.maxTempC;
        }
        dataSet[d].add(new Data(ts, C[d]));
      }
      ts =
          sts
              + ((long) (t + 1) * deltaSize)
              + (long) ran.nextInt((int) deltaRangeTS)
              + (deltaRangeTS / 2L);
      if (ts > ets) {
        ts = ets - 1L;
      }
      // ts = sts + ((t==0)?DateTime.HourSeconds(1):(long)ran.nextInt((int)(ets - sts)));
      Cs = C[0];
    }

    /* add datasets */
    for (int d = 0; d < dataSet.length; d++) {
      ListTools.sort(dataSet[d], null);
      Color color = TEMP_COLOR[d % TEMP_COLOR.length];
      this.addDataSet(color, "Temp " + (d + 1), dataSet[d].toArray(new Data[dataSet[d].size()]));
    }
  }