Level 3 easier but still missing necessary clues to the player.

This commit is contained in:
Niels Serup 2012-08-10 21:54:21 +02:00
parent d6ec520e21
commit c0f59d72c9
2 changed files with 42 additions and 15 deletions

View File

@ -57,16 +57,17 @@ class Level3(level.Level):
# tile.Tile(self, i*64, j*48, self.imgs['ground1']))
task_start = (2, 2)
task_size = (5, 5)
# Abstract "boxes", actually colour fields
boxes = [box + [(0, 0, 0)] * 2 for box in logic.colourboxes.generate_colour_boxes(2, 3)]
boxes += [[(0, 0, 0)] * 2 + box for box in logic.colourboxes.generate_colour_boxes(2, 3)]
boxes += [logic.colourboxes.generate_random_box(4) for _ in range(9)]
boxes += [[(0, 0, 0)] * 4 for _ in range(9)]
boxes = []
for i in range(4):
boxes.extend([(0, 0, 0)] * i + box + [(0, 0, 0)] * (3 - i)
for box in logic.colourboxes.generate_colour_boxes(1, 3))
boxes.extend(logic.colourboxes.generate_random_box(4, 2) for _ in range(20))
boxes.extend([(0, 0, 0)] * 4 for _ in range(10))
random.shuffle(boxes)
pos_colour = {}
for box, (x, y) in zip(boxes, itertools.product(range(6), range(4))):
for box, (x, y) in zip(boxes, itertools.product(range(7), range(6))):
self.tiles.append(tile.Tile(self, 64 * (x + task_start[0] + 1),
48 * (y + task_start[1] + 1),
self.imgs['ground1']))
@ -74,15 +75,20 @@ class Level3(level.Level):
self.draw_background()
action_blocks = [block.ActionBlock(self, 64 * (i + 1 + task_start[0]),
48 * task_start[1], movable=True)
for i in range(6)]
action_blocks = list(itertools.chain(*
[(block.ActionBlock(self, 64 * task_start[0],
48 * (i + 1 + task_start[1]),
movable=True),
block.ActionBlock(self, 64 * (task_start[0] + 8),
48 * (i + 1 + task_start[1]),
movable=True))
for i in range(6)]))
self.objects.extend(action_blocks)
wells = [block.ColorWell(self, task_start[0] * 64, task_start[1] * 48),
block.ColorWell(self, (task_start[0] + 7) * 64, task_start[1] * 48),
block.ColorWell(self, task_start[0] * 64, (task_start[1] + 5) * 48),
block.ColorWell(self, (task_start[0] + 7) * 64, (task_start[1] + 5) * 48),
block.ColorWell(self, (task_start[0] + 8) * 64, task_start[1] * 48),
block.ColorWell(self, task_start[0] * 64, (task_start[1] + 7) * 48),
block.ColorWell(self, (task_start[0] + 8) * 64, (task_start[1] + 7) * 48),
]
self.objects.extend(wells)

View File

@ -91,14 +91,35 @@ def _get_oxs(x):
else (x - 1, x + 1) if x % 3 == 1 \
else (x - 2, x - 1)
def generate_random_box(nwells):
"""Generate a box with random colors except white (111)."""
def generate_random_box(nwells, min_nonblacks=0):
"""
Generate a box that triggers nwells wells, with random colors except white
(111).
Arguments:
min_nonblacks -- minimum number of well colours in a box required not to be
black.
"""
def gen_wc():
wc = [random.choice((0, 1)) for i in range(3)]
if all(b == 1 for b in wc):
wc[random.randrange(3)] = 0
return wc
return [tuple(gen_wc()) for _ in range(nwells)]
def gen_wc_nonblack():
wc = gen_wc()
if all(b == 0 for b in wc):
wc[random.randrange(3)] = 1
return wc
colours = [tuple(gen_wc()) for _ in range(nwells)]
nonblack = lambda t: any(n == 1 for n in t)
missing_nonblacks = min_nonblacks - len(list(filter(nonblack, colours)))
i = 0
while missing_nonblacks > 0:
if not nonblack(colours[i]):
colours[i] = gen_wc_nonblack()
missing_nonblacks -= 1
i += 1
return colours
def get_colours(boxes):
colours = []