Search in sources :

Example 11 with ColorType

use of common.tetfu.common.ColorType in project solution-finder by knewjade.

the class AllFigGenerator method updateField.

@Override
public void updateField(ColoredField field, Mino mino, int x, int y) {
    ColoredField freeze = field.freeze(field.getMaxHeight());
    if (mino != null)
        freeze.putMino(mino, x, y);
    int heightBlock = setting.getFieldHeightBlock();
    int widthBlock = setting.getFieldWidthBlock();
    for (int yIndex = 0; yIndex < heightBlock; yIndex++) {
        boolean isFilledLine = freeze.isFilledLine(yIndex);
        for (int xIndex = 0; xIndex < widthBlock; xIndex++) {
            ColorType type = field.getColorType(xIndex, yIndex);
            FigColor figColor = FigColor.parse(type);
            Color color = getColor(figColor, isFilledLine);
            graphics.setColor(color);
            Rectangle rectangle = positionDecider.getInField(xIndex, yIndex);
            fillRect(rectangle);
        }
    }
}
Also used : ColoredField(common.tetfu.field.ColoredField) FigColor(util.fig.FigColor) FigColor(util.fig.FigColor) Rectangle(util.fig.Rectangle) ColorType(common.tetfu.common.ColorType)

Example 12 with ColorType

use of common.tetfu.common.ColorType in project solution-finder by knewjade.

the class AllFigGenerator method drawMino.

private void drawMino(Piece piece, Rectangle rectangle) {
    if (piece == null)
        return;
    ColorType colorType = colorConverter.parseToColorType(piece);
    FigColor figColor = FigColor.parse(colorType);
    Color color = getColor(figColor, true);
    graphics.setColor(color);
    Mino mino = minoFactory.create(piece, Rotate.Spawn);
    int maxX = mino.getMaxX();
    int minX = mino.getMinX();
    double mx = (maxX - minX + 1) / 2.0 + minX;
    int minY = -mino.getMaxY();
    int maxY = -mino.getMinY();
    double my = (maxY - minY + 1) / 2.0 + minY;
    int nextBlockSize = setting.getNextBlockSize();
    int nextBlockMargin = setting.getNextBlockMargin();
    int size = nextBlockSize + nextBlockMargin;
    double centerX = rectangle.getX() + rectangle.getWidth() / 2.0;
    double centerY = rectangle.getY() + rectangle.getHeight() / 2.0;
    for (int[] position : mino.getPositions()) {
        int x = (int) (centerX + (position[0] - mx) * size + nextBlockMargin / 2.0);
        int y = (int) (centerY - (position[1] + my) * size + nextBlockMargin / 2.0);
        graphics.fillRect(x, y, nextBlockSize, nextBlockSize);
    }
}
Also used : FigColor(util.fig.FigColor) FigColor(util.fig.FigColor) ColorType(common.tetfu.common.ColorType) Mino(core.mino.Mino)

Example 13 with ColorType

use of common.tetfu.common.ColorType in project solution-finder by knewjade.

the class NoHoldFigGenerator method drawMino.

private void drawMino(Piece piece, Rectangle rectangle) {
    if (piece == null)
        return;
    ColorType colorType = colorConverter.parseToColorType(piece);
    FigColor figColor = FigColor.parse(colorType);
    Color color = getColor(figColor, true);
    graphics.setColor(color);
    Mino mino = minoFactory.create(piece, Rotate.Spawn);
    int maxX = mino.getMaxX();
    int minX = mino.getMinX();
    double mx = (maxX - minX + 1) / 2.0 + minX;
    int minY = -mino.getMaxY();
    int maxY = -mino.getMinY();
    double my = (maxY - minY + 1) / 2.0 + minY;
    int nextBlockSize = setting.getNextBlockSize();
    int nextBlockMargin = setting.getNextBlockMargin();
    int size = nextBlockSize + nextBlockMargin;
    double centerX = rectangle.getX() + rectangle.getWidth() / 2.0;
    double centerY = rectangle.getY() + rectangle.getHeight() / 2.0;
    for (int[] position : mino.getPositions()) {
        int x = (int) (centerX + (position[0] - mx) * size + nextBlockMargin / 2.0);
        int y = (int) (centerY - (position[1] + my) * size + nextBlockMargin / 2.0);
        graphics.fillRect(x, y, nextBlockSize, nextBlockSize);
    }
}
Also used : FigColor(util.fig.FigColor) FigColor(util.fig.FigColor) ColorType(common.tetfu.common.ColorType) Mino(core.mino.Mino)

Example 14 with ColorType

use of common.tetfu.common.ColorType in project solution-finder by knewjade.

the class PngWriter method write.

@Override
public void write(List<TetfuPage> tetfuPages) throws IOException {
    int page = startPageIndex + 1;
    for (TetfuPage tetfuPage : tetfuPages) {
        String path = String.format("%s_%03d.png", prefix, page);
        // リセット
        figGenerator.reset();
        // 現在のミノを取得
        ColorType colorType = tetfuPage.getColorType();
        Rotate rotate = tetfuPage.getRotate();
        Mino mino = ColorType.isMinoBlock(colorType) ? minoFactory.create(colorConverter.parseToBlock(colorType), rotate) : null;
        int x = tetfuPage.getX();
        int y = tetfuPage.getY();
        // フィールドの更新
        ColoredField field = tetfuPage.getField();
        figGenerator.updateField(field, mino, x, y);
        // ミノを置くかチェック
        if (ColorType.isMinoBlock(colorType)) {
            // 現在のミノの更新
            figGenerator.updateMino(colorType, rotate, x, y);
            // bagの更新
            Piece piece = colorConverter.parseToBlock(colorType);
            bag.use(piece);
        }
        // ネクストの更新
        figGenerator.updateNext(bag.getNext(nextBoxCount));
        // ホールドの更新
        figGenerator.updateHold(bag.getHold());
        // 画像の生成
        BufferedImage image = figGenerator.fix();
        // 画像の出力
        ImageIO.write(image, "png", new File(path));
        page++;
    }
}
Also used : TetfuPage(common.tetfu.TetfuPage) ColoredField(common.tetfu.field.ColoredField) Rotate(core.srs.Rotate) Piece(core.mino.Piece) ColorType(common.tetfu.common.ColorType) Mino(core.mino.Mino) File(java.io.File) BufferedImage(java.awt.image.BufferedImage)

Example 15 with ColorType

use of common.tetfu.common.ColorType in project solution-finder by knewjade.

the class ActionEncoder method coordinate_to_int.

private int coordinate_to_int(TetfuElement element) {
    int x = element.getX();
    int y = element.getY();
    ColorType type = element.getColorType();
    Rotate rotate = element.getRotate();
    if (!ColorType.isMinoBlock(type)) {
        x = 0;
        y = 22;
    } else if (type == ColorType.O && rotate == Rotate.Left) {
        x -= 1;
        y -= 1;
    } else if (type == ColorType.O && rotate == Rotate.Reverse)
        x -= 1;
    else if (type == ColorType.O && rotate == Rotate.Spawn)
        y += 1;
    else if (type == ColorType.I && rotate == Rotate.Reverse)
        x -= 1;
    else if (type == ColorType.I && rotate == Rotate.Left)
        y += 1;
    else if (type == ColorType.S && rotate == Rotate.Spawn)
        y += 1;
    else if (type == ColorType.S && rotate == Rotate.Right)
        x += 1;
    else if (type == ColorType.Z && rotate == Rotate.Spawn)
        y += 1;
    else if (type == ColorType.Z && rotate == Rotate.Left)
        x -= 1;
    return (TETFU_FIELD_TOP - y - 1) * TETFU_FIELD_WIDTH + x;
}
Also used : Rotate(core.srs.Rotate) ColorType(common.tetfu.common.ColorType)

Aggregations

ColorType (common.tetfu.common.ColorType)27 ColoredField (common.tetfu.field.ColoredField)19 Piece (core.mino.Piece)15 Mino (core.mino.Mino)11 Rotate (core.srs.Rotate)11 ColorConverter (common.tetfu.common.ColorConverter)10 Field (core.field.Field)9 MinoFactory (core.mino.MinoFactory)8 List (java.util.List)8 TetfuPage (common.tetfu.TetfuPage)7 Collectors (java.util.stream.Collectors)7 ColoredFieldFactory (common.tetfu.field.ColoredFieldFactory)6 FinderParseException (exceptions.FinderParseException)6 Arrays (java.util.Arrays)6 BlockField (common.datastore.BlockField)5 Tetfu (common.tetfu.Tetfu)5 TetfuElement (common.tetfu.TetfuElement)5 LinkedList (java.util.LinkedList)5 Optional (java.util.Optional)5 FigColor (util.fig.FigColor)5