0

我对这个评估有疑问,“旧”,它是一个元组列表,当使用 bp_list 评估时应该评估 False,bp_list 是相同的元组列表,但项目更少。非常感谢你。

while True: # game loop
    if dead_flag == True:
        pygame.time.wait(2000)
        dead_flag = False    
    MAINSURF.fill(BLACK)

    thePill.drawPills(p_inventary)
    oldpoints = points
    p_inventary, points = thePill.eatenPill(pac._x, pac._y, p_inventary)

    bigPill(*bp_list)
    #### This is the problematic part
    old = bp_list
    print ">>>", old
    bp_list = eatBig(bp_list, pac._x, pac._y)
    print "---",bp_list
    if (old != bp_list):
        print "they're different"
        print "##", old_bp_list
        print "##", bp_list
        score += 50

    if oldpoints != points:
        score = (basep - points) * 10


    """else: 
        print "old_bp_list ", old_bp_list
        print "bp_list ", bp_list    """     
    if p_inventary == []:
        break
4

1 回答 1

1
old = bp_list

此行不会old变成bp_list. 在这一行之后,old两者bp_list都引用同一个对象,对 的任何修改都bp_list将显示在old.

于 2013-09-08T05:09:15.237 回答