top of page

Assignment 4

- Decorator Pattern -

The objective of this assignment was to create a game feature with Unity and C# that uses an implementation of the decorator design pattern.

Play the Game

UML Diagram

- Crop Creation System - Utilizing the Decorator Pattern


Questions and Answers

1.    Briefly, what was the game feature you chose to create?
The game feature I created was a farm, consisting of spawnable crops and a crop list that keeps track of all of the crops on that farm.

2.    What is the player able to do with the game feature you chose to create? What goal are they able to achieve with it and for what purpose?
As a player, I want to place crops and keep track of the ones I place so I can create a nice looking farm.

3.    What does the player do in the game that creates an object of a type that can be decorated?
The farmland is the object that is decorated, and the crops are what it is decorated with. This object is pre-placed for the player; they are provided with a set of land they can start placing crops on.

4.    What does the player do that adds a decorator to that object (with the decorator design pattern) while the game is running?
The player presses numbers 1-4 to add crops to the farmland. When a key is pressed, the farmland object is decorated with that type of crop. I decided to simplify the process by using Generics. For example, in the Farm class I created a method AddCrop<T>(FarmLand farmLand). I can pass in the type of crop T and the FarmLand to add the crop to. This decorates the farmLand with a crop of type T.

5.    What does the decorator do to change the object it decorates?
The decorator adds crops to the farmland, increases the farmland’s crop count, and updates the farmland’s description. This means each farmland has its own crop count, description, and boundaries for spawning its crops in.

6.    What were the benefits of using the Decorator Pattern to make your game feature?
The decorator pattern helped reduce repetition in my code and made what I was trying to accomplish easier to understand, both when writing the code and reviewing it after completion.

7.    Did you find any drawbacks to using the Decorator Pattern?  If so, what were they?
My main concern is if using the decorator pattern here was really necessary. After completing the assignment, I felt that I easily could have kept an array of crops in the FarmLand class and updated the crop count in that class instead of using the decorator pattern’s recursion of adding 1 to the crop count and returning the sum.

8.    How is the goal of the game feature communicated to the player in your unity project?
The goal is communicated to the player by the inclusion of a controls list and an empty farm enclosure. From there, the player can press buttons to spawn in crops, adding them to the farm and the crops list.

9.    How are the controls required to use the game feature you created communicated to the player in your unity project?
The controls are listed in the upper right hand corner of the screen via UI elements.

10.  How does the game communicate to players whether or not they have successfully used the game feature?
Players will know they have successfully placed a crop in the enclosure because a crop will spawn and the crop list will get updated.


Kyle Grenier

Immersive Technology and Game Developer

bottom of page