top of page

Assignment 6

- Factory Method Pattern -

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

Play the Game

UML Diagram

- Weapon Creation -

Utilizing the Factory Method Pattern

download (1).png

Questions and Answers

1.    Briefly, what was the game feature you chose to create?

I decided to create a weapon spawning system, where the player can choose between spawning in two different classes of weapons: Elvish and Dwarven weapons, each with unique stats, names, and models!

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 spawn in specific classes of weapons so I can use them in combat.

3.    What does the player do in the game that determines which Creator class is used to create objects?

The player presses TAB to switch between two different classes of weapons: Dwarven and Elvish. Once a class is selected, the player can press 1 or 2 to spawn in a sword or a bow respectively. The spawned weapon will be of the selected class with stats pertaining to that class.

4.    What determines which Product object the Creator class creates (with the Factory Method 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 method? 

The condition is the type of weapon the player selects to spawn, either a sword or a bow. These weapons are spawned in by either a DwarvenWeaponCreator or a ElvishWeaponCreator depending on the class the player has selected.

5.    What were the benefits of using the Factory Method Pattern to make your game feature?

I feel the factory method pattern helped follow good object oriented design principles, especially when it comes to the principle of “program to interfaces over implementations.”

6.    Did you find any drawbacks to using the Factory Method Pattern?  If so, what were they?Overall, I feel that my idea would be better suited for the Decorator pattern. I felt that my two weapon creator classes (DwarvenWeaponCreator and ElvishWeaponCreator) had almost entirely repeated code. The only thing that changed was the stats applied to the weapons that were created. After realizing this, I thought that maybe the Decorator pattern would be more beneficial. I could have an abstract Weapon class and decorate it with a class and stats.

7.    How is the goal of the game feature communicated to the player in your unity project?

The goal is communicated through the in-game UI. When a player spawns in a weapon, the UI gets updated with that weapon’s stats, name, durability, etc. Also, the controls help communicate to goal to the player.

8.    How are the controls required to use the game feature you created communicated to the player in your unity project? 

Controls are on-screen in the top-right corner.

9.    How does the game communicate to players whether or not they have successfully used the game feature?  

The player knows they have succeeded in using the game feature because an Elvish or Dwarven sword or bow will spawn depending on the player’s selections. Each class has a unique model for each type of weapon. This will quickly become evident to the player.

Kyle Grenier

Immersive Technology and Game Developer

app-icon.png
GitHub-Mark-Light-64px.png
LinkedIn_icon_circle.png
bottom of page