Skip to content

Python! Pet Simulator Game | Lectures 18

Lecture 18 OOP Project Pet Simulator

Let’s Start Python Programming for Beginners to Advanced. OOP Project – Pet Simulator Game, Lectures 18

🐍 Lecture 18: OOP Project – Pet Simulator Game

🎯 Goal

By the end of this lecture, you will:

  • Understand how to apply Object-Oriented Programming (OOP) in a real-world project.
  • Be able to create and manage multiple objects from a class.
  • Build a fun Pet Simulator Game where you can feed, play with, and track your pet’s happiness and hunger.
  • Learn how to organize code using classes and methods.

🧠 What Are We Building?

We’re going to build a Pet Simulator Game, where:

  • You can create a virtual pet.
  • Feed it, play with it, and keep it happy.
  • Track its mood over time.

This project will help you practice:

  • Creating classes
  • Defining methods
  • Using attributes
  • Managing object states

πŸ› οΈ Step-by-Step Plan

Step 1: Define the Pet Class

We’ll create a Pet class with attributes like name, hunger, and happiness. It will also have methods like feed() and play().

class Pet:
    def __init__(self, name):
        self.name = name
        self.hunger = 50   # 0 = full, 100 = hungry
        self.happiness = 50  # 0 = sad, 100 = happy
    
    def feed(self):
        if self.hunger > 10:
            self.hunger -= 20
            print(f"{self.name} is eating. Hunger decreased.")
        else:
            print(f"{self.name} is already full!")
    
    def play(self):
        if self.happiness < 90:
            self.happiness += 10
            print(f"{self.name} is playing. Happiness increased.")
        else:
            print(f"{self.name} is already super happy!")
    
    def status(self):
        print(f"\n{self.name}'s Status:")
        print(f"Hunger: {self.hunger}")
        print(f"Happiness: {self.happiness}")
Step 2: Create Your Pet Object

Now let’s create an instance of the Pet class:

my_pet = Pet("Buddy")
Step 3: Interact with Your Pet

Use the methods to interact with your pet:

my_pet.status()
my_pet.feed()
my_pet.play()
my_pet.status()
Step 4: Make It Interactive!

Let’s make a simple menu so users can choose what to do:

print("Welcome to the Pet Simulator!")

pet_name = input("What is your pet's name? ")
my_pet = Pet(pet_name)

while True:
    print("\nWhat would you like to do?")
    print("1. Feed")
    print("2. Play")
    print("3. Check Status")
    print("4. Quit")
    
    choice = input("Enter your choice (1–4): ")

    if choice == "1":
        my_pet.feed()
    elif choice == "2":
        my_pet.play()
    elif choice == "3":
        my_pet.status()
    elif choice == "4":
        print("Goodbye! Take care of your pet!")
        break
    else:
        print("Invalid choice. Please try again.")
Lecture 18 OOP Project Pet Simulator
Lecture 18 OOP Project Pet Simulator

πŸ§ͺ Try It Yourself!

Try adding more features to your game:

  • Add a method for sleeping or taking a nap.
  • Add a timer that increases hunger and decreases happiness over time.
  • Let users adopt more than one pet!

πŸ’‘ Sample Code for Sleeping:

def sleep(self):
    if self.hunger < 90:
        self.hunger += 10
        print(f"{self.name} took a nap. Hunger increased a little.")
    else:
        print(f"{self.name} is too hungry to sleep well.")

πŸš€ Challenge (Optional)

Add a mood checker that prints a message based on the pet’s current state:

def check_mood(self):
    if self.happiness >= 70 and self.hunger <= 30:
        print(f"{self.name} is feeling great!")
    elif self.happiness >= 50 or self.hunger <= 50:
        print(f"{self.name} is okay today.")
    else:
        print(f"{self.name} is unhappy. Try playing or feeding them.")

Call it after each action:

my_pet.check_mood()

πŸ§’ Kids Corner

🧠 Imagine you’re caring for a robot pet β€” just like a real animal! You have to feed it, play with it, and make sure it stays happy.

πŸ€– Robot says:

Beep boop! I'm hungry... and sad 😒
Can we play?

πŸ“Œ Summary

  • We built a Pet Simulator Game using Object-Oriented Programming.
  • Created a Pet class with attributes and methods.
  • Learned how to simulate pet behavior using object state changes.
  • Practiced user interaction and menu-based programs.
Stay Updated

If you found this information useful, don’t forget to bookmark this page and Share and leave your feedback in the comment section below.

Python! Inheritance | Lectures 17

Najeeb Alam

Najeeb Alam

Technical writer specializes in developer, Blogging and Online Journalism. I have been working in this field for the last 20 years.

Leave a Reply

Your email address will not be published. Required fields are marked *