Laser Maze Game in Python

In this Python programming challenge, we are going to recreate the game “Laser Maze”.

The aim is to redirect a laser beam across a given stage in order to reach the exit gate of the stage.

The laser can only travel in four directions:

  • Up
  • Right
  • Down
  • Left

The stage/maze is a 2D grid consisting of 12×12 tiles (including the outside walls of the room):

The following rules will apply when generating the stage:

  • The source of the laser beam will be randomly positioned on the left wall of the room and the laser will be aiming to the right.
  • The exit gate of stage will be randomly positioned on the right wall of the room.
  • 3 Bombs will be randomly placed on three tiles of the stage.

To solve the level, the user will have to place some reflectors on the stage using the following rules:

  • Reflectors can only be placed on empty tiles. They cannot be placed on existing walls, bombs, laser source or exit gate.
  • There will be two types of reflectors: // and \\ which will redirect the laser beam by 90 degrees either clockwise (\\) or anti-clockwise (//)

Structure Diagram (Decomposition)

Here is the structure diagram for our Laser Maze Game:

From this structure diagram, we can generate the following checklist:
Initialise 12×12 empty maze
Place Laser Source
Place Exit Gate
Place Bombs
Display maze
Player inputs row and column numbers and type of reflector
Place reflectors on the maze
Repeat process (for any additional reflectors)
Shooting: Start Laser Beam at Source
Trace laser in all four directions (right, left, up, down)
Detect collision with bombs
Detect collision with walls
Detect collision with laser source
Detect collision with exit gate
Detect collision with reflectors
Redirect laser beam (when laser collides with a reflector)
Output “Level Complete” message or “Game Over Message”

Python Code

We have started the code for our laser game but our code is incomplete. Your task is to complete this game to allow the user to solve the level by placing reflectors on the 2D grid to redirect the laser beam either clockwise or anti-clockwise.

Extension Task

Your extension task is to implement a scoring system.
At the start of the game, the user has 100 points.
Each reflection wall used costs 20 points.
Once a level is complete, the user should earn 50 points.
Once a level is complete, the user should automatically be presented with a new level.
The game stops when the user hits a wall or a bomb.



The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Did you like this challenge?

Click on a star to rate it!

Average rating 3.3 / 5. Vote count: 51

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: