1
Fork 0

Only allow unit actions if adjacent to that unit

This commit is contained in:
Joshua Goins 2022-05-02 13:21:31 -04:00
parent e5e6fef3cc
commit 2db1135447

View file

@ -194,16 +194,18 @@ public class GameScreen implements Screen {
for(Unit unit : units) { for(Unit unit : units) {
if(unit.positionX == x && unit.positionY == y) { if(unit.positionX == x && unit.positionY == y) {
if(unit.team != currentUnit.team) { if(isAdjacent(currentUnit, unit)) {
if (unit.team != currentUnit.team) {
actions.add(new AttackAction(currentUnit, unit)); actions.add(new AttackAction(currentUnit, unit));
} else { } else {
// you can't trade with yourself! // you can't trade with yourself!
if(unit != currentUnit) { if (unit != currentUnit) {
actions.add(new TradeAction()); actions.add(new TradeAction());
} }
} }
} }
} }
}
actions.add(new WaitAction()); actions.add(new WaitAction());