Answer To: ProblemDescription:...
Swapnil answered on Jul 15 2021
import PySimpleGUI as sg
import numpy as np
import math
import random
AppFont = 'Any 16'
sg.theme('DarkGrey5')
_VARS = {'cellCount': 10, 'gridSize': 400, 'canvas': False, 'window': False,
'playerPos': [0, 0], 'cellMAP': False}
cellSize = _VARS['gridSize']/_VARS['cellCount']
exitPos = [_VARS['cellCount']-1, _VARS['cellCount']-1]
def makeMaze(dimX, dimY):
starterMap = np.zeros((dimX, dimY), dtype=int)
for x in range(2):
randRow = random.randint(1, dimX)
randColumn = random.randint(1, dimY)
starterMap[randRow-1:randRow] = 1
starterMap[:, randColumn-1] = 1
for x in range(4):
starterMap[randRow-1][random.randint(0, dimY-1)] = 0
starterMap[random.randint(0, dimX-1)][randColumn-1] = 0
starterMap[0][0] = 0
starterMap[0][1] = 0
starterMap[1][0] = 0
starterMap[dimX-1][dimY-1] = 0
starterMap[dimX-1][dimY-2] = 0
starterMap[dimX-2][dimY-1] = 0
starterMap[dimX-2][dimY-2] = 0
return starterMap
_VARS['cellMAP'] = makeMaze(_VARS['cellCount'], _VARS['cellCount'])
def drawGrid():
cells = _VARS['cellCount']
_VARS['canvas'].TKCanvas.create_rectangle(
1, 1, _VARS['gridSize'], _VARS['gridSize'], outline='BLACK', width=1)
for x in range(cells):
_VARS['canvas'].TKCanvas.create_line(
((cellSize * x), 0), ((cellSize * x), _VARS['gridSize']),
fill='BLACK', width=1)
_VARS['canvas'].TKCanvas.create_line(
(0, (cellSize * x)),...