Exemple #1
0
def step(screen_size,
         color_of_tile,
         flooded_list,
         color,
         show_graphics=False,
         gen_tests=False,
         times=[]):
    global tests
    global test
    global board_size
    global max_moves
    global screen

    if color != None and step.movecount < max_moves:
        step.movecount += 1

        if show_graphics:
            tile = pygame.Surface(TILE_SIZE)
            tile.fill(rgb[color])

        if gen_tests:
            test.append(copy.deepcopy(color_of_tile))
            test.append(color)

        for coord in flooded_list:
            color_of_tile[coord] = color

        # This is the function the students will write. -Jeremy
        t1 = time.time()
        flood(color_of_tile, flooded_list, screen_size)
        t2 = time.time()
        times.append(t2 - t1)

        if show_graphics:
            for i in range(len(flooded_list)):
                screen.blit(tile, flooded_list[i])

        # drought every seven years
        if drought_enabled and len(
                flooded_list) > 0 and step.movecount % 7 == 0:
            td1 = time.time()
            drought_tiles = create_drought(flooded_list, color_of_tile)
            #             td2 = time.clock()
            diff = time.time() - td1
            print "%0.8lf" % diff
            #             times.append(diff)

            if show_graphics:
                display.set_caption('Flood-it! Drought in progress!')
                for coord in drought_tiles:
                    tile.fill(rgb[color_of_tile[coord]])
                    screen.blit(tile, coord)
        else:
            if show_graphics:
                display.set_caption('Flood-it! ' + str(step.movecount) + '/' +
                                    str(max_moves))

        if show_graphics:
            pygame.display.update()

    if len(flooded_list) == (board_size * board_size):
        if show_graphics:
            game_over('win.png', screen_size)
            display.set_caption('Flood-it! Congratulations. You won!')
        if gen_tests:
            test.append(copy.deepcopy(color_of_tile))
            tests.append(test)
            test = []
        step.movecount = 0
        return True

    if step.movecount == max_moves and len(flooded_list) != (board_size *
                                                             board_size):
        if show_graphics:
            game_over('gameover.png', screen_size)
            display.set_caption('Flood-it! GAME OVER!')
        if gen_tests:
            test.append(copy.deepcopy(color_of_tile))
            tests.append(test)
            test = []
        step.movecount = 0
        return True

    return False
Exemple #2
0
                for coord in flooded_list:
                    color_of_tile[coord] = color

                # This is the function the students will write. -Jeremy
                flood(color_of_tile, flooded_list)

                for i in range(len(flooded_list)):
                    screen.blit(tile, flooded_list[i])

                # drought (new feature, disabled for now) -Jeremy
                if False and len(flooded_list) > 1 and random.randint(1,
                                                                      5) == 1:
                    display.set_caption('Flood-it! Drought in progress!')
                    movecount -= 1
                    num_remove = len(flooded_list) / 10
                    drought_tiles = create_drought(flooded_list, color_of_tile)
                    for coord in drought_tiles:
                        tile.fill(rgb[color_of_tile[coord]])
                        screen.blit(tile, coord)
                else:
                    display.set_caption('Flood-it! ' + str(movecount) + '/25')

                pygame.display.update()

        if len(flooded_list) == 196:
            if not for_restart:
                game_over('win.png')
                for_restart = True
            display.set_caption('Flood-it! Congratulations. You won!')

        if movecount == 25 and len(flooded_list) != 196: