Optimized pick-random-elements-from-list method.
This commit is contained in:
@@ -30,6 +30,7 @@ import random
|
||||
import re
|
||||
import itertools
|
||||
|
||||
import misc
|
||||
import level
|
||||
import player
|
||||
import tile
|
||||
@@ -52,10 +53,8 @@ class Level(level.Level):
|
||||
|
||||
self.draw_background()
|
||||
|
||||
emptys = list(itertools.product(range(2, 20), range(2, 20)))
|
||||
for _ in range(150):
|
||||
x, y = random.choice(emptys)
|
||||
emptys.remove((x, y))
|
||||
for x, y in misc.pick_random_elements(
|
||||
list(itertools.product(range(2, 20), range(2, 20))), 150):
|
||||
self.objects.append(block.Block(self, 64 * x, 48 * y,
|
||||
self.imgs['block1'], movable=True))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user