Which pattern did you choose?
Object Pool Pattern
Why did you choose each pattern? (Justify your use of it).
I was initially uncertain as to what pattern to choose and was going to
incorporate the singleton and the private data class pattern, which I partially did, but
as was programing the doors for my game, I came to the realization that the object
pool pattern worked really well as an efficiently way to manage when the doors were
activated and were the doors were going to go.
The object pool pattern takes multiple instances of an object or in this case my
doors and has them reused by some sort of management program, in my case the map
manager itself. The map manager then tells them to activate or deactivate if a room is
adjacent to the current room on all sides and tells each door where to go if the player
uses them. The object pool works most efficiently when there are few instances of
reusable objects. So, in my case because the rooms never change size and there are
always four walls, I have only four doors spawn in the four needed locations at the
beginning of the game and activate or deactivate them when needed my the map
manager. Those four doors are then reused over and over again by my map manager
making my feature generally speaking quite efficient.
Draw the class diagram for your pattern(s):
Source Code
Based off
Would something else have worked as well or better than this pattern?
When would be a bad time to use this pattern?
The doors in Grombo’s Bad Day in their current implementation I do not believe could be seen as any other pattern, but there are lots of patterns that could have been used if I took a more traditional approach to them.
- For example, the builder pattern could have been used to place doors down in each room and as they were built providing them with their destination and location, then once the room is left, I could delete them and make new ones for the next scene.
- The Object Pool Pattern would be very difficult to implement or very complicated to implement if the rooms varied in size, shape and number of doors, the difficulty of making the game feel continuous and preserving the continuity of the players experience would be too difficult to handle for a single semester class. This task would require me creating specific door placement locations for potentially every
room and creating a map that could handle irregularly shaped rooms.