示例#1
0
  private void generateBait() {
    java.util.Random r = new java.util.Random();
    int x = 0, y = 0;

    while (x == 0) {
      x = r.nextInt(snakeAreaX + snakeAreaWidth - 30);

      if (x <= snakeAreaX + 30) x = 0;

      for (int i = 0; i < snakeLength; i++) {
        if (x == snakex[i]) x = 0;
      }
    }
    // System.out.print("\njj"+x);
    while (y == 0) {
      y = r.nextInt(snakeAreaY + snakeAreaHeight - 30);
      if (y <= snakeAreaY + 30) y = 0;

      for (int i = 0; i < snakeLength; i++) {
        if (y == snakey[i]) y = 0;
      }
    }
    int tmp;

    tmp = x % 10;
    tmp = 10 - tmp;
    baitX = x + tmp;
    tmp = y % 10;
    tmp = 10 - tmp;
    baitY = y + tmp;
  }
示例#2
0
文件: set.java 项目: wcyuan/Set
 public void shuffle() {
   for (int i = 0; i < 3; i++) {
     for (int j = 0; j < num_cards; j++) {
       int k = Math.abs(rand.nextInt() % num_cards);
       /* swap */
       int temp = deck[j];
       deck[j] = deck[k];
       deck[k] = temp;
     }
   }
   current = 0;
 }