Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##Takaoka_Ian_Proj4.py
- ##INF120: Elementary Programming
- from random import*
- def escapemaze():
- ##Here the user is prompted to select a proper maze file, and displays it.
- choose=pickAFile()
- maze=makePicture(choose)
- show(maze)
- ##These variables define the parameters of the maze as it will work with any maze provided.
- ##This is divided by half in order to discern the starting point of the robot.
- h=getHeight(maze)
- w=getWidth(maze)
- y=h/2
- x=w/2
- ##This places our robot on the maze.
- pix = getPixelAt(maze, x, y)
- repaint(maze)
- ##These are the variables for the winning conditions. Later on these can be edited in order to win or lose the game.
- boom=0
- beamedUp=0
- outside=0
- ##This while statement tells the robot what to do while still within the boundaries, and when it hasn't hit the obstacles.
- while (outside == 0 and beamedUp == 0 and boom == 0):
- xOld= x
- yOld= y
- x = x + randrange(-5, 6)
- y = y + randrange(-5, 6)
- ##Dr. Hossain, getPixelAt here gives me an error once I reach the outside on my own, and I'm completely unsure why.
- pix = getPixelAt(maze,x,y)
- color = getColor(pix)
- ##This if statement tells the program whether to trigger the winning conditions, or what to do when it hits the walls.
- if (x < 0 or x >= w or y < 0 or y >= h):
- outside = 1
- elif color== black:
- x = xOld
- y = yOld
- elif color== red:
- boom = 1
- elif color== blue:
- beamedUp = 1
- addLine(maze, xOld, yOld, x, y, magenta)
- repaint(maze)
- ##This if statement tells the program what to do once it's hit either the teleporter or reached the outside on its own
- if (outside==1 or beamedUp==1):
- showInformation("LET'S GET OUT OF HERE, MAN!")
- showInformation("Game Over.")
- else:
- showInformation("BOOM!")
- showInformation("Game Over.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement