Пример #1
0
 def sizeHint(self):
     if not self.sizeHint_:
         pic = QPicture()
         painter = QPainter(pic)
         getModuleAttrDict(Client.gameObject.module)['paintGame'](painter)
         painter.end()
         self.sizeHint_ = pic.boundingRect().size()
     return self.sizeHint_
Пример #2
0
def getState():
    mstates = []
    for module in modules:
        vars = dict()
        for name, var in getModuleAttrDict(module).items():
            if not name.startswith('__') and not name.endswith('__') and not inspect.ismodule(var) \
                    and not inspect.isfunction(var) and not inspect.isclass(var):
                vars[name] = var
        mstates.append(vars)
    return pickle.dumps([Client.gameObject.currentPlayerIndex, mstates])
Пример #3
0
 def paintEvent(self, QPaintEvent):
     pic = QPicture()
     painter = QPainter(pic)
     getModuleAttrDict(Client.gameObject.module)['paintGame'](painter)
     painter.end()
     painter.begin(self)
     bRect = pic.boundingRect()
     self.sizeHint_ = bRect.size()
     painter.setWindow(bRect)
     painter.setViewTransformEnabled(True)
     width = self.width()
     height = self.height()
     if width * bRect.height() < height * bRect.width():
         pheight = (width * bRect.height()) / bRect.width()
         painter.setViewport(0, (height - pheight) / 2, width, pheight)
     else:
         pwidth = (height * bRect.width()) / bRect.height()
         painter.setViewport((width - pwidth) / 2, 0, pwidth, height)
     self.invTrafo = painter.combinedTransform().inverted()[0]
     pic.play(painter)
Пример #4
0
 def handleEvent(self, event):
     if not Client.gameObject.isMoving():
         return
     next = getModuleAttrDict(Client.gameObject.module)['makeMove'](event)
     if next is not None:
         if type(next) != int:
             raise Exception(
                 'makeMove returned "{}" which is neither None nor an integer'
                 .format(str(next)))
         if next < -1 or next >= Client.gameObject.getPlayerCount():
             raise Exception(
                 'makeMove returned {} which is neither -1 nor a valid player index'
                 .format(next))
         Client.gameObject.currentPlayerIndex = next
         self.moveDone.emit(next)
     self.update()
Пример #5
0
def getPathsAndModules():
    module = Client.gameObject.module
    normalizePath = lambda x: QFileInfo(x).absoluteFilePath()
    moduleFile = normalizePath(getModuleFilePath(module))
    path = moduleFile[:(moduleFile.rfind('/') + 1)]
    pathLen = len(path)
    modules = [[moduleFile[pathLen:], module]]
    stack = [module]
    while len(stack) > 0:
        module = stack.pop()
        for name, var in getModuleAttrDict(module).items():
            if var not in modules and var != GamePlayer and inspect.ismodule(
                    var) and hasattr(var, '__file__'):
                moduleFile = normalizePath(var.__file__)
                if moduleFile.startswith(path):
                    modules.append([moduleFile[pathLen:], var])
                    stack.append(var)
    return modules
Пример #6
0
def applyState(state):
    [currentPlayerIndex, mstates] = pickle.loads(state)
    Client.gameObject.currentPlayerIndex = currentPlayerIndex
    for module, vars in zip(modules, mstates):
        getModuleAttrDict(module).update(vars)
Пример #7
0
def initGame():
    initGameFunc = getModuleAttrDict(Client.gameObject.module).get('initGame')
    if initGameFunc:
        initGameFunc()