# -*- coding: utf-8 # Copyright 2006 by Meelis Mets from Products.Archetypes.public import BaseSchema, Schema from Products.Archetypes.public import BooleanField, ImageField, StringField from Products.Archetypes.public import BooleanWidget, ImageWidget, StringWidget, SelectionWidget from Products.Archetypes.public import OrderedBaseFolder, BaseContent, registerType from Globals import InitializeClass from Products.CMFCore.utils import getToolByName from AccessControl import ClassSecurityInfo, Unauthorized from config import PROJECT_NAME from BaseGame import BaseGame schema = BaseGame.schema.copy() schema_lvl = schema + Schema(( BooleanField('useMirrors', accessor = 'getUseMirrors', default = True, widget = BooleanWidget( label = 'Mirrors are used in game', label_msgid='label_use_mirrors', description = 'Check if you want to use mirrors in game', description_msgid = 'desc_use_mirrors', i18n_domain="psyhvel", visible = {'view': 'invisible', 'edit':'visible'}, ), ), BooleanField('useLens', accessor = 'getUseLens', default = False, widget = BooleanWidget( label = 'Lens are used in game', label_msgid='label_use_lens', description = 'Check if you want to use lens in game', description_msgid = 'desc_use_lens', i18n_domain="psyhvel", visible = {'view': 'invisible', 'edit':'visible'}, ), ), StringField('tableWidth', accessor = 'getTableWidth', vocabulary = 'getNumbers', default = '8', widget = SelectionWidget( format = 'select', label = 'Table width', label_msgid='label_table_width', description = 'How many objects are in table by horizontally', description_msgid = 'desc_table_width', i18n_domain="psyhvel", visible = {'view': 'invisible', 'edit':'visible'}, ), ), StringField('tableHeight', accessor = 'getTableHeight', vocabulary = 'getNumbers', default = '8', widget = SelectionWidget( format = 'select', label = 'Table height', label_msgid='label_table_height', description = 'How many objects are in table by vertically', description_msgid = 'desc_table_height', i18n_domain="psyhvel", visible = {'view': 'invisible', 'edit':'visible'}, ), ), )) #schema.delField('multipleChoice') #schema.delField('answerRequired') #schema.delField('time') #schema.moveField('time', pos='bottom') #class RoboRunFunctions: # """ Functions that are needed to run flower task in test view""" # def saveFlowerTask(self,REQUEST): # """ saving data """ # answer=REQUEST.get('current_array') # current = self.getCurrentSheet() # current_id = current.id # if answer != None and answer != "": # answer = answer.split(",") # rc = current.getRightChoice() # if int(answer[0])==rc[0] and int(answer[1])==rc[1]: # rca = 2 # else: # rca = 1 # answers = {'choice':rca} # print "datasse l2hevad "+str(current_id)+" ja "+str(answers) # self.setDataToDatabase(current_id,answers) # self.setCurrentPage() # else: # return self.REQUEST.RESPONSE.redirect(self.absolute_url()+'?error=true') # self.submitToTheNextPage(REQUEST) class RoboLaser(OrderedBaseFolder, BaseGame): """ RoboLaser Game""" meta_type = "RoboLaser" archetype_name = "Robo Laser" global_allow = 0 exclude_from_nav = True filter_content_types = True allowed_content_types = ('RoboLaserLevel',) security = ClassSecurityInfo() schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/robo_laser', 'permissions': ('View',), }, { 'id':'edit', 'name':'Configuration', 'action':'string:${object_url}/base_edit', 'permissions': ('Modify portal content',), }, { 'id':'metadata', 'name':'Info', 'action':'string:${object_url}/base_metadata', 'permissions': ('View',), } ) def __init__(self, id): self.id = id self.gameLevel = 0 def getGameLevel(self): """get Level""" if not hasattr(self, 'gameLevel'): self.gameLevel = 0 levels = self.objectValues('RoboLaserLevel') if len(levels)>0: return levels[self.gameLevel] return False def getGameLevelNr(self): if not hasattr(self, 'gameLevel'): self.gameLevel = 0 return self.gameLevel+1 def getGameData(self): """game data""" game_level = self.getGameLevel() if game_level: return game_level.getGameData() return False def getGameActor(self): """actor image""" return "robo_body.gif" registerType(RoboLaser, PROJECT_NAME) class RoboLaserLevel(BaseGame): """ RoboLaser Game""" meta_type = "RoboLaserLevel" archetype_name = "Robo Laser Level" global_allow = 0 exclude_from_nav = True filter_content_types = True allowed_content_types = () security = ClassSecurityInfo() schema = schema_lvl actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/robo_laser_lvl', 'permissions': ('View',), }, { 'id':'edit', 'name':'Configuration', 'action':'string:${object_url}/base_edit', 'permissions': ('Modify portal content',), }, { 'id':'create', 'name':'Create', 'action':'string:${object_url}/robo_laser_edit', 'permissions': ('Modify portal content',), }, { 'id':'metadata', 'name':'Info', 'action':'string:${object_url}/base_metadata', 'permissions': ('View',), } ) def __init__(self, id): self.id = id self.gameTable = self.createGameTable() self.roboPosition = 0 self.friendPosition = 0 def createGameTable(self): """returns table""" table = [] rows = int(self.getTableHeight()) cols = int(self.getTableWidth()) for col in range(0,cols): table.append([]) for row in range(0,rows): table[col].append("empty") return table def getGameTable(self): """returns table""" if int(self.getTableWidth()) != len(self.gameTable) or int(self.getTableHeight()) != len(self.gameTable[0]): self.gameTable = self.createGameTable() self.p_changed = 1 return self.gameTable def setGameTable(self, px, py, val): """set val of gt pos""" self.gameTable[int(px)][int(py)]=val self.p_changed = 1 def getRoboPosition(self): """returns robo pos""" return self.roboPosition def setRoboPosition(self, pos): """set robo pos""" self.roboPosition = pos self.p_changed = 1 def getFriendPosition(self): """returns friend pos""" return self.friendPosition def setFriendPosition(self, pos): """set friend pos""" self.friendPosition = pos self.p_changed = 1 def getGameData(self): """return game data""" return [self.getRoboPosition(),self.getFriendPosition(),self.getGameTable()] registerType(RoboLaserLevel, PROJECT_NAME)