Code Duplication    Length = 28-28 lines in 2 locations

examples/samples_old.py 1 location

@@ 1065-1092 (lines=28) @@
1062
def render_bsp(first, key, mouse):
1063
    global bsp, bsp_generate, bsp_refresh, bsp_map
1064
    global bsp_random_room, bsp_room_walls, bsp_depth, bsp_min_room_size
1065
    if bsp_generate or bsp_refresh:
1066
        # dungeon generation
1067
        if bsp is None:
1068
            # create the bsp
1069
            bsp = libtcod.bsp_new_with_size(0, 0, SAMPLE_SCREEN_WIDTH,
1070
                                            SAMPLE_SCREEN_HEIGHT)
1071
        else:
1072
            # restore the nodes size
1073
            libtcod.bsp_resize(bsp, 0, 0, SAMPLE_SCREEN_WIDTH,
1074
                               SAMPLE_SCREEN_HEIGHT)
1075
        bsp_map = list()
1076
        for x in range(SAMPLE_SCREEN_WIDTH):
1077
            bsp_map.append([False] * SAMPLE_SCREEN_HEIGHT)
1078
        if bsp_generate:
1079
            # build a new random bsp tree
1080
            libtcod.bsp_remove_sons(bsp)
1081
            if bsp_room_walls:
1082
                libtcod.bsp_split_recursive(bsp, 0, bsp_depth,
1083
                                            bsp_min_room_size + 1,
1084
                                            bsp_min_room_size + 1, 1.5, 1.5)
1085
            else:
1086
                libtcod.bsp_split_recursive(bsp, 0, bsp_depth,
1087
                                            bsp_min_room_size,
1088
                                            bsp_min_room_size, 1.5, 1.5)
1089
        # create the dungeon from the bsp
1090
        libtcod.bsp_traverse_inverted_level_order(bsp, traverse_node)
1091
        bsp_generate = False
1092
        bsp_refresh = False
1093
    libtcod.console_clear(sample_console)
1094
    libtcod.console_set_default_foreground(sample_console, libtcod.white)
1095
    rooms = 'OFF'

examples/samples_py.py 1 location

@@ 911-938 (lines=28) @@
908
    def on_draw(self, delta_time):
909
        global bsp, bsp_generate, bsp_refresh, bsp_map
910
        global bsp_random_room, bsp_room_walls, bsp_depth, bsp_min_room_size
911
        if bsp_generate or bsp_refresh:
912
            # dungeon generation
913
            if bsp is None:
914
                # create the bsp
915
                bsp = libtcod.bsp_new_with_size(0, 0, SAMPLE_SCREEN_WIDTH,
916
                                                SAMPLE_SCREEN_HEIGHT)
917
            else:
918
                # restore the nodes size
919
                libtcod.bsp_resize(bsp, 0, 0, SAMPLE_SCREEN_WIDTH,
920
                                   SAMPLE_SCREEN_HEIGHT)
921
            bsp_map = list()
922
            for x in range(SAMPLE_SCREEN_WIDTH):
923
                bsp_map.append([False] * SAMPLE_SCREEN_HEIGHT)
924
            if bsp_generate:
925
                # build a new random bsp tree
926
                libtcod.bsp_remove_sons(bsp)
927
                if bsp_room_walls:
928
                    libtcod.bsp_split_recursive(bsp, 0, bsp_depth,
929
                                                bsp_min_room_size + 1,
930
                                                bsp_min_room_size + 1, 1.5, 1.5)
931
                else:
932
                    libtcod.bsp_split_recursive(bsp, 0, bsp_depth,
933
                                                bsp_min_room_size,
934
                                                bsp_min_room_size, 1.5, 1.5)
935
            # create the dungeon from the bsp
936
            libtcod.bsp_traverse_inverted_level_order(bsp, traverse_node)
937
            bsp_generate = False
938
            bsp_refresh = False
939
        libtcod.console_clear(sample_console)
940
        libtcod.console_set_default_foreground(sample_console, libtcod.white)
941
        rooms = 'OFF'