def setStaticBlockNumbers(self, numberStructure, staticBlocks=[]): ''' Assign static block numbers that will be used when matching logical_blocks to static_blocks. The numbers assigned to static_blocks is based on the order and pattern in the numberStructure. The method expects a number structure such as : { 1 : [1, 2, 3, 4], 2 : [5, 6, 7, 8], 3 : [9, 10, 11, 12], 4 : [13, 14, 15], } The dictionary key / index numbers represent static block rows. The list values of these index numbers represents the order in which numbers must be assigned to static blocks.. Required static_block properties: @property row <int> @property index <int> In summary, the numberStructure represents the pattern in which the puzzle needs to be solved.. ''' self.log.debug( 'Using numberStructure %s to assign block_numbers to static blocks', numberStructure) if not staticBlocks: staticBlocks = self.getStaticBlocks() for staticBlock in staticBlocks: staticBlocProp = ObjProperties(staticBlock) staticBlocIndex = staticBlocProp.getProp('index') staticBlocRow = staticBlocProp.getProp('row') if staticBlocRow in numberStructure: numStructRow = numberStructure[staticBlocRow] numStructIndexVal = numStructRow[staticBlocIndex] staticBlocProp.setProp('block_number', numStructIndexVal) self.log.debug( ''' Static block %s has been assigned block_number %s ''', staticBlock, numStructIndexVal) else: error = ''' Static obj %s's row %s not found in number structure! ''', staticBlock, staticBlockRow self.log.error(error) raise PuzzleBlockLoaderError(error)
def setLogicalBlockNumbers(self): ''' Assigns random block_numbers to logical_blocks in the active scene. Note: By default, a logical block does not have a block_number ''' logicalBlocks = self.getLogicalBlocks() lbCount = len(logicalBlocks) generatedNums = [] for logicalBlock in logicalBlocks: lbProp = ObjProperties(logicalBlock) randomNum = 0 # Skip random number 0 because blocks are counted from 1 to 15 # for example.. while (randomNum in generatedNums or randomNum == 0): randomNum = randint(0, lbCount) generatedNums.append(randomNum) lbProp.setProp('block_number', randomNum) self.log.debug('%s assigned to logic_block', randomNum)
class Clock(): ''' An API for controlling Timer property built into the game engine found in game properties. It provides control for starting, stopping and resuming a timer. Note: Game object passed in the constructor must have the following properties: 1) 'timer' type 'Timer' 2) 'is_timer_active' type 'Boolean' 3) 'timer_snapshot' type 'Float' ''' def __init__(self, timerObj): self.timerObj = ObjProperties(timerObj) def start(self): self.reset() self._setIsActive(True) def stop(self): self.setTimeSnapshot(self.curtime()) self._setIsActive(False) def reset(self): self.settimer(0.0) def resume(self): self._setIsActive(True) self.settimer(self.getTimeSnapshot()) def curtime(self): if not self.isActive: return self.getTimeSnapshot() return self.timerObj.getProp('timer') def setTimeSnapshot(self, time): self.timerObj.setProp('timer_snapshot', time) def settimer(self, val): self.timerObj.setProp('timer', val) def _setIsActive(self, bool): self.timerObj.setProp('is_timer_active', bool) def getTimeSnapshot(self): return self.timerObj.getProp('timer_snapshot') @property def isActive(self): return self.timerObj.getProp('is_timer_active')