Question 15
AQA Computer Science June 2024 Paper 1C (8525/1C)GCSE8 marks
On the specification
- 3.2 Programming
Question text
15 A programmer is writing a game. box The game uses a row of cells represented as an array. Figure 20 shows an example. Figure 20 1 2 3 4 5 6 7 X X Figure 21 describes how the game is to be played. Figure 21 • The player starts at position 0 in a row of cells. • The aim of the game is for the player to reach the end of the row. • At each turn the player must enter either 1 or 2 o if the player enters 1, the player’s position increases by 1 o if the player enters 2, the player’s position increases by 2 • If the player’s position goes beyond the end of the row or contains an X: o the message Bad move is displayed o the player goes back to position 0 • These steps are repeated until the player reaches the end of the row. • If the player reaches the end of the row the game is finished. For example, using the array in Figure 20: • the player starts in position 0 1 2 3 4 5 6 7 X X • if the player enters a 1, then they move to position 1 1 2 3 4 5 6 7 X X • if the player then enters a 2, Bad Move is displayed as position 3 contains an X 1 2 3 4 5 6 7 X X Bad move • the player then goes back to position 0 1 2 3 4 5 6 7 X X • if the player then enters a 2, they move to position 2 1 2 3 4 5 6 7 X X • if the player then enters a 2, they move to position 4 1 2 3 4 5 6 7 X X • if the player then enters a 1, they move to position 5 1 2 3 4 5 6 7 X X • if the player then enters a 2, the game finishes. 1 2 3 4 5 6 7 X X Figure 22 shows part of a VB.NET program that will be used for the game. box Figure 22 Dim pos As Integer = 0 Dim lastPos As Integer = row.Length - 1 While pos < lastPos pos is a variable that contains the player’s current position. Extend the program from Figure 22 so that the game works as described in Figure 21, on page 37. When writing your program you should assume: • there is an array called row • the number of X characters in row can vary • the position of the X characters in row can vary • the X characters have already been added to the array called row • the row array can be of any length. You should use meaningful variable name(s) and VB.NET syntax in your answer. The answer grid below contains vertical lines to help you indent your code. [8 marks] Dim pos As Integer = 0 Dim lastPos As Integer = row.Length - 1 While pos < lastPos End While 8