Login

Please fill in your details to login.





d. the grid navigator

A coding challenge

Objective

Create a grid-based movement system using a 2D array. This will test your ability to manipulate multi-dimensional data structures and implement robust validation logic (bounds and collision checking).

Requirements

Initialise a 5x5 2D array (or list of lists) to represent a map.
Populate the grid using characters or strings:
Use . to represent empty, walkable space.
Use X to represent impassable obstacles (walls).
Use P to represent the player's starting position (e.g., row 0, column 0).
Write a game loop that asks the user for a directional command (W to move Up, S to move Down, A to move Left, D to move Right).
Implement boundary checking: before moving the player, ensure the new coordinate is not outside the 5x5 grid. If it is, block the movement and display an error message.
Implement obstacle collision: before moving, ensure the new coordinate does not contain an X. If it does, block the movement and display an error message.
Redraw the grid to the console after every valid move so the user can see their new position.

Stretch Goal

Add a 'Goal' tile (represented by a G) to the grid. If the player successfully moves onto the goal tile, display a victory message and end the loop.

Last modified: September 6th, 2026
The Computing Café works best in landscape mode.
Rotate your device.
Dismiss Warning