Esempio n. 1
0
  public void moveToQuadrant(int v, int h) {
    String coordinates = af.getQuadrantXY(v, h);
    int y = Integer.parseInt(coordinates.substring(0, coordinates.indexOf("_")));
    int x = Integer.parseInt(coordinates.substring(coordinates.indexOf("_") + 1));

    if (getX() < x) {
      while (getX() != x) {
        turn(Direction.RIGHT);
        move();
      }
    } else {
      while (getX() != x) {
        turn(Direction.LEFT);
        move();
      }
    }

    if (getY() < y) {
      while (getY() != y) {
        turn(Direction.DOWN);
        move();
      }
    } else {
      while (getY() != y) {
        turn(Direction.UP);
        move();
      }
    }
  }
Esempio n. 2
0
 public void turn(Direction direction) {
   this.direction = direction;
   try {
     af.repaint();
   } catch (Exception e) {
     System.out.println("Repaint exception");
   }
 }
Esempio n. 3
0
 boolean checkRight(int checkX, int checkY) {
   for (; checkX < 9; checkX++) {
     if (bf.scanQuadrant2(checkY, checkX) instanceof Rock
         || af.getQuadrantString(checkX, checkY).equals(enemyTankPosition())) {
       return true;
     }
   }
   return false;
 }
Esempio n. 4
0
 public int battleFieldScanner() {
   for (int fieldX = 0; fieldX < bf.getDimentionX(); fieldX++) {
     for (int fieldY = 0; fieldY < bf.getDimentionY(); fieldY++)
       if ((af.getQuadrantString(fieldX, fieldY).equals(enemyTankPosition()))
           || (bf.scanQuadrant2(fieldY, fieldX) instanceof Rock)) {
         return fieldX + 1;
       }
   }
   return 0;
 }
Esempio n. 5
0
  public void reappear() {
    try {
      Thread.sleep(1000);
    } catch (Exception e) {
      System.out.println("Exception");
    }
    x = new Random().nextInt(bf.getDimentionX()) * 64;
    y = new Random().nextInt(bf.getDimentionY()) * 64;

    af.repaint();
  }
Esempio n. 6
0
  boolean lineScanner(Direction direction) {
    String checkQuad = af.getQuadrant(this.x, this.y);
    int checkX = Integer.parseInt(checkQuad.substring(0, checkQuad.indexOf("_")));
    int checkY = Integer.parseInt(checkQuad.substring(checkQuad.indexOf("_") + 1));

    if (checkX >= 0 && checkX < 9 && checkY >= 0 && checkY < 9) {
      if (checkDirection(direction, checkX, checkY)) {
        return true;
      }
    }
    return false;
  }
Esempio n. 7
0
  public void destroy() {
    if (this instanceof Tiger) {
      Tiger t = (Tiger) this;
      if (t.getArmor() > 0) {
        t.setArmor(0);
        return;
      } else {
        t.setArmor(1);
      }
    }

    x = -100;
    y = -100;
    af.repaint();
    reappear();
  }
Esempio n. 8
0
 public void fire() {
   Bullet bullet = new Bullet((x + 27), (y + 27), direction, tower);
   af.processFire(bullet, this);
 }
Esempio n. 9
0
  public void moveRandomWithFire() {

    af.processMoveRandomWithFire(this);
  }
Esempio n. 10
0
 public void moveRandom() {
   af.processMoveRandom(this);
 }
Esempio n. 11
0
 public void move() {
   af.processMove(this);
 }