MCPcopy Create free account
hub / github.com/asweigart/PythonStdioGames / main

Function main

src/gamesbyexample/hungryrobots.py:25–59  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

23
24
25def main():
26 print('''Hungry Robots, by Al Sweigart al@inventwithpython.com
27
28You are trapped in a maze with hungry robots! You don't know why robots
29need to eat, but you don't want to find out. The robots are badly
30programmed and will move directly toward you, even if blocked by walls.
31You must trick the robots into crashing into each other (or dead robots)
32without being caught. You have a personal teleporter device, but it only
33has enough battery for {} trips. Keep in mind, you and robots can slip
34through 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
62def getNewBoard():

Callers 1

hungryrobots.pyFile · 0.70

Calls 6

addRobotsFunction · 0.85
getRandomEmptySpaceFunction · 0.85
moveRobotsFunction · 0.85
getNewBoardFunction · 0.70
displayBoardFunction · 0.70
askForPlayerMoveFunction · 0.70

Tested by

no test coverage detected