/** * If near planet only one type enemy return his name * * @param planet - our planet * @return - enemy name */ private String whoIsInvader(Planet planet) { String invader = ""; for (Mob mob : mobs) { if (mob.getFigure() .overlaps( new Circle( planet.getFigure().x, planet.getFigure().y, 2 * planet.getFigure().radius))) { if (invader.equals("")) { invader = mob.getHostName(); } else if (!invader.equals(mob.getHostName())) { return ""; } } } return invader; }
/** * Check if player's mobs near planet * * @param planet - planet * @return - true, if only enemies */ private Boolean onlyEnemiesNearPlanet(Planet planet) { int count = 0; for (Mob mob : mobs) { if (mob.getFigure() .overlaps( new Circle( planet.getFigure().x, planet.getFigure().y, 2 * planet.getFigure().radius)) && mob.getHostName().equals(planet.getHostName())) { return false; } else if (mob.getFigure() .overlaps( new Circle( planet.getFigure().x, planet.getFigure().y, 2 * planet.getFigure().radius)) && !mob.getHostName().equals(planet.getHostName())) { count++; } } if (count > 0) { return true; } return false; }
/** * Click on game field * * @param screenX - screen position click X * @param screenY - screen position click Y */ public void clickOnWorld(int screenX, int screenY) { screenY = (int) (game.getScreenHeight() - screenY); Circle helpCircle = new Circle(screenX, screenY, 1); if (checkOnTouch(helpCircle) == null && isSelected) { moveToPoint(screenX, screenY, null); } else if (checkOnTouch(helpCircle) instanceof Planet) { Planet planet = (Planet) checkOnTouch(helpCircle); if (planet.getHostName().equals(playerName)) { isSelected = true; planet.setIsSelected(true); } else { moveToPoint(planet.getFigure().x, planet.getFigure().y, planet); } } else if (checkOnTouch(helpCircle) instanceof Mob) { Mob mob = (Mob) checkOnTouch(helpCircle); if (mob.getHostName().equals(playerName)) { isSelected = true; mob.setIsSelected(true); } else { moveToPoint(mob.getFigure().x, mob.getFigure().y, mob); } } }