Conclusion

After we setup CodeCraft, we can call function game.set_block() to build a block in CodeCraft world. It requires two input parameters in the parentheses: a Position(x, y, z) object and a number indicating the block material. For example:

game.set_block(Position(0, 1, -10), 2)

Just for your reference, here is the complete code to set up CodeCraft, display all the block materials(we'll learn that later), and build one obsidian block.

CodeCraft Setup Code, First Block:

# Python first block
# Setup up CodeCraft
from codecraft import Game, Position
game = Game()
materials = game.materials

print('Hello, CodeCraft!')
print(materials)

# Show all blocks
for i in range(len(materials)):
    game.set_block(Position(int(i / 4) * 2, 4 + (i % 4) * 2, -20), i + 1)

# First block, a black obsidian block

game.set_block(Position(2, 2, -10), 67)

Here is the screenshot after the program runs:

results matching ""

    No results matching ""