summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/tankontank/engine/TileSet.java
blob: 6f71b423c9b17e1d1aa3bca2a8da097aab8b7e33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package ch.asynk.tankontank.engine;

import java.util.Iterator;
import java.util.Collection;
import java.util.LinkedHashSet;

public class TileSet extends LinkedHashSet<Tile> implements Board.TileCollection
{
    private final Board board;

    public TileSet(Board board, int n)
    {
        super(n);
        this.board = board;
    }

    public Tile first()
    {
        if (isEmpty()) return null;
        return iterator().next();
    }

    public void enable(int i, boolean enable)
    {
        for (Tile tile : this)
            board.enableOverlayOn(tile, i, enable);
    }

    public void collectPawns(Board.PawnCollection pawns)
    {
        pawns.clear();
        for (Tile tile : this) {
            Iterator<Pawn> itr = tile.iterator();
            while(itr.hasNext())
                pawns.add(itr.next());
        }
    }

    public int fromNodes(Collection<SearchBoard.Node> nodes)
    {
        clear();
        for (SearchBoard.Node node : nodes) {
            Tile tile = board.getTile(node.col, node.row);
            add(tile);
        }

        return size();
    }
}