top of page

Assignment 2

- Strategy Pattern -

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

Play the Game

UML Diagram

- Weapons system -

utilizing the strategy pattern

download.png

Questions and Answers

1.    What does the player do in the game that changes the behavior being used by a class (with the strategy design pattern) while the game is running?

The player controls a rocket ship that fires different lasers from a Weapon. At runtime, the player has the ability to swap between two different lasers - a red laser and a blue laser. The player’s Weapon has a WeaponBehaviour, and the RedLaser and BlueLaser are those two different behaviours.

​

2.    What changes in the game when the behavior of the client class changes?

The player weapon’s WeaponBehaviour changes, from a red laser to a blue laser, or vice versa.

​

3.    What were the benefits of using the Strategy Pattern to make your mini-game?

The strategy pattern really helped reduce the amount of times I copied and pasted code, made my code less coupled, 

​

4.    Did you find any drawbacks to using the Strategy Pattern?  If so, what were they?

It took a lot of thought to figure out what kind of “has-a” relationships I wanted to use and how I wanted to incorporate it. I had to refer to the book’s diagram with the Duck class as a reminder on how I should go about incorporating it. I’ve also been practicing on using more composition and using the single-responsibility principle, so that took some thought as well.

​

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

The player’s goal is to shoot the colored blocks with the similarly colored laser and reach a score of 1000. This is challenging because the blocks have a random amount of health (within the bounds of two numbers), and the colored block that spawns isn’t hard coded, so the player has to make sure they have the right laser color equipped to destroy the block in front of them.

​

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

The goal is communicated via a textbox at the start of the game. There is ample time for the player to read through the tutorial before the game starts and practice with the controls.

​

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

The player fails by running into a block. Once this happens, a textbox appears that lets the player know they can press ‘R’ to restart or ‘ESC’ to quit. Regardless of whether or not they die, the player can always press ‘R’ to ‘ESC’ mid game, and they’ll have the same effect. 

​

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

When the player switches weapon behaviours, their rocket changes color to signify what color they swapped to. Additionally, when they press the fire button, the laser shoots out in front of the rocket. Dealing damage is signified by the health of the blocks depleting, and is visible through the number inside of the block.

Kyle Grenier

Immersive Technology and Game Developer

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