Search in sources :

Example 1 with ActionFlags

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

the class Tetfu method encode.

// コメント・フィールドは初期設定のみ設定可能
public String encode(List<TetfuElement> elements) {
    ColoredField prevField = ColoredFieldFactory.createField(TETFU_MAX_HEIGHT);
    String prevComment = "";
    for (int index = 0; index < elements.size(); index++) {
        TetfuElement element = elements.get(index);
        ColoredField field = element.getField().orElse(prevField);
        // field settings
        // prevFieldは、ひとつ前のミノを置いてできたフィールド
        // fieldは次に表示させたいフィールド。今回は、最初をのぞいてひとつ前のミノを置いてできたフィールドをそのまま利用
        encodeField(prevField, field);
        String comment = element.getEscapedComment();
        ActionFlags flags = new ActionFlags(comment, prevComment, index, element);
        parseAction(element, flags);
        ColorType colorType = element.getColorType();
        if (flags.isLock) {
            if (ColorType.isMinoBlock(colorType)) {
                Piece piece = converter.parseToBlock(colorType);
                Mino mino = minoFactory.create(piece, element.getRotate());
                field.putMino(mino, element.getX(), element.getY());
            }
            field.clearLine();
            if (flags.isBlockUp) {
                throw new UnsupportedOperationException();
            // currentField.blockUp();
            // for (int x = 0; x < TETFU_FIELD_WIDTH; x++)
            // currentField.setBlockNumber(x, 0, blockUp[x]);
            }
            if (flags.isMirror) {
                throw new UnsupportedOperationException();
            // currentField.mirror();
            }
        }
        // next field
        prevField = field;
        prevComment = comment;
    }
    StringBuilder builder = new StringBuilder();
    for (int index = 0; index < encodedValues.size(); index++) {
        Integer value = encodedValues.get(index);
        String encoded = TetfuTable.encodeData(value);
        builder.append(encoded);
        if (index % 47 == 41)
            builder.append('?');
    }
    return builder.toString();
}
Also used : ColoredField(common.tetfu.field.ColoredField) Piece(core.mino.Piece) ColorType(common.tetfu.common.ColorType) Mino(core.mino.Mino) ActionFlags(common.tetfu.common.ActionFlags)

Aggregations

ActionFlags (common.tetfu.common.ActionFlags)1 ColorType (common.tetfu.common.ColorType)1 ColoredField (common.tetfu.field.ColoredField)1 Mino (core.mino.Mino)1 Piece (core.mino.Piece)1