Optimized pick-random-elements-from-list method.

This commit is contained in:
Niels Serup
2012-08-10 11:27:36 +02:00
parent 9860036860
commit 1f552640e5
4 changed files with 31 additions and 22 deletions

View File

@@ -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))