In this challenge, we are looking at using a 2D Array to create the maze used in a Pacman Game.
Our 2D array will contains different numerical values to represents the corridors, walls and the pac-dots:
So in our 2D-array a corridor is represented using a 0, a wall using a 1 and a pac-dot using a 2.
maze = [[1,1,1,1,1,1,1,1,1,1,1,1,1], [1,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,1,1,0,1,0,1,0,1,1,0,1], [1,0,1,0,0,1,0,1,0,0,1,0,1], [1,0,0,0,1,1,0,1,1,0,0,0,1], [1,0,1,0,0,0,0,0,0,0,1,0,1], [1,0,1,0,1,1,0,1,1,0,1,0,1], [1,0,1,0,0,0,0,0,0,0,1,0,1], [1,0,0,0,1,1,0,1,1,0,0,0,1], [1,0,1,0,0,1,0,1,0,0,1,0,1], [1,0,1,1,0,1,0,1,0,1,1,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,1], [1,1,1,1,1,1,1,1,1,1,1,1,1]]
We can then easily add pac-dots in our maze using the following code:
maze[3][3] = 2 maze[3][9] = 2 maze[9][3] = 2 maze[9][9] = 2
We can then use a script to paint all the tiles of this maze on the screen. In this case we have done so using Python Turtle.
Python Code
Your Task
Your task is to add a piece of Python code to add four new pac-dots on this maze. These pac-dots should be randomly placed in the maze but not over a wall or an existing pac-dot.
Here is the flowchart for this algorithm:
Solution...
The solution for this challenge is available to full members!Find out how to become a member:
➤ Members' Area