Variables pygame-python使用visiter模式获取变量

Variables pygame-python使用visiter模式获取变量,variables,methods,pygame,visitor,Variables,Methods,Pygame,Visitor,我试图使用visiter模式从第一个类中获取self.coin值,并将其返回给第二个类中的方法,但它不起作用,总是不返回任何值。。。有人能帮忙吗 class coin_collector(Observer): def __init__(self): super(Observer, self).__init__() self.coin_count = 0 self.run = True self.coin = 0 d

我试图使用visiter模式从第一个类中获取self.coin值,并将其返回给第二个类中的方法,但它不起作用,总是不返回任何值。。。有人能帮忙吗

class coin_collector(Observer):
    def __init__(self):
        super(Observer, self).__init__()
        self.coin_count = 0
        self.run = True
        self.coin = 0

    def acceptVisitor(self, visitor):
        visitor.visit(self)

    def update(self, observable, other):
        me = coin_collector()
        me.coin_Count(other, True)

    def coin_Count(self, value, TF):
        run = TF
        if run:
            self.coin = value
            print self.coin
        return self.coin

    def __str__(self):
        return self.__class__.__name__

#this is part of a different class in a different file 
    def visit(self, location):
        location.coin_Count(0, False)

    def update(self):
        visitee = coin_collector()
        self.c_Count = self.visit(visitee) # for some reason this always returns none
        print self.c_Count, "working" # this always prints none...

好的,让我们从
硬币收集器开始。他的
coin
属性设置为0。 您还有一个带有
更新
访问
功能的第二个类

更新功能在每次调用时创建一个新的硬币收集器。然后它将
visit
函数的返回值分配给
self.c_Count
。现在让我们看看
visit
功能

它接收一个全新的
硬币收集器
并返回None,如果您将
True
作为
TF
传递,它会将其值参数分配给
硬币
字段


coin\u count
函数返回后,您在
visit
函数中不执行任何操作,因此返回值丢失。这就是为什么当您尝试分配self.visit的结果时,您会得到一个
None

您希望返回什么?