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

Method __init__

src/gamesbyexample/zombiebitefight.py:91–110  ·  view source on GitHub ↗
(self, zombies)

Source from the content-addressed store, hash-verified

89
90class Board:
91 def __init__(self, zombies):
92 self.zombies = zombies
93 random.shuffle(self.zombies)
94
95 numberOfZombies = len(zombies)
96 numberOfSpaces = WIDTH * HEIGHT
97 if numberOfZombies >= numberOfSpaces:
98 raise Exception('Too many zombies for this size board.')
99
100 # Place the zombie objects on the board:
101 for zombie in zombies:
102 while True:
103 x = random.randint(0, WIDTH - 1)
104 y = random.randint(0, HEIGHT - 1)
105 zombieAtXY = self.getZombieAt(x, y)
106
107 if zombieAtXY == None:
108 zombie._x = x
109 zombie._y = y
110 break
111
112
113 def getZombieAt(self, x, y):

Callers 2

__init__Method · 0.45
__init__Method · 0.45

Calls 1

getZombieAtMethod · 0.95

Tested by

no test coverage detected