public void attack(Direction d) throws NotEnoughResourcesException, ChampionDisarmedException { Damageable f = null; Champion c = getCurrentChampion(); for (int i = 0; i < c.getAppliedEffects().size(); i++) { if (c.getAppliedEffects().get(i) instanceof Disarm) { throw new ChampionDisarmedException(); } } if (c.getCurrentActionPoints() < 2) { throw new NotEnoughResourcesException(); } else { if (d == Direction.DOWN) { for (int i = 1; i < c.getAttackRange(); i++) { if (c.getLocation().x - i > 0) break; if (board[c.getLocation().x - i][c.getLocation().y] != null) { f = (Damageable) this.board[c.getLocation().x - i][c .getLocation().y]; if (f instanceof Champion) { if (firstPlayer.getTeam().contains(c) && firstPlayer.getTeam().contains(f) || secondPlayer.getTeam().contains(c) && secondPlayer.getTeam().contains(f) || hasShield((Champion) f) || tryDodge((Champion) f)) { } else { if (checkRange(c.getAttackRange(), c, f)) { helperAttack(f); if (f.getCurrentHP() == 0) Eliminate(f); break; } } } if (f instanceof Cover) { if (checkRange(c.getAttackRange(), c, f)) { helperAttack(f); if (f.getCurrentHP() == 0) Eliminate(f); break; } } } } } if (d == Direction.LEFT) { for (int i = 1; i < c.getAttackRange(); i++) { if (c.getLocation().y - i < 0) break; if (board[c.getLocation().x][c.getLocation().y - i] != null) { f = (Damageable) this.board[c.getLocation().x][c .getLocation().y - i]; if (f instanceof Champion) { if (firstPlayer.getTeam().contains(c) && firstPlayer.getTeam().contains(f) || secondPlayer.getTeam().contains(c) && secondPlayer.getTeam().contains(f) || hasShield((Champion) f) || tryDodge((Champion) f)) { } else { if (checkRange(c.getAttackRange(), c, f)) { helperAttack(f); if (f.getCurrentHP() == 0) Eliminate(f); break; } } } if (f instanceof Cover) { if (checkRange(c.getAttackRange(), c, f)) { helperAttack(f); if (f.getCurrentHP() == 0) Eliminate(f); break; } } } } } if (d == Direction.UP) { for (int i = 1; i < c.getAttackRange(); i++) { if (c.getLocation().x + i > 4) break; if (board[c.getLocation().x + i][c.getLocation().y] != null) { f = (Damageable) this.board[c.getLocation().x + i][c .getLocation().y]; if (f instanceof Champion) { if (firstPlayer.getTeam().contains(c) && firstPlayer.getTeam().contains(f) || secondPlayer.getTeam().contains(c) && secondPlayer.getTeam().contains(f) || hasShield((Champion) f) || tryDodge((Champion) f)) { } else { if (checkRange(c.getAttackRange(), c, f)) { helperAttack(f); if (f.getCurrentHP() == 0) Eliminate(f); break; } } } if (f instanceof Cover) { if (checkRange(c.getAttackRange(), c, f)) { helperAttack(f); if (f.getCurrentHP() == 0) Eliminate(f); break; } } } } } if (d == Direction.RIGHT) { for (int i = 1; i < c.getAttackRange(); i++) { if (c.getLocation().y + i > 4) break; if (board[c.getLocation().x][c.getLocation().y + i] != null) { f = (Damageable) this.board[c.getLocation().x][c .getLocation().y + i]; if (f instanceof Champion) { if (firstPlayer.getTeam().contains(c) && firstPlayer.getTeam().contains(f) || secondPlayer.getTeam().contains(c) && secondPlayer.getTeam().contains(f) || (hasShield((Champion) f)) || (tryDodge((Champion) f))) { } else { if (checkRange(c.getAttackRange(), c, f)) { helperAttack(f); if (f.getCurrentHP() == 0) Eliminate(f); break; } } } if (f instanceof Cover) { if (checkRange(c.getAttackRange(), c, f)) { helperAttack(f); if (f.getCurrentHP() == 0) Eliminate(f); break; } } } } } } c.setCurrentActionPoints(c.getCurrentActionPoints() - 2); }