At My Fingertips

Documentation

Pac-Man Maze

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.

pacman maze

The tiles

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.

Loading...

The straight tiles

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.

horizontal straight tile

vertical straight tile

Loading...

The corner tiles

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.

corner tile rotation 0

corner tile rotation 90

corner tile rotation 180

corner tile rotation 270

Loading...

The floor tiles

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.

    empty floot tile

  • If dot is True, then the tile should contain a white circle with diameter of 1/5 times the tile's size

    dot floor tile

  • If pill is True, then the tile should contain a white circle with diameter equal to the tile's size

    pill floor tile

  • dot and pill should never be both True

Loading...

Building a maze

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.

Mapping characters to tiles

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:

  • "|" to represent a vertical straight tile
  • "-" to represent an horizontal straight tile
  • " " to represent an empty floor tile
  • "." to represent a floor tile with a dot
  • "o" to represent a floor tile with a pill
  • "7" to represent a corner tile with rotation 0 (top right corner)
  • "C" to represent a corner tile with rotation 90 (top left corner)
  • "L" to represent a corner tile with rotation 180 (bottom left corner)
  • "J" to represent a corner tile with rotation 270 (bottom right corner)

These are just suggestions, you can choose different characters if you prefer.

Loading...

Mapping strings to a maze

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.

Loading...

Now you are able to efficiently create large mazes!

Extra

You can now experiment yourself, for example:

  • try adding a pacman tile, maybe represented by the character "P".
  • try adding tiles for oriented pacmans (looking left, right, up, or down), maybe represented by characters "l", "r", "u", "d"

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!

Loading...

This activity has been created by LuCE Research Lab and is licensed under CC BY-SA 4.0.

Pac-Man Maze

Logo of PyTamaro

PyTamaro is a project created by the Lugano Computing Education Research Lab at the Software Institute of USI

Privacy PolicyPlatform Version 79aacf0 (Fri, 08 Nov 2024 13:24:29 GMT)