Lecture 6 · Objects and classes

Crystal Run

Edit the class. Create your character.
Escape the sentries.

Your code runs the game

Your next escape

First contact

Your code

Build your escape.

PYTHON
Python loads when you run

Loading the starter code

1

Define a class

These rules belong to every Character.

character.py
2

Create your objects

Give each character its own name, health and power.

Arguments follow the parameters in your __init__ method.You control hero. The sentries move automatically.

Run mission creates three fresh objects. Edits are saved in this browser.

Ctrl or ⌘ + Enter runs your code. Tab indents. Esc then Tab leaves the editor.

Make the hero your own

Change the hero constructor call, then run the mission and inspect the three objects.

Expected result

The hero changes while the two sentries keep their own constructor values.

Ask an object Try a Python statement
Run the mission to create your objects.

Collect every power cell and reach the portal. You decide whether to dodge or fight.

LIVE SIMULATION
0 / 3cells
0turns
1medkits

One hero. Your rules.

Ready for an escape?

Collect the power cells, outsmart the sentries and reach the portal. Your Python creates every character.

Take your time. Sentries move only after your turn.

Power cellMedkitLaserExit

↑←↓→or WASD

Walk into a sentry to attack. A red warning means it will attack next turn if you stay beside it.

Run the mission to create your hero and the two sentries.

One class. Three objects.

Your best escape will appear here

All three come from the same class. Constructor arguments customize each object.

You controlReady

Nova

hero
Character("Nova", 100, 25)
Health100 / 100
Power25Shield0
More attributes
Automatic sentryPatrol

Rust

guard1
Character("Rust", 45, 14)
Health45 / 45
Power14Shield0
More attributes
Automatic sentryPatrol

Bolt

guard2
Character("Bolt", 60, 18)
Health60 / 60
Power18Shield0
More attributes

What your code just did

An action is a method call.

Each character is a separate object. A method call changes the object it receives.

CALLRun the mission to begin
OUTPUT
Your Python has not run yet

Back to the lecture

Keep experimenting.

Follow the original character example in the walkthrough, or run the practice problems in the notebook.