At My Fingertips
Rapid Playground
In this activity you will need to implement different functions to create different tiles, that composed together can generate a pacman maze like the one below.
Each tile is a square with a black background, different tiles can have different patterns, let's go over each one.
Let's first implement a black_square
helper function that returns a black square of the given side
to use as the background of each tile.
Implement the straight_tile
function that generates a straight border tile that is horizontal if the value of boolean parameter horizontal
is True
, otherwise it should be vertical.
The blue line that goes over the straight tile should be centered and the thickness should be 1/5 of the tile's size.
Use the black_square
function you implemented.
Implement the function corner_tile
to generate a corner tile rotated according to the rotation
parameter, that represents the angle of rotation of the corner. The permitted values are 0, 90, 180 or 270.
The blue line should have thickness of 1/5 times the tile's size, and should pass through the middle of the sides.
Implement the function floor_tile
to generate a floor tile that can be empty or have a dot or a pill, depending on the value of parameters dot
and pill
.
If dot
and pill
are both False
, then the floor tile should be empty, therefore just a black square.
If dot
is True
, then the tile should contain a white circle with diameter of 1/5 times the tile's size
If pill
is True
, then the tile should contain a white circle with diameter equal to the tile's size
dot
and pill
should never be both True
To build a maze you can combine the previous solutions using above and beside, tile by tile. Unfortunately, it can take a lot of time to create a big maze.
We will now guide you through a more quick and easy way to do it.
Let's implement a char_to_tile
function that takes a character (a string of length 1) and returns the tile represented by that character.
Let's choose characters that look similar to the tiles that we want them to represent, for example, we used:
These are just suggestions, you can choose different characters if you prefer.
Let's implement a strings_to_maze
function that maps a list of strings to a whole maze. Strings are composed by characters, each string represents all the tiles in a row: each tile of a row should be placed beside the other. Each row should then be placed above the other.
Now you are able to efficiently create large mazes!
You can now experiment yourself, for example:
Remember that you have to map the tiles to a character in the char_to_tile
function, and run the code cells again.
Have fun!
This activity has been created by LuCE Research Lab and is licensed under CC BY-SA 4.0.
Pac-Man Maze
PyTamaro is a project created by the Lugano Computing Education Research Lab at the Software Institute of USI
Privacy Policy • Platform Version 79aacf0 (Fri, 08 Nov 2024 13:24:29 GMT)