Package com.jcloisterzone.board

Source Code of com.jcloisterzone.board.AbstractTileTest

package com.jcloisterzone.board;

import org.junit.Before;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import com.jcloisterzone.Expansion;
import com.jcloisterzone.config.Config;
import com.jcloisterzone.game.Game;

public class AbstractTileTest {

    protected Game game = new Game("1");
    protected TilePackFactory packFactory = new TilePackFactory();
    protected TileFactory tileFactory = new TileFactory();

    protected void setUpGame(Game game) {
        game.getExpansions().add(Expansion.BASIC);
    }

    @Before
    public void initFactories() {
        Config config = new Config();
        game.setConfig(config);
        setUpGame(game);
        packFactory.setGame(game);
        packFactory.setConfig(config);
        tileFactory.setGame(game);
    }

    protected Tile createTile(Expansion exp, String id) {
        Element el = packFactory.getExpansionDefinition(exp);
        NodeList nl = el.getElementsByTagName("tile");
        for (int i = 0; i < nl.getLength(); i++) {
            Element card = (Element) nl.item(i);
            if (id.equals(card.getAttribute("id"))) {
                return tileFactory.createTile(exp, id, card, false);
            }
        }
        throw new IllegalArgumentException("Invalid tile id");
    }

}
TOP

Related Classes of com.jcloisterzone.board.AbstractTileTest

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.