Skip to content

Commit

Permalink
little changes
Browse files Browse the repository at this point in the history
  • Loading branch information
asemanehnafe committed May 4, 2022
1 parent c81f0fe commit fe73ac5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
7 changes: 5 additions & 2 deletions src/main/java/controllers/CombatController.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public static String attackUnit(int x, int y) {
City defenderCity = hex[x][y].getCapital();
Combatable attacker = selectedUnit;
Combatable defender;
//todo: check capital
if (defenderCity != null) {
defender = defenderCity;
} else if (hex[x][y].getMilitaryUnit() != null) {
Expand All @@ -34,7 +33,12 @@ public static String attackUnit(int x, int y) {
if(attacker.isInPossibleCombatRange(x, y,0, attacker.getX(), attacker.getY())){
return "out of sight range";
}
attacker.attack(defender);
defender.defend(attacker);
return handelCombatType(defenderCity, x, y);
}

private static String handelCombatType(City defenderCity, int x, int y){
if (selectedUnit instanceof Ranged) {
if (defenderCity != null) {
return rangedCityCombat(defenderCity);
Expand All @@ -53,7 +57,6 @@ else if(hex[x][y].getMilitaryUnit() != null) {
}
return null;
}

private static String meleeCivilianCombat(int x, int y) {
return null;
}
Expand Down
32 changes: 11 additions & 21 deletions src/main/java/views/GameMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public void run(Scanner gameScanner) {
selectCivilian(Integer.parseInt(matcher.group("x")), Integer.parseInt(matcher.group("y")));
} else if ((matcher = getMatcher("move to (--coordinates|-c) (?<x>-?\\d+) (?<y>-?\\d+)", command)) != null) {
moveUnitView(Integer.parseInt(matcher.group("x")), Integer.parseInt(matcher.group("y")));
} else if ((matcher = getMatcher("attack (--coordinates|-c) (?<x>-?\\d+) (?<y>-?\\d+)", command)) != null) {
attackUnitView(Integer.parseInt(matcher.group("x")), Integer.parseInt(matcher.group("y")));
} else if ((matcher = getMatcher("Remove citizen at (--coordinates|-c) (?<x>-?\\d+) (?<y>-?\\d+) from work", command)) != null) {
System.out.println(CityController.removeCitizenFromWork(Integer.parseInt(matcher.group("x")), Integer.parseInt(matcher.group("y"))));
} else if ((matcher = getMatcher("lock an citizen to (--coordinates|-c) (?<x>-?\\d+) (?<y>-?\\d+)", command)) != null) {
Expand Down Expand Up @@ -160,31 +162,19 @@ else if (UnitController.isHexOccupied(x, y))

}

private static boolean handelErrors(int x, int y) {

private void attackUnitView(int x, int y) {
//todo : mp
if (UnitController.getSelectedUnit() == null) {
System.out.println("You should choose a unit first");
return false;
} else if (GameController.getPlayerCiviliansByLocation(UnitController.getSelectedUnit().getCurrentHex().getX(), UnitController.getSelectedUnit().getCurrentHex().getY()) == null
&& GameController.getPlayerMilitaryByLocation(UnitController.getSelectedUnit().getCurrentHex().getX(), UnitController.getSelectedUnit().getCurrentHex().getY()) == null) {
System.out.println("You don't own this unit");
return false;
} else if (UnitController.isHexOccupied(x, y)) {
System.out.println("This hex already has a unit of this type");
return false;
return;
}
return true;
}

private void attackUnitView(int x, int y) {
//todo: errors
if (handelErrors(x, y)) {
if (UnitController.getSelectedUnit() instanceof Civilian) {
System.out.println("you can not attack with a civilian unit");
return;
}
String combatResult = CombatController.attackUnit(x, y);
System.out.println(combatResult);
if (UnitController.getSelectedUnit() instanceof Civilian) {
System.out.println("you can not attack with a civilian unit");
return;
}
String combatResult = CombatController.attackUnit(x, y);
System.out.println(combatResult);
}

public static void cityCombatMenu(City city, Player player) {
Expand Down

0 comments on commit fe73ac5

Please sign in to comment.