
Two more 'main' files.
One has the game running inside a basic wxPython window.
Another extends the AUI Docking Window Manager Demo as can be seen in the photo here.
A Cute Blocks World for AI Experimentation
The global is necessary because the actual class object doesn't get created until it's instantiated. If you try it inside the class definition you get this:
WaterBlock_singleton = None
class WaterBlock(Block):
def __new__(cls, *args, **kargs):
global WaterBlock_singleton
if not WaterBlock_singleton:
obj = object.__new__(cls)
WaterBlock_singleton = obj
obj.__init__(*args, **kargs)
return WaterBlock_singleton
def __init__(self):
super(WaterBlock, self).__init__()
self.vu = BlockVu(self, 'Water Block.png')
UnboundLocalError: local variable 'WaterBlock_singleton' referenced before assignment
WaterBlock_singleton = None
class WaterBlock(Block):
#MetaClass
class __metaclass__(type):
def __call__(cls, *args, **kwargs):
return cls.__new__(cls, *args, **kwargs)
#Class
def __new__(cls, *args, **kargs):
global WaterBlock_singleton
if not WaterBlock_singleton:
obj = object.__new__(cls)
WaterBlock_singleton = obj
obj.__init__(*args, **kargs)
return WaterBlock_singleton
def __init__(self):
super(WaterBlock, self).__init__()
self.vu = BlockVu(self, 'Water Block.png')