A digital game can give students the opportunity to learn and refine their object-oriented programming (OOP) skills which is a requirement at years 9–10. Students follow a problem-solving process to design, build and evaluate a digital game. They state the digital design problem and decompose it in order to develop a solution. They create an algorithm for the game and relate this to an OOP approach. As a group or in pairs they implement a solution to build a computer game using OOP principles. Finally, they evaluate the end product (the game) and the solution.
Flow of Activities
A digital game can test a user’s skill, provide them with a challenge and/or educate the user, all using game play.
The first step is to define the problem. Defining what the game is required to do enables us to identify the functional and non-functional requirements. At this point we also need to identify if there are any constraints or factors that should influence the nature of the game or how it is developed. How will the user interact – via a keyboard using arrow keys, a mouse or game console?
State the problem in terms of requirements. This will help in the process of designing an algorithm and, following that, to write the computer program.
Imagine we want a game where a superhero completes a challenge to gain points. If the superhero fails to complete the challenge in the allotted time, they lose a life. For each challenge, rewards are available for the superhero to increase their power. Their power starts to decrease as the challenge begins.
To make this game, we need to:
To incorporate the use of OOP language students will need to be familiar with how to use classes as a way of associating variables and functions. This will help students to clarify ideas in the design phase. Note in OOP, variables are often referred to as attributes and functions are referred to as methods.
Using the superhero game as an example, class ‘Superhero’ could include:
|Attributes (variables)||Methods (functions)|
|Power level||Gain power|
Other classes might include ‘Score display’, ‘Energy discs’ (for increasing power levels), etc.
Note: The programming language that students use to build the game will depend on students’ experience with general purpose programming languages. Note that Python on its own can be used to produce fairly rudimentary games in terms of a user interface. Students who want to include graphics can use the PyGame library by importing it at the start of the computer program.
An algorithm is a logical step-by-step process for stating how to create a digital solution. Algorithms are generally written as a flowchart or in pseudocode. A flowchart is a common way to visually represent an algorithm. Another relevant approach particular for games and apps is to do a storyboard which often focuses on the onscreen actions.
Pseudocode is a way of describing a set of instructions that does not have to use specific syntax. Students use structured English to express these instructions; for example, using ‘while’ and ‘endwhile’ when describing a ‘while loop’.
As they design the solution, students need to refer back to any constraints identified when they defined the problem, such as social and technical constraints. The design of the user interface and consideration of these constraints is referred to as user experience. Design of the user interface draws on design principles such as contrast, space, balance and repetition.
Select your superhero to start. Our superhero jumps from box to box to reach the life elixir (reward) to increase her life by 1. Along the way she captures energy discs to boost her power. She avoids the monster that guards the top box where the life elixir is stored. A collision with the monster results in a life lost. Three lives lost and the game is over.
Nouns Verbs superhero
It is a requirement that students in years 9 and 10 use an OOP. This will require a shift from a procedural programming approach to using OOP approaches.
OOP is a style of programming that focuses on using objects to design and build applications.
In OOP, objects represent a combination of data (the variables or attributes of an object) and the actions that can be performed on or with that data (the functions or methods of the object). An example might be the declaration of a ‘car’ which has attributes that describe its physical nature (such as the number of doors, its colour, the size of the engine) and methods for the actions it can perform (such as accelerating, braking and turning).
The attributes and methods of an object are defined by its class. Using a class, we can organise information as attributes so we can reuse these elements when making multiple instances of that data type.
A programmer could make three instances of a superhero, such as Batman, Wonder Woman and the Hulk, using the Superhero class to store similar information that is unique to each superhero. For example, they look different, have different levels of power, etc. The programmer could also associate the appropriate information with each superhero. The methods of the superhero might be to jump and collect tokens. Collecting tokens could replenish power levels.
Once students have developed their algorithm and mapped out the classes with their associated attributes and methods they can begin to implement their design by programming.
Rubrics can be used to assess the quality of the final product. In conjunction with the rubric, a peer review can be conducted with a suitable scaffold to provide feedback on the quality of the final product from a user’s perspective.
Student performance evaluation
As students progress through the task ask them to document their design solution, implementation plan, and any code reviews. Several pieces of evidence should be gathered to evaluate student performance. Peer reviews can also be a valuable tool.