# -*- 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 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(( StringField('tableWidth', accessor = 'getTableWidth', vocabulary = 'getNumbers', default = '4', widget = SelectionWidget( format = 'select', label = 'Table width', label_msgid='label_table_width', description = 'How many flowers 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 = '4', widget = SelectionWidget( format = 'select', label = 'Table height', label_msgid='label_table_height', description = 'How many flowers 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 BearBasket(BaseGame): """ BearBasket Game""" meta_type = "BearBasket" archetype_name = "Bear Basket" global_allow = 0 exclude_from_nav = True filter_content_types = True security = ClassSecurityInfo() schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/bear_basket', 'permissions': ('View',), }, { 'id':'edit', 'name':'Configuration', 'action':'string:${object_url}/base_edit', 'permissions': ('Modify portal content',), }, { 'id':'create', 'name':'Create', 'action':'string:${object_url}/bear_basket_edit', 'permissions': ('Modify portal content',), }, { 'id':'messages', 'name':'Messages', 'action':'string:${object_url}/game_messages', 'permissions': ('Modify portal content',), }, { 'id':'metadata', 'name':'Info', 'action':'string:${object_url}/base_metadata', 'permissions': ('View',), } ) def __init__(self, id): self.id = id self.gameObjects = [] def getGameObjects(self): """game objs""" if not hasattr(self, 'gameObjects'): self.gameObjects = [] return self.gameObjects def addGameObject(self): """game objs""" fruit = self.REQUEST.get('fruit') p_x = int(self.REQUEST.get('position_x'))-1 p_y = int(self.REQUEST.get('position_y')) if fruit and p_x>=0 and p_y>=0 and p_x<=8: last_y_pos = 0 numberOfGameObjects = len(self.gameObjects) if numberOfGameObjects>0: last_y_pos = self.gameObjects[numberOfGameObjects-1][2] self.gameObjects.append([fruit,p_x,(last_y_pos-p_y)]) self.p_changed = 1 return self.REQUEST.RESPONSE.redirect(self.absolute_url()+"/bear_basket_edit") def delGameObjects(self): """remove selected rows""" for_remove = self.REQUEST.get("rows_for_remove") if for_remove: if isinstance(for_remove, type('')): for_remove = [for_remove] for fr in for_remove: self.gameObjects.pop(int(fr)) self.p_changed = 1 return self.REQUEST.RESPONSE.redirect(self.absolute_url()+"/bear_basket_edit") def getGameData(self): """game data""" return [self.getGameObjects(), self.getGameMessages()] def getMyBestScore(self): """best score""" return 0 registerType(BearBasket, PROJECT_NAME)