9-10 酒場の人びと

解説動画

解答コード

function pillar(height: number, typeOfBlock: number) {
    for (let i = 0; i < height; i++) {
        agent.setItem(typeOfBlock, 64, 1);
        agent.place(FORWARD);
        agent.move(UP, 1);
    }
}

function wall2(height: number, width: number, typeOfBlock: number) {
    for (let j = 0; j < width; j++) {
        pillar(height, typeOfBlock);
        agent.move(DOWN, height);
        agent.move(RIGHT, 1);
    }
}

function floor2(depth: number, width: number, typeOfBlock: number) {
    for (let i = 0; i < width; i++) {
        for(let j = 0; j < depth; j++) {
            agent.setItem(typeOfBlock, 64, 1);
            agent.move(FORWARD, 1);
            agent.place(DOWN);
        }
        agent.move(BACK, depth);
        agent.move(RIGHT, 1);
    }
}

function stairs2(height: number, width: number, steps: number, typeOfBlock: number) {
    for (let k = 0; k < steps; k++) {
        wall2(height, width, typeOfBlock);
        agent.move(LEFT, width);
        agent.move(BACK, 1);
        height -= 1;
    }
}

function roof2(depth: number, width: number, steps: number, typeOfBlock: number) {
    agent.move(UP, 1);
    for (let k = 0; k < steps; k++) {
        floor2(depth, width, typeOfBlock);
        agent.move(UP, 1);
        agent.move(LEFT, width - 1);
        agent.move(FORWARD, 1);
        depth -= 2;
        width -= 2;
    }
}

player.onChat("9-10", function() {
    floor2(9, 9, PLANKS_SPRUCE);

    agent.teleport(world(-20, 64, -841), NORTH);

    for (let j = 0; j < 4; j++) {
        pillar(7, LOG_SPRUCE);
        agent.move(DOWN, 7);
        agent.move(RIGHT, 1);
        agent.move(FORWARD, 9);
        agent.turn(TurnDirection.Left);
    }

    agent.teleport(world(-19, 64, -843), WEST);

    for (let j = 0; j < 3; j++) {
        wall2(7, 7, PLANKS_SPRUCE);
        agent.move(RIGHT, 1);
        agent.move(FORWARD, 2);
        agent.turn(TurnDirection.Left);
    }

    for (let i = 0; i < 2; i++) {
        wall2(7, 3, PLANKS_SPRUCE);
        agent.move(RIGHT, 1);
    }

    agent.move(LEFT, 5);
    agent.move(UP, 2);
    pillar(5, PLANKS_SPRUCE);

    agent.teleport(world(-27, 64, -846), NORTH);

    stairs2(4, 2, 4, PLANKS_SPRUCE);
    agent.move(UP, 4);
    agent.move(FORWARD, 4);
    floor2(2, 7, PLANKS_SPRUCE);

    agent.teleport(world(-29, 71, -840), NORTH);

    roof2(11, 11, 6, PLANKS_SPRUCE);
})