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

game.setBlock(new 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:

//JS,  First Block

//Setup up CodeCraft
let game = new Game();
let materials = game.materials;

console.log("Hello, CodeCraft!");

// show all blocks
let length = Object.keys(materials).length;
for (let i = 0; i < length; i++) {
  game.setBlock(new Position(Math.floor(i / 4)*  2, 4 + (i % 4)*
  2, -20), i + 1);

// First block
game.setBlock(new Position(0, 3, -20), 67);

Here is the screenshot after the program runs:

results matching ""

    No results matching ""