private boolean processInterception() { String str = getQuadrantXY(bullet.getX(), bullet.getY()); int i = Integer.valueOf(str.substring(0, 1)); int q = Integer.valueOf(str.substring(2, str.length())); if (i >= battleField.getBattleField().length - battleField.getBattleField().length && i < battleField.getBattleField().length && q >= battleField.getBattleField().length - battleField.getBattleField().length && q < battleField.getBattleField().length && battleField.scanQuadrant(i, q) == "B") { battleField.updateQuadrant(i, q, " "); return true; } else return false; }
public int fireLeft() throws Exception { String str = getQuadrantXY(tank.getX(), tank.getY()); int tankV = Integer.valueOf(str.substring(0, 1)); int tankH = Integer.valueOf(str.substring(2, str.length())); tank.turn(Direction.LEFT); for (int idx = tankV; idx < tankV + 1; idx++) { for (int j = tankH; j >= 0; j--) { if (battleField.scanQuadrant(idx, j) == "B") { tank.fire(); } } } return tankH; }
public int fireDown() throws Exception { String str = getQuadrantXY(tank.getX(), tank.getY()); int tankV = Integer.valueOf(str.substring(0, 1)); int tankH = Integer.valueOf(str.substring(2, str.length())); tank.turn(Direction.DOWN); for (int idx = tankV; idx < battleField.getBattleField().length; idx++) { for (int j = tankH; j < tankH + 1; j++) { if (battleField.scanQuadrant(idx, j) == "B") { tank.fire(); } } } return tankV; }
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); int i = 0; Color cc; for (int v = 0; v < 9; v++) { for (int h = 0; h < 9; h++) { if (COLORDED_MODE) { if (i % 2 == 0) { cc = new Color(252, 241, 177); } else { cc = new Color(233, 243, 255); } } else { cc = new Color(180, 180, 180); } i++; g.setColor(cc); g.fillRect(h * 64, v * 64, 64, 64); } } for (int j = 0; j < battleField.getDimentionY(); j++) { for (int k = 0; k < battleField.getDimentionX(); k++) { if (battleField.scanQuadrant(j, k).equals("B")) { String coordinates = getQuadrant(j + 1, k + 1); int separator = coordinates.indexOf("_"); int y = Integer.parseInt(coordinates.substring(0, separator)); int x = Integer.parseInt(coordinates.substring(separator + 1)); g.setColor(new Color(0, 0, 255)); g.fillRect(x, y, 64, 64); } } } g.setColor(new Color(255, 0, 0)); g.fillRect(tank.getX(), tank.getY(), 64, 64); g.setColor(new Color(0, 255, 0)); if (tank.getDirection() == Direction.UP) { g.fillRect(tank.getX() + 20, tank.getY(), 24, 34); } else if (tank.getDirection() == Direction.DOWN) { g.fillRect(tank.getX() + 20, tank.getY() + 30, 24, 34); } else if (tank.getDirection() == Direction.LEFT) { g.fillRect(tank.getX(), tank.getY() + 20, 34, 24); } else { g.fillRect(tank.getX() + 30, tank.getY() + 20, 34, 24); } g.setColor(new Color(255, 0, 255)); g.fillRect(agressor.getX(), agressor.getY(), 64, 64); g.setColor(new Color(255, 255, 0)); if (agressor.getDirection() == Direction.UP) { g.fillRect(agressor.getX() + 20, agressor.getY(), 24, 34); } else if (agressor.getDirection() == Direction.DOWN) { g.fillRect(agressor.getX() + 20, agressor.getY() + 30, 24, 34); } else if (agressor.getDirection() == Direction.LEFT) { g.fillRect(agressor.getX(), agressor.getY() + 20, 34, 24); } else { g.fillRect(agressor.getX() + 30, agressor.getY() + 20, 34, 24); } g.setColor(new Color(255, 255, 0)); g.fillRect(bullet.getX(), bullet.getY(), 14, 14); }