kavabun

Day 13 – Implementing Strategy Pattern for Placement

Hi, I’m back again!

Today, I worked on building the Decor class.

The purpose of this class is to support objects that can be placed on top of tables, such as lamps, books, and later on, weapons (for weapon displays).
I needed a flexible system so players could place these smaller items during gameplay.


Challenges

I live-streamed for almost 4 hours, but it felt like I didn’t get much done at first. The main difficulty was that my placement system was too tightly hardcoded for Furniture class.

I needed a cleaner way to allow different object types (like Decor vs. Furniture) to define their own placement rules.


Strategy Pattern to the Rescue

To solve it, I implemented a Strategy Pattern:

Now, Decor and Furniture have their own strategies!

That said, the way strategies are currently built isn’t perfect yet —
DecorPlacementStrategy and FurniturePlacementStrategy still contain some redundant code, and it needs further refactoring.

At least for now, basic testing shows that it’s working, though there are still a few weird bugs I haven't figured out yet.


Future Plans

I want players to interact with Decors. For example:

Now that the interaction part is modular, I can easily extend and create more variations!


Unfortunately, I couldn't record a demo video this time. It got too late at night, and my son woke up suddenly, so I had to stop.

But progress is progress! I’ll try to record a demo video tomorrow!


Thanks for reading, and I hope to see you in the next post!

📬 Enjoying the journey?
Subscribe here to get my devlogs and updates delivered directly to your inbox!

✨ Also, check out regular development updates at my BHB Studios Blog!