Beispiel #1
0
def build_block():
    for x in range(st.NUMBER_COLUMN):
        for y in range(st.NUMBER_ROW):
            if not (x == st.NUMBER_COLUMN / 2 and y == st.NUMBER_ROW / 2):
                block = Block(st.SIZE_BORDER + st.SIZE * x,
                              st.SIZE_BORDER + st.SIZE * y)
                if not random.randint(0,
                                      st.DENSITY_MINES) and block.is_empty():
                    block.is_mine = True
                elif not random.randint(
                        0, st.DENSITY_MONSTERS) and block.is_empty():
                    block.is_monster = True
                elif not random.randint(
                        0, st.DENSITY_SUPERMONSTERS) and block.is_empty():
                    block.is_super_monster = True
Beispiel #2
0
def restore_blocks(mydb):
    mycol = mydb["blocks"]  #create collection
    mylist = mycol.find()
    for data_block in mylist:
        block = Block(data_block["x"], data_block["y"])
        block.is_mine = data_block["is_mine"]
        block.is_monster = data_block["is_monster"]
        block.is_super_monster = data_block["is_super_monster"]
        block.is_key = data_block["is_key"]
        block.is_exit = data_block["is_exit"]
        block.is_open = data_block["is_open"]
    for blocks in Data.blocks:
        for block in blocks:
            if (not block):
                continue
            elif block.is_open:
                block.restore()