player1
Object A
Grog
Not createdhealth· / 100
- max_health
- ·
- is_defeated
- ·
Lecture 6 · Objects and classes
The class defines the rules.
Each object keeps its own state.
Run the walkthrough to create two separate objects from the same class.
selfplayer1player2player1 = PlayerCharacter("Grog", 100)Nothing printed yet
The idea to keep
player1.take_damage(30) uses the method defined by PlayerCharacter. Inside that call, self refers to the object named by player1.
The class is shared. Grog’s and Vex’s health values are not.
Make a prediction
Start with Grog at 100 and Vex at 80. Run player2.take_damage(50). What are their health values now?