Como prometi, o código que ilustra a parte de renderização. Python não implementa interfaces explícitas, como em Java, então fiz uma ligeira gambiarra com uma classe abstrata. E sim, eu programo em inglês. Me processem
# Object renderer abstract class
class Renderer:
# Default constructor
#
# Raises an exception because this class can't
# be instantiated. It's used as a base class
# for other renderer classes
def __init__(self):
raise "Can't instantiate this abstract class"
# Renders an object
#
# Renders the object based on its class. It uses
# an ugly chain of "if else isinstance", because
# Python can't do method overloading (at least
# not out of the box). Thanks, guys.
def render(self, object):
if isinstance(object, Map):
self.__renderMap__(object)
# Renderer that uses pygame's routines
class PygameRenderer(Renderer):
# Default constructor
#
# Overrides the base class' constructor
# to prevent an instantiation exception
def __init__(self):
pass
# Renders a map object
def __renderMap__(self, map):
print "Rendering map using PyGame!"
# Renderer that uses OpenGL routines
class OpenGLRenderer(Renderer):
# Default constructor
#
# Overrides the base class' constructor
# to prevent an instantiation exception
def __init__(self):
pass
# Renders a map object
def __renderMap__(self, map):
print "Rendering map using OpenGL!"