so currently i'm trying to plot out a block maze by reading from a .txt file and then displaying it in Python's Turtle Library. Currently, my code is only able to draw out the boxes, but not the grid lines surrounding the boxes. Is there anyway to deal with this problem, cuze i tried to see the docs and they only suggested turtle.Turtle.fillcolor, which doesnt really seems right.
Here's my current code:
# import the necessary library
import turtle
# read the .txt file here!
with open("map01.txt") as f:
content = f.readlines()
content = [x.strip() for x in content]
# create the map here!
window = turtle.Screen()
window.bgcolor("white") # set the background as white(check if this is default)
window.title("PIZZA RUNNERS") # create the titlebar
window.setup(700,700)
# create pen
class Pen(turtle.Turtle):
def __init__(self):
turtle.Turtle.__init__(self)
self.shape("square")
self.color('grey')
self.penup()
self.speed(0)
# create maze_list
maze = []
# add the maze to maze
maze.append(content)
# create conversion from the list to the map in turtle
def setup_maze(level):
for y in range(len(level)):
for x in range(len(level[y])):
# get the character at each x,y coordinate
character = level[y][x]
# calculate the screen x, y coordinates
screen_x = -288 + (x * 24)
screen_y = 288 - (y * 24)
# check if it is a wall
if character == "X":
pen.goto(screen_x, screen_y)
pen.stamp()
# create class instances
pen = Pen()
# set up the maze
setup_maze(maze[0])
# main game loop
while True:
pass
And this is how the current text file i am reading from looks like:
XXXXXXXXXXXX
X.........eX
X.XXX.XXX..X
X.XsX.X.XX.X
X.X......X.X
X.XXXXXXXX.X
X..........X
XXXXXXXXXXXX
The 's' and 'e' are supposed to represent the starting point and the ending point, which is not implemented yet, so it can be ignored. The dots represent the path, and the X represents walls. The current map(or txt) dimension is 8 rows by 12 columns.
Right now my output looks like this:

I wanted it to look something like this(referring to the addition of grids, not the same pattern maze):



