Boot up
Start a brand-new game from an empty file, using only what you learnt in the summer.
Your mission
The power grid died three years ago. WARDEN, the machine network, sends robots through what's left of the city. This week you write the opening of Dead Grid: a title screen, a survivor with stats, a dangerous first choice and three nights of patrols.
There's no new syntax this week. Everything you need, you've already used. The difference is the empty file: nobody hands you a pattern to copy.
New this week
- Planning before coding
- A structure diagram
- Starting from a blank file
You'll reuse
print(),input(), variablesif,elif,elserandom.randint()andforloops- Lists, functions and
whilevalidation
Plan before you type
Big programs are built from small parts. Breaking a problem into parts is called decomposition, and a structure diagram is how you draw it: the whole game at the top, its parts underneath, and the jobs inside each part below that.
Dead Grid
┌──────────────┬──────┴───────┬──────────────┐
Start First choice Nights Ending
┌────┴────┐ ┌────┴────┐ ┌────┴────┐ ┌──┴──┐
Title Survivor Menu Check Roll Lose Status Message
screen stats choice dice health
Each box near the bottom is small enough to code and test on its own. Code one box, run it, then move to the next.
Set up your folder
- Make a folder called
dead-grid. - Create
dead_grid.pyinside it. This is the file you'll grow all term. - At the end of each week, save a copy as
week01.py,week02.pyand so on. If you break something next week, you can always go back.
Use the same Python and editor as the summer. If you're on a new computer, ask your teacher before installing anything.
Try it
Warm up from memory, about 10 minutes
Without looking at the summer course, write a program that:
- asks for the survivor's name,
- stores
energyas 10, - takes 3 away from
energy, - prints the name and the energy left.
Predict the output before you run it.
Name: Kai
Survivor: Kai
Energy left: 7Done when it runs and matches your prediction.
Main mission
Write the opening scene, about 1–2 hours
Build these in order. Run the program after each one.
- A
show_title()function that prints the game's title. Call it. - Ask for the survivor's name. Store
health(100),energy(10) and akitlist with two items. Print the kit with aforloop. - A
show_status(name, health, energy)function that prints all three values. Call it. - A menu of three escape routes. A
whileloop must keep asking until the player types 1, 2 or 3. - Each route changes at least one stat. One route adds an item to the kit with
append(). - Three nights, using a
forloop. Each night, rollrandom.randint(1, 6). If the roll beats astealthvalue, a Hunter spots you and you lose health. - Show the status again, then an ending message that depends on how much health is left.
========================================
D E A D G R I D
========================================
The power grid died three years ago.
WARDEN's machines patrol what is left.
Survivor, what do they call you? Kai
Welcome to the ruins, Kai
You are carrying:
- torch
- water bottle
...
Choose 1, 2 or 3: 4
No time for that. Pick a real route.
Choose 1, 2 or 3: 1
It's wet and dark, but the drones can't see you down here.
You need to cross the district before dawn.
Night 1
The patrol passes. You keep moving.
Night 2
A Hunter unit spots you! You get away, but not cleanly.
Night 3
The patrol passes. You keep moving.
...
Kai reaches the edge of the district. The real journey starts now.Done when all seven parts work, including a wrong menu choice.
Exam corner
On paper, about 15 minutes
- Draw a structure diagram for your game with at least three levels.
- Sketch your city on squared paper: five squares by five. Name each square or mark it as rubble. You'll need it in week 3. (You can copy the map at the top of this page.)
- Exams use pseudocode: code-like writing that isn't any one language. Here's a validation loop for an age:
Now write the pseudocode for your route menu's validation loop.
Done when all three are on paper. Bring them to show and tell.
Solo mission
Stretch yourself
Make the route choice matter later on. The route should change stealth: the drains make you harder to spot, the rooftops easier. Then add a random event to the nights: on a roll of 1, you find a battery and add it to your kit.
Done when route choice changes what happens at night.