- Composite Pattern -
The objective of this assignment was to create a game feature with Unity and C# that uses an implementation of the composite design pattern.
Play the Game
- Extendable Power Up System -
Utilizing the Composite Pattern
Questions and Answers
1. Briefly, what was the game feature you chose to create?
The game feature I chose to create is a powerup system. This system is quite modular because I’m using the composite pattern to create groups of powerups that call upon individual powerups to accomplish some effect.
2. What is the player able to do with the game feature you chose to create?
As a player, I want to powerup my character so I can become stronger.
3. What are the composite and leaf objects in your Unity Project implementing a game feature?
The composite and leaf objects both implement the abstract PowerUpComponent class. The leaf objects are the individual powerups (health increase, strength increase, etc.) and the composite objects are the PowerUpContainer objects, which hold groups of power ups.
4a. In the starting UML class diagram above, there is an operation() method that is shared by the Leaf and Composite objects. Your code needs to iterate through and call this method you create on all of the leaf and composite items.
What is one method your code calls on all of your leaf and composite items?
This operation() method is renamed to Activate() in my program. The Activate() method calls upon the powerup to invoke its particular behaviour, whether it be applying a health buff or a mana buff, for example.
4b. What visible effect does this method have on objects in the game?
Not only does text change to show the player their change in stats, including a pop up text with how much the stat increased, but there are also icons that symbolize the powerups the player has activated that are displayed.
4c. What triggers this method in the game?
The player triggers this method via keyboard input.
5. What were the benefits of using the Composite Pattern to make your game feature?
The composite pattern helped keep my code flexible so I can create a bunch of individual powerups and create stronger, larger buffs that is composed of those smaller powerups in addition to using those smaller powerups by themselves.
6. Did you find any drawbacks to using the Composite Pattern? If so, what were they?
I wondered if I really needed to use the composite pattern for this example, but I think overall it’s pretty beneficial because of how flexible creating new powerups is!
I also had trouble going about organizing and structuring my program, but I referred back to the textbook example code for inspiration and help.
7. How is the goal of the game feature communicated to the player in your unity project?
The goal is communicated via on-screen text.
8. How are the controls required to use the game feature you created communicated to the player in your unity project?
Controls are communicated via on-screen text.
9. How does the game communicate to players whether or not they have successfully used the game feature?
Players will know that they successfully used the game feature because they will see their stats change and other elements pop up on their screen highlighting their change in stats.
The player will know they used the game feature once a shape is drawn to the screen.