()
| 23 | |
| 24 | |
| 25 | def main(): |
| 26 | print('''Hungry Robots, by Al Sweigart al@inventwithpython.com |
| 27 | |
| 28 | You are trapped in a maze with hungry robots! You don't know why robots |
| 29 | need to eat, but you don't want to find out. The robots are badly |
| 30 | programmed and will move directly toward you, even if blocked by walls. |
| 31 | You must trick the robots into crashing into each other (or dead robots) |
| 32 | without being caught. You have a personal teleporter device, but it only |
| 33 | has enough battery for {} trips. Keep in mind, you and robots can slip |
| 34 | through the corners of two diagonal walls! |
| 35 | '''.format(NUM_TELEPORTS)) |
| 36 | |
| 37 | input('Press Enter to begin...') |
| 38 | |
| 39 | # Set up a new game: |
| 40 | board = getNewBoard() |
| 41 | robots = addRobots(board) |
| 42 | playerPosition = getRandomEmptySpace(board, robots) |
| 43 | while True: # Main game loop. |
| 44 | displayBoard(board, robots, playerPosition) |
| 45 | |
| 46 | if len(robots) == 0: # Check if the player has won. |
| 47 | print('All the robots have crashed into each other and you') |
| 48 | print('lived to tell the tale! Good job!') |
| 49 | sys.exit() |
| 50 | |
| 51 | # Move the player and robots: |
| 52 | playerPosition = askForPlayerMove(board, robots, playerPosition) |
| 53 | robots = moveRobots(board, robots, playerPosition) |
| 54 | |
| 55 | for x, y in robots: # Check if the player has lost. |
| 56 | if (x, y) == playerPosition: |
| 57 | displayBoard(board, robots, playerPosition) |
| 58 | print('You have been caught by a robot!') |
| 59 | sys.exit() |
| 60 | |
| 61 | |
| 62 | def getNewBoard(): |
no test coverage detected