Assignment 5
- Simple Factory Pattern -
The objective of this assignment was to create a game feature with Unity and C# that uses an implementation of the simple factory design pattern.
Play the Game
UML Diagram
- Unique Coin Creation -
Utilizing Simple Factory
Questions and Answers
1. Briefly, what was the game feature you chose to create?
I chose to create the game feature of spawning various types of coins. I got the inspiration from the Super Mario games.
​
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 collect coins so I can increase my score.
​
3. What does the player do in the game that creates an object of a specific type?
The player left clicks on the coin boxes, spawning a coin of the appropriate type. The player score is increased based on the coin spawned.
​
4. What determines which object is created (with the Simple Factory design pattern) while the game is running? Does the player choose the object or does the game choose the object based on something the player does? In other words, what sets the condition that is checked by the factory?
The condition set by the factory is the type of coins the coin box is set to spawn. I have that stored as an enum that can be set in the inspector. At runtime, the color of the box is changed to match what type of coin will spawn, and when the box is clicked on the appropriate coin will spawn.
​
5. What were the benefits of using the Simple Factory Pattern to make your Unity Project implement a game feature?
I really like the concept of encapsulating retrieving prefabs to another class. It helps keep things centralized, less cluttered, and easier to understand.
​
6. Did you find any drawbacks to using the Simple Factory Pattern? If so, what were they?Looking back on it, I felt that the simple factory came in handy. With it, I don’t have to assign all of the types of coins into each CoinBox. Instead, I can keep all of that inside of the CoinFactory, call upon the CreateCoin method with a specified coin type, and get the coin I need.
​
7. How is the goal of the game feature communicated to the player in your unity project?
The goal of the game feature is indicated by the score text at the top of the screen and the on-screen controls. The player will quickly grasp that they need to click on the coin boxes to increase their score.
​
8. How are the controls required to use the game feature you created communicated to the player in your unity project?
The only control is the left mouse button to click on the boxes. This is displayed to the player on screen.
​
9. How does the game communicate to players whether or not they have successfully used the game feature?
Coins are spawned above the coin box, and the score is increased.