Learn how to solve all the levels of the Google's Blockly Maze (introduction to loops and conditionals).


Google's Blockly Games is a series of educational games that teach programming. It is based on the Blockly library. All code is free and open source. The Maze Game is an introduction to loops and conditionals. It starts simply, but every level is more challenging than the last. The game engine and source is available as an open source project at Github here.

In this article we'll share with you the solution to all 10 levels available in the Maze Game of Blockly.

Level #1

Stack a couple of 'move forward' blocks together to help me reach the goal.

Google's Blockly Programming Level 1

The respective JavaScript code of this level is:

moveForward();
moveForward();

Level #2

Google's Blockly Maze Game Level 2

The respective JavaScript code of this level is:

moveForward();
turnLeft();
moveForward();
turnRight();
moveForward();

Level #3

Google's Blockly Maze Game Level 3

The respective JavaScript code of this level is:

while (notDone()) {
  moveForward();
}

Level #4

Google's Blockly Maze Level 4

The respective JavaScript code of this level is:

while (notDone()) {
  moveForward();
  turnLeft();
  moveForward();
  turnRight();
}

Level #5

Google's Blockly Maze Level 5

The respective JavaScript code of this level is:

moveForward();
moveForward();
turnLeft();
while (notDone()) {
  moveForward();
}

Level #6

Google's Blockly Maze Level 6

The respective JavaScript code of this level is:

while (notDone()) {
  moveForward();
  if (isPathLeft()) {
    turnLeft();
  }
}

Level #7

Google's Blockly Maze Game Level 7

The respective JavaScript code of this level is:

while (notDone()) {
  moveForward();
  if (isPathRight()) {
    turnRight();
    moveForward();
  }
}

Level #8

Google's Blockly Maze Game Level 8

The respective JavaScript code of this level is:

while (notDone()) {
  if (isPathLeft()) {
    turnLeft();
  }
  if (isPathRight()) {
    turnRight();
  }
  moveForward();
}

Level #9

Google's Blockly Maze Game Level 9

The respective JavaScript code of this level is:

while (notDone()) {
  moveForward();
  if (isPathForward()) {
    moveForward();
  } else {
    if (isPathLeft()) {
      turnLeft();
    } else {
      turnRight();
    }
  }
}

Level #10

Can you solve this complicated maze? Try following the left-hand wall. Advanced programmers only!

Google's Blockly Maze Game Level 10

The respective JavaScript code of this level is:

while (notDone()) {
  if (isPathLeft()) {
    turnLeft();
  }
  moveForward();
  if (isPathLeft()) {
    turnLeft();
  }
  moveForward();
  if (isPathRight()) {
    turnRight();
    moveForward();
  }
}

Happy coding !


Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Sponsors