Skip to content

Course home

Programming concepts

Programming concepts

EasyMediumHard
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
Question 48

A game developer is creating a text-based adventure game where a player navigates through a hazardous cave represented as an array.

Figure 1: Example cave array

Index012345678
Content##

Figure 2: Game Rules

  • The player begins at index 0 of the cave array.
  • The goal is to reach the final index of the array (lastPos).
  • At each turn, the player is prompted to enter a movement value: 1, 2, or 3.
    • The player's position is increased by the inputted movement value.
  • If the player's new position exceeds the final index of the array, or lands on a index containing the trap character '#':
    • The message "Trap triggered!" is displayed.
    • The player's position is reset to 0.
  • These steps repeat until the player successfully reaches (or lands exactly on) the final index of the array.

Figure 3: Starting Code

pos = 0
lastPos = len(cave) - 1
while pos < lastPos:

Extend the program from Figure 3 so that the game works as described in the rules in Figure 2.

When writing your program, you should assume:

  • There is an existing array called cave.
  • The number of '#' characters in cave can vary.
  • The positions of the '#' characters in cave can vary.
  • The '#' characters have already been initialized in the array.
  • The cave array can be of any length greater than 1.

You should use meaningful variable names and correct programming syntax in your answer.

[8]
Markscheme

Programming concepts Questions

  1. GCSE
  2. /Computer Science
  3. /Programming concepts

298 exam-style questions on AQA GCSE Computer Science Programming concepts. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank