Package koth.user.jlb

Source Code of koth.user.jlb.Square

package koth.user.jlb;

import koth.game.*;
import koth.util.Vector;

import java.util.*;

/**
* Create a square board
*
* <pre>{@code
*   .........
*   .........
*   .........
*   .........
*   .........
*   .........
*   .........
*   .........
*   .........
* }</pre>
*/
public class Square implements Generator {

    public static Board create(int teams, int size) {
        if (size <= 0)
            throw new IllegalArgumentException();
        // Create tiles
        Set<Vector> tiles = new HashSet<Vector>();
        for (int x = 0; x < size; ++x)
            for (int y = 0; y < size; ++y)
                tiles.add(new Vector(x, y));
        // Add all tiles as spawns
        List<Set<Vector>> spawns = new ArrayList<Set<Vector>>();
        for (int i = 0; i < teams; ++i)
            spawns.add(tiles);
        return new Board(tiles, spawns);
    }

    @Override
    public Board create(int teams) {
        return create(teams, 9);
    }

}
TOP

Related Classes of koth.user.jlb.Square

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.