top of page

Assignment 7

- Command Pattern -

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

Play the Game

UML Diagram

- Customizable Control Panel -

Utilizing the Command Pattern

CIS497 Assignment 7 - Command

Questions and Answers

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

I chose to create an in-game control panel that can execute any command deriving from the ICommand interface. I was inspired by a co-op level in Portal 2 where one player uses a control panel to manipulate a maze while the other player has to navigate through it.

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 manipulate the game environment so I can navigate the level in new ways.

3.    What does the player do in the game that determines which Concrete Command is executed on a receiver?

The player presses numbers 1-4 corresponding to each button on the control panel to rotate through all of the available commands. The currently selected command is displayed above each button. When the player left clicks on the button, the command is executed.

4.    What determines which Receiver class receives the command?  Does the player choose the Receiver somehow or does the game choose the Receiver?  In other words, what sets the Receiver that the Command is executed on? 

The player does not select the receiver themselves. Right now, there is only one Room object, but my intention is that each control panel (RemoteControl is the script name) is associated with a particular Room, and that room holds all of the objects that the player can manipulate via the control panel. For example, the Room has methods such as GetLight() and GetHoverPad() that returns the light and hover pad associated with that room. This can be expanded further with a more generic method such as GetInteractable(string name) and that will return the interactable with that name. In this game feature, however, there is only one room with one light and one hoverpad. These were set by me in the inspector.

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

The command pattern came in very useful to program in a wide variety of commands into a single control panel. If I can program the computer to do something (like the CommandFactory to load all of the possible commands into an array) so I don’t need to hardcode anything I will try my best to implement that! I think that makes the software more modular and expandable anyway.

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

The main thing I struggled with is how I wanted to go about instantiating new commands - did I want to use a CommandFactory like I wound up going with or hardcode a switch statement that would determine which command to instantiate? I like the CommandFactory approach because A) I don’t need to hardcode a switch statement to determine which command to instantiate and B) I can implement a method like GetNextCommandName() to return the name of the next command in the array of available commands. That way, the button can execute a variety of commands at runtime based on the player’s inputs and I don’t need to hardcode in new commands that could get added in the future - I just create the command, have it derive from ICommand, and place it in the Resources/Commands folder!

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

The goal of the feature is communicated via in-game UI that displays the instructions and controls.

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

The controls are communicated to the player via in-game UI.

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

Once the player rotates between commands by pressing 1-4, the text above the corresponding button will change to display the newly selected command. Once the button is pressed, the player will see the result of the command’s execution in affect the environment, whether it be a light lighting up a tiny shack or a hover pad turning on and levitating a cube.

Kyle Grenier

Immersive Technology and Game Developer

bottom of page