Bhodi's Tutoring - Dead by Daylight Edition
Example 1: Survivor Role (Python)
Survivor Class: Interacting with Generators
This example shows how you might define a Survivor in Python, using basic class syntax. Survivors in Dead by Daylight have attributes like life, speed, and can interact with Generators. Here’s a more advanced class to represent a Survivor:
# --- Now, let's update our Survivor blueprint to interact with Generators ---
class Survivor:
"""
This is our 'blueprint' for a Survivor.
It's similar to before, but now Survivors can fix Generators!
"""
def __init__(self, survivor_name_text):
"""
This sets up a new Survivor.
"""
self.name = survivor_name_text # String
self.life = 2 # Integer
self.speed = 10.0 # Float
self.is_alive = True # Boolean
print(f"--- A new Survivor named {self.name} has been created! ---")
self.show_current_status() # Show their starting stats!
def show_current_status(self):
"""
This function shows the current values of our Survivor's variables.
"""
print(f"Status for {self.name}:")
print(f" Life Points: {self.life}")
print(f" Movement Speed: {self.speed} units/sec")
print(f" Is Alive?: {self.is_alive}")
# Notice: We removed generator_progress from Survivor, because it's now on the Generator itself!
print("--------------------")
def take_damage(self, amount_of_damage):
"""
This function makes the Survivor take some damage.
"""
print(f"{self.name} is taking {amount_of_damage} damage!")
self.life = self.life - amount_of_damage
if self.life <= 0:
self.is_alive = False
print(f"!!! {self.name} has run out of life and is no longer alive! !!!")
else:
print(f"{self.name} still has {self.life} life points left.")
self.show_current_status()
def boost_speed(self, multiplier):
"""
This function makes the Survivor faster!
"""
print(f"{self.name} is getting a speed boost!")
self.speed = self.speed * multiplier
print(f"{self.name}'s new speed is {self.speed} units/sec.")
self.show_current_status()
def heal_up(self):
"""
This function makes the Survivor recover some life.
"""
print(f"{self.name} is healing!")
self.life = self.life + 1
print(f"{self.name} now has {self.life} life points.")
self.show_current_status()
def repair_generator(self, target_generator, skill_check_success: bool):
"""
This function simulates a Survivor repairing a generator.
It now takes TWO inputs:
1. 'target_generator': This is a Generator object (like 'generator_A').
2. 'skill_check_success': A 'boolean' (True/False) if they hit the skill check.
"""
print(f"{self.name} is trying to repair {target_generator.name}...")
# First, let's check if the generator is already working.
if target_generator.is_working == True:
print(f"{target_generator.name} is already fixed and working!")
return # Stop the function here
# Now, we use an 'if' statement to check the 'skill_check_success' boolean.
if skill_check_success == True: # If the skill check was successful
print(f"{self.name} hit the skill check! Good job!")
target_generator.progress = target_generator.progress + 10 # Add 10 progress to the GENERATOR
print(f"{target_generator.name} progress increased to {target_generator.progress}%!")
else: # If the skill check was missed
print(f"!!! {self.name} missed the skill check on {target_generator.name}! Loud noise made! !!!")
target_generator.progress = target_generator.progress - 5 # Lose 5 progress from the GENERATOR
# Make sure progress doesn't go below zero
if target_generator.progress < 0:
target_generator.progress = 0
print(f"{target_generator.name} progress decreased to {target_generator.progress}%!")
# After changing the progress, let's check if the generator is now fully repaired!
if target_generator.progress >= 100:
target_generator.is_working = True # Set the Generator's 'is_working' to True
print(f"*** {target_generator.name} is now fully repaired and WORKING! ***")
else:
print(f"{target_generator.name} is not fully repaired yet.")
target_generator.show_status() # Show the updated Generator status!
self.show_current_status() # Also show the Survivor's status (unchanged by repair)