Introduction
15 minThis lesson has no new blocks in it.
Everything you need you already have. Today is the first time you put all of it together on one build, and find out what eleven lessons adds up to.
What you are making
A maze. A real one, that somebody else can walk into and get lost in:
- an outer wall with a roof, so it is dark inside and you cannot cheat by flying over it,
- partition walls inside it, with gaps that make a path,
- an entrance and an exit on opposite sides,
- mobs loose inside it,
- and a backup copy, so that when somebody knocks a hole in it you can put it back.
Everything comes from somewhere
Nothing below is new. Each part is a lesson you have already done:
| The part | Comes from |
|---|---|
| the outer shell and the roof | Lesson 7 — fill, and hollow |
| building it where you stand | Lesson 8 — tilde positions |
| the partition walls, all alike | Lesson 3 — repeat |
| moving each partition along | Lesson 5 — a variable that grows |
| the doorways and the entrance | Lesson 7 — filling with air |
| the mobs inside | Lesson 9 — spawn, in a loop |
| repairing the damage | Lesson 10 — clone, and a master copy |
| keeping it readable | Lesson 11 — functions |
If any of those feels shaky, this is the lesson where it stops being an exercise and starts being a tool.
⚠️ About the monsters
Your world is set to Peaceful, and monsters will not survive in it.
You have two choices, and the program is identical either way:
- Keep Peaceful and release animals — cows, pigs, chickens. A maze full of livestock is funnier and just as good a test of your code.
- Change Difficulty to Easy in the world settings, and release zombies or skeletons. Do this only if your class is happy with it.
Decide before you start, because it is the one thing you cannot change from inside the program.
How to work today
This is 90 minutes on one build, not six small exercises. So:
- Plan on paper first. A maze is arithmetic, and arithmetic is much cheaper on paper than in the world.
- Build the shell before the details. Get the box right, then partition it.
- Make a backup as soon as anything works — Lesson 10 gave you the command for it.
- Name things as you go. By Challenge 3 the program is long enough that the names are what stop you getting lost in it.
Warm-up — walk one first
Before writing anything, sketch a maze on squared paper — a box, four or five walls inside it, and a path that winds from one side to the other.
Then count: how many walls, how far apart, where is each gap? Those numbers are your program. You are not designing as you type; you are copying out something you have already worked out.
Basic
20 minBuild this together. Everyone should finish this part with a maze you can walk into.
Step 1 — The shell
A maze is a box with a lid. You have built that before.
hollow gives you four walls, a floor and a roof, with nothing inside — which is exactly a maze waiting to happen.
Type maze and walk round the outside. It should be a solid, sealed block of stone, 25 by 25.
Step 2 — The way in and the way out
Two air fills, on opposite walls, two blocks high so a player fits.
The entrance is in the wall at ~0; the exit is in the wall at ~24, at the far end. Both are at ~1 to ~2 — the two blocks a player's body occupies.
Walk in. It is a dark empty room, and now it needs walls.
Step 3 — The partitions, with a loop
Here is where Lesson 3 and Lesson 5 come back.
Every partition is the same wall, in a different place. So: one fill in a loop, with a variable that moves it along each lap.
Four walls, at ~4, ~9, ~14 and ~19, each running almost the full depth of the box. Type walls and look down into it from above.
It is not a maze yet — it is a set of sealed corridors. Every wall needs a gap.
Challenge 1
15 minRelease the mobs.
An empty maze is a puzzle. A maze with something in it is a game.
- Press
Cand write a new function calledreleaseMobs. - Using a loop, spawn at least 10 mobs spread through the maze — not all in one spot.
- To spread them out, move the spawn position each lap with a variable, exactly as the partition walls moved in Basic.
- Every mob must start inside the maze and not inside a wall. The inside of the shell runs from
~1to~23. - Add a call to
releaseMobsat the end of yourmazecommand. - Type
maze, then walk in and find them.
Remember the warning about Peaceful in the Introduction. Animals work either way; monsters need the difficulty changed first.
It works if: at least ten mobs are alive inside the maze, spread across more than one section of it, none are stuck inside a wall, and none are outside the outer shell.
Challenge 2
20 minRepair the damage.
Somebody will break your maze. Probably you.
- Make sure your
backupcommand from Basic has been run, and that the master copy is safely out of the way. - Now damage the maze on purpose: blow a hole through two or three partition walls with an air fill, or delete a chunk of the roof.
- Walk in and confirm it is genuinely ruined — you should be able to walk straight through where a wall used to be.
- Write a command called
restorethat clones the master copy back over the broken maze and puts it exactly as it was. - Type
restore, then walk the maze again from the entrance.
Both commands use tilde positions, so where you are standing when you type them is part of the program. Work out how to make that reliable — Lesson 10's extra challenge ran into exactly this.
It works if: after wrecking the maze and typing restore, every wall is back, the path is walkable from entrance to exit again, and the master copy is still intact and ready to use a second time.
Challenge 3
25 minA maze to order.
Let the player say how big it should be, and have the program work out the rest.
- Press
Cand rewrite yourmazecommand so it takes a number. Rename itsize. - Guard it, as in Lesson 6: anything under 10 or over 40 gets a helpful message and builds nothing.
- The shell must be
sizeblocks across, and the partition walls must fit inside it — so how many walls there are has to be worked out fromsize, not typed in. A 12-block maze cannot hold four walls five apart. - Use if / else to make the maze change character with its size. For example: a small maze gets a few mobs and a big one gets many, or small mazes are built in stone and large ones in something darker.
- Try
maze 12, thenmaze 30, thenmaze 100, thenmazeon its own.
Step 3 is the real work. If the walls are five apart, the number of them is roughly size divided by 5 — and the Math drawer has a division block.
It works if: maze 12 and maze 30 both produce complete, walkable mazes of visibly different sizes with walls that fit inside their shells, the two are visibly different in character as well as size, and both maze 100 and a bare maze are refused with a message.
Extra challenge
spare timeOne command, five words.
Your maze program is now the longest thing you have written. Make it the clearest.
- Rewrite the whole project so that the
mazechat command contains nothing but function calls — no fills, no spawns, no loops, no variables. - Every job gets its own named function: the shell, the partitions, the doorways, the mobs, the backup. Five or so in total.
- No function may be longer than about twelve blocks. If one is, it is doing two jobs — split it.
- Any function that needs to know the size must take it as a parameter, rather than reading a variable you set somewhere else.
- Show someone who has not seen your program only the chat command, and ask them what it builds.
It works if: the maze builds exactly as it did before, the chat command reads as a list of what happens, and your reader can describe the maze without opening a single function.
Why this is the last thing you do today
You have just written a program with a shell, partitions, doorways, mobs, a guard, a size and a backup. That is more moving parts than anything else in Section 1.
Left as one long list of blocks, it is unreadable within a week — including by you. Broken into five named jobs, it stays understandable for as long as the names are honest.
Every lesson from here builds something bigger than this one. The habit you finish today with is the one that decides whether that is enjoyable or miserable.