# -*- 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, OrderedBaseFolder, 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(( 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 BearCombolingFunctions: """ Functions that are needed to bear comboling 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) pass class BearComboling(OrderedBaseFolder, BaseGame): """ BearComboling Game""" meta_type = "BearComboling" archetype_name = "Bear Comboling" global_allow = 0 exclude_from_nav = True filter_content_types = True allowed_content_types = ('BearCombolingLevel',) filter_content_types = True security = ClassSecurityInfo() schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/bear_comboling', 'permissions': ('View',), }, { 'id':'edit', 'name':'Configuration', 'action':'string:${object_url}/base_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.gameLevel = 0 def getGameLevel(self): """get Level""" if not hasattr(self, 'gameLevel'): self.gameLevel = 0 levels = self.objectValues('BearCombolingLevel') 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 "bear_body.gif" registerType(BearComboling, PROJECT_NAME) class BearCombolingLevel(BaseGame): """ BearComboling GameLevel""" meta_type = "BearCombolingLevel" archetype_name = "Bear Comboling Level" global_allow = 0 exclude_from_nav = True security = ClassSecurityInfo() schema = schema_lvl actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/bear_comboling_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}/bear_comboling_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 def createCombolingTable(self): """table creation""" combolingTable = [] for x in range(0,int(self.getTableWidth())): ctl = [] for y in range(0, int(self.getTableHeight())): ctl.append(0) combolingTable.append(ctl) self.combolingTable = combolingTable self._p_changed = 1 def getCombolingTable(self): """return ct""" if not hasattr(self, 'combolingTable'): self.createCombolingTable() print self.combolingTable return self.combolingTable def getCombolingSQ(self, row, col): """creats new sq""" if not hasattr(self, 'combolingTable'): self.createCombolingTable() return self.combolingTable[int(row)][int(col)] def setCombolingSQ(self, row, col, val): """creats new sq""" if not hasattr(self, 'combolingTable'): self.createCombolingTable() self.combolingTable[int(row)][int(col)] = val self._p_changed = 1 def getNumberOfSQ(self): """get sq number""" nrsq = 0 for i in self.combolingTable: for j in i: if j == '1': nrsq = nrsq + 1 return nrsq def getGameData(self): """game data""" return [self.getGameMessages(),] registerType(BearCombolingLevel, PROJECT_NAME)