summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/tankontank/engine
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/ch/asynk/tankontank/engine')
-rw-r--r--core/src/ch/asynk/tankontank/engine/Board.java11
-rw-r--r--core/src/ch/asynk/tankontank/engine/Player.java46
2 files changed, 23 insertions, 34 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java
index 203436c..a7ebabf 100644
--- a/core/src/ch/asynk/tankontank/engine/Board.java
+++ b/core/src/ch/asynk/tankontank/engine/Board.java
@@ -1,5 +1,6 @@
package ch.asynk.tankontank.engine;
+import java.util.List;
import java.util.Iterator;
import java.util.Collection;
import java.util.ArrayList;
@@ -302,11 +303,10 @@ public abstract class Board implements Disposable
return searchBoard.possibleTargetsFrom(pawn, targets);
}
- protected int collectPossibleTargets(Pawn pawn, Iterator<Pawn> units, PawnCollection targets)
+ protected int collectPossibleTargets(Pawn pawn, List<Pawn> units, PawnCollection targets)
{
targets.clear();
- while (units.hasNext()) {
- Pawn target = units.next();
+ for (Pawn target : units) {
if (pawn.canEngage(target) && searchBoard.collectAttacks(pawn, target, true))
targets.add(target);
}
@@ -332,11 +332,10 @@ public abstract class Board implements Disposable
return assists.size();
}
- protected int collectAttackAssists(Pawn pawn, Pawn target, Iterator<Pawn> units, PawnCollection assists)
+ protected int collectAttackAssists(Pawn pawn, Pawn target, List<Pawn> units, PawnCollection assists)
{
assists.clear();
- while (units.hasNext()) {
- Pawn p = units.next();
+ for (Pawn p : units) {
if ((p != pawn) && p.canEngage(target) && searchBoard.collectAttacks(p, target, !p.canAssistEngagementWithoutLos()))
assists.add(p);
}
diff --git a/core/src/ch/asynk/tankontank/engine/Player.java b/core/src/ch/asynk/tankontank/engine/Player.java
index cb9543d..8bda179 100644
--- a/core/src/ch/asynk/tankontank/engine/Player.java
+++ b/core/src/ch/asynk/tankontank/engine/Player.java
@@ -9,10 +9,10 @@ import ch.asynk.tankontank.engine.Pawn;
public abstract class Player
{
- protected Faction faction;
- protected ArrayList<Pawn> units;
- protected ArrayList<Pawn> casualties;
- protected ArrayList<Pawn> reinforcement;
+ public Faction faction;
+ public ArrayList<Pawn> units;
+ public ArrayList<Pawn> casualties;
+ public ArrayList<Pawn> reinforcement;
public abstract void turnEnd();
public abstract void turnStart();
@@ -25,44 +25,39 @@ public abstract class Player
this.reinforcement = new ArrayList<Pawn>(n);
}
- public Faction getFaction()
- {
- return faction;
- }
-
- public List<Pawn> getReinforcement()
+ public String getName()
{
- return reinforcement;
+ return faction.toString();
}
- public int unitsLeft()
+ public boolean is(Faction faction)
{
- return (units.size() + reinforcement.size());
+ return (this.faction == faction);
}
- public int casualties()
+ public boolean isEnemy(Pawn pawn)
{
- return casualties.size();
+ return pawn.isEnemy(faction);
}
- public String getName()
+ public boolean isEnemy(Faction other)
{
- return faction.toString();
+ return faction.isEnemy(other);
}
- public boolean is(Faction faction)
+ public int unitsLeft()
{
- return (this.faction == faction);
+ return (units.size() + reinforcement.size());
}
- public boolean isEnemy(Pawn pawn)
+ public int reinforcement()
{
- return pawn.isEnemy(faction);
+ return reinforcement.size();
}
- public boolean isEnemy(Faction other)
+ public int casualties()
{
- return faction.isEnemy(other);
+ return casualties.size();
}
public void addUnit(Pawn pawn)
@@ -92,9 +87,4 @@ public abstract class Player
units.remove(pawn);
casualties.add(pawn);
}
-
- public Iterator<Pawn> unitIterator()
- {
- return units.iterator();
- }
}