Advertisement
itak365

Untitled

Mar 21st, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. ##Takaoka_Ian_Proj4.py
  2. ##INF120: Elementary Programming
  3. from random import*
  4. def escapemaze():
  5. ##Here the user is prompted to select a proper maze file, and displays it.
  6. choose=pickAFile()
  7. maze=makePicture(choose)
  8. show(maze)
  9. ##These variables define the parameters of the maze as it will work with any maze provided.
  10. ##This is divided by half in order to discern the starting point of the robot.
  11. h=getHeight(maze)
  12. w=getWidth(maze)
  13. y=h/2
  14. x=w/2
  15. ##This places our robot on the maze.
  16. pix = getPixelAt(maze, x, y)
  17. repaint(maze)
  18. ##These are the variables for the winning conditions. Later on these can be edited in order to win or lose the game.
  19. boom=0
  20. beamedUp=0
  21. outside=0
  22. ##This while statement tells the robot what to do while still within the boundaries, and when it hasn't hit the obstacles.
  23. while (outside == 0 and beamedUp == 0 and boom == 0):
  24. xOld= x
  25. yOld= y
  26. x = x + randrange(-5, 6)
  27. y = y + randrange(-5, 6)
  28. ##Dr. Hossain, getPixelAt here gives me an error once I reach the outside on my own, and I'm completely unsure why.
  29. pix = getPixelAt(maze,x,y)
  30. color = getColor(pix)
  31. ##This if statement tells the program whether to trigger the winning conditions, or what to do when it hits the walls.
  32. if (x < 0 or x >= w or y < 0 or y >= h):
  33. outside = 1
  34. elif color== black:
  35. x = xOld
  36. y = yOld
  37. elif color== red:
  38. boom = 1
  39. elif color== blue:
  40. beamedUp = 1
  41. addLine(maze, xOld, yOld, x, y, magenta)
  42. repaint(maze)
  43. ##This if statement tells the program what to do once it's hit either the teleporter or reached the outside on its own
  44. if (outside==1 or beamedUp==1):
  45. showInformation("LET'S GET OUT OF HERE, MAN!")
  46. showInformation("Game Over.")
  47. else:
  48. showInformation("BOOM!")
  49. showInformation("Game Over.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement