Lesson 3: Classes Part 1 โ Attributes + Methods
Learning Intentions
- Introduce object-oriented programming โ the foundation for Pygame.
Success Criteria
- I can define a class with __init__ and 2+ methods.
- I've created 2+ instances of my class.
- I can explain what self refers to.
๐ Do Now โ Error of the Day
Fix this broken code: class Dog: def bark: print('Woof!') โ what's missing? (Three things.)
๐ I Do โ Teacher Demo
Live-code a Character class: (1) define class with def __init__(self, name, hp); (2) add take_damage method; (3) create hero + enemy instances; (4) show what self refers to.
๐ค We Do โ Build Together
Class builds together: Character class with 3 attributes + 2 methods. Create 2 instances. Have them attack each other once.
๐ You Do โ Your Turn
Arcade quests below focus on class creation + self. Then: write your OWN Character class with the attributes you want for your game. Test it runs.
- Build a Character class with name + hp + attack
- Write take_damage(amount) and is_alive() methods
- Create 2 instances: hero + enemy
๐ฎ Practice Quests โ work through these
Loading practice quests for this lesson...
Three tiers โ pick yours
Support
starter class with __init__ pre-written; fill in the methods. Visual diagram: class vs instance
Core
Follow the plan as written. Attempt the arcade quests above at your own pace.
Extension
Complete all quests above + try a Boss battle for bonus XP. Help a classmate if you finish.
Extensions
- Add an __str__ method for readable printing.
- Add a class-level counter tracking how many instances exist.
๐ Exit Ticket โ Coding Journal
Journal: what's one thing about classes that clicked for you today? What's still confusing?
Evidence of Learning
Student's character_class.py runs; hero and enemy can exchange attacks.