top of page

Assignment 8

- Template Method Pattern -

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

Play the Game


- Sports Action System -

Utilizing the Template Method Pattern

download (2).png

Questions and Answers

1.    What is the multi-step process you are implementing with the Template Method design pattern?

The multi-step process I implemented is the sequence of events that occur after a sports ball is kicked. These events involve getting the ball’s specific name, its kick force, and launching the ball.

2.    How is the process different across the subclasses that implement parts of the template method differently?

The subclasses override the abstract GetName() and GetKickForce() methods. This way, the template method, Kick(), in the abstract SportsBall class can focus on executing the right sequence of events, but each unique sports ball can send over any data it needs to (name, kick force, etc.).

3.    What does the player do in the game that determines whether or not one of the hooks you are using will call the method it is controlling?  In other words, what does the player do that triggers one of your hooks?

The player clicks and drags on one of the sports balls to wind up a kick. Once they release, they launch the sports ball. As previously described, the launch process involves getting the ball’s name and kick force. These two values are passed over to the Scoreboard via an event. From there, the scoreboard displays the ball’s name and the magnitude of the kick! Additionally, I added in a patriotic particle system for kicking the football. The Football class overrides the virtual Launch() method to include the instantiation of the particle system. The particles are displayed in front of the scoreboard.

4.    What were the benefits of using the Template Method Pattern to make your mini-game?

The template method pattern helped reduce the repetition of my code and created a central script to control the sequence of events that would occur after a sports ball is kicked. I really like the addition of hooks that concrete subclasses may or may not override.

5.    Did you find any drawbacks to using the Template Method Pattern?  If so, what were they?

For this particular project, I felt that instead of using the methods GetName() and GetKickForce() I could have just assigned them in the inspector using serialized private fields and used the Rigidbody’s mass to determine the “kick force”, so overall it felt like it wasn’t completely necessary for this project. Although some aspects of its use such as the Football overriding the Launch() method to instantiate a particle came in handy, and I can see how useful this can be outside of this project.

6.    What is the player’s goal in your mini-game and what makes it challenging?

The player’s goal is to hit the sporadically moving target 10 times with whatever ball they are given, but each ball has a different inherent kick force (which substitutes for the mass of the object), so the player has to make sure they don’t hit the ball too softly or too hard if they want to hit the target.

7.    How does the game communicate its goal(s) to the player?

The goal is communicated via an on screen tutorial that is displayed at the start of the game. This information is accessible via a button click at any point in the game.

8.    How can the player fail at the game and how does the game detect it?

The player fails at the game if they run out of lives, meaning the ball goes out of bounds, 3 times. The player can track their score via the in-game scoreboard. Once the lives counter drops to 0, the scoreboard will display “Game Over!” and the scene will be restarted.

9.    How does the game give players feedback about how well they are doing?

The in-game scoreboard keeps track of the player’s lives and score. Once the player reaches the winning score (10), the scoreboard will display “You Win!” and the scene will be restarted automatically. 

Kyle Grenier

Immersive Technology and Game Developer

bottom of page