def check_result(self): result = [" " for i in range(self.alphabet_len)] if self.board.grid[0] == self.board.grid[self.data[1] - 1] == self.solution_grid: for i in range(len(self.board.ships)): if self.board.ships[i].grid_y == 0: result[ self.board.ships[i].grid_x] = self.board.ships[i].value elif self.board.ships[i].grid_y == self.data[1] - 1: if self.last_block and not self.lang.ltr_text: result[self.data[0] + self.board.ships[i].grid_x - 1] = self.board.ships[i].value else: result[self.data[0] + self.board.ships[i]. grid_x] = self.board.ships[i].value if ((self.lang.ltr_text and self.word == result) or (not self.lang.ltr_text and ex.unival(self.word) == ex.unival("".join(result)))): self.auto_check() self.level.next_board() else: self.auto_check() elif self.data[5] == 0: self.auto_check_reset()
def paint_bg_letter(self): txt = self.active_letter val = ex.unival(txt) text = self.canvas_block.font.render("%s" % (val), 1, (220, 220, 220, 0)) font_x = ((self.board.scale * self.canvas_block.grid_w - self.canvas_block.font.size(val)[0]) // 2) font_y = ( (self.board.scale * self.canvas_block.grid_h - self.canvas_block.font.size(val)[1]) // 2) - 3 * self.board.scale txt2 = ex.unival(self.active_word) text2 = self.canvas_block.font3.render("%s" % (txt2), 1, (220, 220, 220, 0)) font_x2 = ((self.board.scale * self.canvas_block.grid_w - self.canvas_block.font3.size(txt2)[0]) // 2) font_y2 = ((self.board.scale * self.canvas_block.grid_h - self.canvas_block.font3.size(txt2)[1]) // 2) + 7 * self.board.scale self.word_pos_y = font_y2 self.canvas.fill(self.bg_color) self.canvas.blit(text, (font_x, font_y)) self.canvas.blit(text2, (font_x2, font_y2)) self.copy_to_screen()
def __init__(self, menu, dbgameid, item_id, cat_id, title, subtitle, constructor, img_src, img_src2, variant=0, var2=0, max_age=7, menu_line=0): self.menu = menu self.item_id = item_id self.cat_id = cat_id self.game_constructor = constructor self.variant = variant self.var2 = var2 self.dbgameid = dbgameid self.lang_activity = False self.title = ex.unival(title) self.subtitle = ex.unival(subtitle) self.max_age = max_age self.img_src = img_src self.img_src2 = img_src2 self.menu_line = menu_line
def __init__(self, menu, unit_id, title, subtitle, menu_line): self.selected = False self.categories = [] self.menu = menu self.unit_id = unit_id self.title = ex.unival(title) self.subtitle = ex.unival(subtitle) self.menu_line = menu_line
def __init__(self, menu, top_id, cat_id, title, subtitle, img_src, has_inner, menu_line): self.menu = menu self.cat_id = cat_id self.top_id = top_id self.has_inner = has_inner self.title = ex.unival(title) self.subtitle = ex.unival(subtitle) self.img_src = img_src self.menu_line = menu_line
def auto_check(self): if self.board.grid[2] == self.solution_grid: for i in range(len(self.board.ships)): if self.board.ships[i].grid_y == 2: self.board.ships[i].update_me = True if ex.unival(self.board.ships[i].value) == ex.unival( self.word_l[self.board.ships[i].grid_x - self.left_offset]): self.board.ships[i].set_display_check(True) else: self.board.ships[i].set_display_check(False)
def __init__(self, wnd, l, t, w, h, caption, img_src1, img_src2, fsubmit, fargs): pygame.sprite.Sprite.__init__(self) self.wnd = wnd self.w = w self.h = h self.l = l self.t = t self.fsubmit = fsubmit self.fargs = fargs self.caption = ex.unival(caption) self.is_mouse_over = False self.color = (255, 255, 255, 0) self.image = pygame.Surface([self.w, self.h], flags=pygame.SRCALPHA) #self.image.set_colorkey((255, 255, 255)) self.rect = self.image.get_rect() self.rect.topleft = [self.l, self.t] self.img_src1 = img_src1 self.img_src2 = img_src2 self.active_img = None if len(self.img_src1) > 0: self.img_pos = (0, 0) try: self.img1 = pygame.image.load(os.path.join('res', 'images', self.img_src1)).convert_alpha() self.img2 = pygame.image.load(os.path.join('res', 'images', self.img_src2)).convert_alpha() self.active_img = self.img1 except: pass # self.image.set_colorkey(self.color) self.update()
def time2str(h, m): 'takes 2 variables: h - hour, m - minute, returns time as a string, ie. five to seven - for 6:55' if m > 30: if h == 12: h = 1 else: h += 1 #if sys.version_info < (3, 0): if sys.version_info[0] < 3: if m == 0: return unival(n2txt(h)) elif m == 1: return r(unicode(" דקה אחרי", "utf-8")) + n2txt(h) elif m == 15: return r(unicode(" רבע אחרי", "utf-8")) + n2txt(h) elif m == 30: return r(unicode("חצי אחרי ", "utf-8")) + n2txt(h) elif m == 45: return r(unicode("רבע ל ", "utf-8")) + n2txt(h) elif m == 59: return r(unicode("דקה ל ", "utf-8")) + n2txt(h) elif m < 30: return n2txt(m) + r(unicode(" אחרי ", "utf-8")) + n2txt(h) elif m > 30: return n2txt(60 - m) + r(unicode(" ל ", "utf-8")) + n2txt(h) return "" else: if m == 0: return n2txt(h) elif m == 1: return r(" דקה אחרי") + n2txt(h) elif m == 15: return r(" רבע אחרי") + n2txt(h) elif m == 30: return r("חצי אחרי ") + n2txt(h) elif m == 45: return r("רבע ל ") + n2txt(h) elif m == 59: return r("דקה ל ") + n2txt(h) elif m < 30: return n2txt(m) + r(" אחרי ") + n2txt(h) elif m > 30: return n2txt(60 - m) + r(" ל ") + n2txt(h) return ""
def create_card(self, active): val = ex.unival(active.value) if sys.version_info < (3, 0): self.say(val[0].encode("utf-8")) else: self.say(val[0]) indx = [0, 1] self.board.units[0].value = val word_index = random.randint(0, len(self.words[active.unit_id]) - 1) self.slide.value = self.words[active.unit_id][word_index] self.slide.speaker_val = self.words[active.unit_id][word_index] self.word_label.set_value(self.words[active.unit_id][word_index]) self.word_label.speaker_val = self.words[active.unit_id][word_index] self.pos_l_labels[0].set_value(self.al_e[active.unit_id]) self.pos_l_labels[1].value = self.al_m[active.unit_id] self.pos_l_labels[2].value = self.al_i[active.unit_id] for each in self.pos_l_labels: each.update_me = True indx2 = [self.abc_len, self.abc_len + 1] img_src = os.path.join( 'fc', "fc%03i.jpg" % self.imgs[active.unit_id][word_index]) self.slide.change_image(img_src) self.board.active_ship = -1 self.slide.update_me = True for i in indx: self.board.units[i].update_me = True for i in indx2: self.board.ships[i].update_me = True self.mainloop.redraw_needed[0] = True
def __init__(self, wnd, l, t, w, h, caption, img_src1, img_src2, fsubmit, fargs): pygame.sprite.Sprite.__init__(self) self.wnd = wnd self.w = w self.h = h self.l = l self.t = t self.fsubmit = fsubmit self.fargs = fargs self.caption = ex.unival(caption) self.is_mouse_over = False self.color = (245, 0, 245) self.image = pygame.Surface([self.w, self.h]) self.image.set_colorkey((255, 255, 255)) self.rect = self.image.get_rect() self.rect.topleft = [self.l, self.t] self.img_src1 = img_src1 self.img_src2 = img_src2 self.active_img = None if len(self.img_src1) > 0: self.img_pos = (0, 0) try: self.img1 = pygame.image.load(os.path.join('res', 'images', self.img_src1)).convert() self.img2 = pygame.image.load(os.path.join('res', 'images', self.img_src2)).convert() self.active_img = self.img1 except: pass # self.image.set_colorkey(self.color) self.update()
def set_value(self, new_value): self.value = ex.unival(new_value) self.txt = self.value self.update_me = True if self.multi_color: self.coltxt = self.split_tags(self.value) self.value = "".join(self.coltxt[1]) self.update(self.board)
def create_card(self, active): val = ex.unival(active.value) if sys.version_info < (3, 0): self.say(val[0].encode("utf-8")) else: self.say(val[0]) indx = [0, 1] if self.lang.has_uc: if len(val) == 2: lcb = 0 lce = 1 ucb = 1 uce = 2 if len(val) == 4: lcb = 0 lce = 2 ucb = 2 uce = 4 self.board.units[0].value = val[lcb:lce] if self.lang.has_cursive: self.board.units[1].value = val[lcb:lce] if self.lang.has_cursive: indx = [0, 1, 2, 3] self.board.units[2].value = val[ucb:uce] self.board.units[3].value = val[ucb:uce] else: self.board.units[1].value = val[ucb:uce] else: self.board.units[0].value = val self.board.ships[self.abc_len].value = self.word_list[active.unit_id] self.board.ships[self.abc_len].speaker_val = self.pword_list[ active.unit_id] self.board.ships[self.abc_len + 1].set_value( self.word_list[active.unit_id]) self.board.ships[self.abc_len + 1].speaker_val = self.pword_list[active.unit_id] if self.lang.has_cursive: indx2 = [self.abc_len, self.abc_len + 1, self.abc_len + 2] self.board.ships[self.abc_len + 2].set_value( self.word_list[active.unit_id]) self.board.ships[self.abc_len + 2].speaker_val = self.pword_list[active.unit_id] else: indx2 = [self.abc_len, self.abc_len + 1] img_src = os.path.join('fc', "fc%03i.jpg" % self.frame_flow[active.unit_id]) self.slide.change_image(img_src) self.board.active_ship = -1 self.slide.update_me = True for i in indx: self.board.units[i].update_me = True for i in indx2: self.board.ships[i].update_me = True self.mainloop.redraw_needed[0] = True
def sure_to_close(self): self.hide_buttons(0, 0, 0, 0, 1, 0, 1, 0, 0) self.mainloop.redraw_needed[1] = True self.hidden = True self.close_dialog = True self.title = ex.unival(self.lang.d["close_confirm"]) self.subtitle = "" self.mainloop.sfx.play(2) self.layout_update()
def paint_bg_letter(self): txt = self.active_letter val = ex.unival(txt) text = self.canvas_block.font.render("%s" % (val), 1, (220, 220, 220, 0)) font_x = ((self.board.scale*self.canvas_block.grid_w-self.canvas_block.font.size(val)[0])//2) font_y = ((self.board.scale*self.canvas_block.grid_h-self.canvas_block.font.size(val)[1])//2) - 3*self.board.scale txt2 = ex.unival(self.active_word) text2 = self.canvas_block.font3.render("%s" % (txt2), 1, (220, 220, 220, 0)) font_x2 = ((self.board.scale*self.canvas_block.grid_w-self.canvas_block.font3.size(txt2)[0])//2) font_y2 = ((self.board.scale*self.canvas_block.grid_h-self.canvas_block.font3.size(txt2)[1])//2) + 7*self.board.scale self.word_pos_y = font_y2 self.canvas.fill(self.bg_color) self.canvas.blit(text, (font_x,font_y)) self.canvas.blit(text2, (font_x2,font_y2)) self.copy_to_screen()
def next_image(self, direction=1): l = 100 if direction == 1: while l > self.max_word_len: self.w_index = self.current_image_index + 1 if self.w_index > len(self.words) - 1: self.w_index = 0 self.word = ex.unival(self.words[self.w_index]) if self.word[0] != "<": l = len(self.word) else: l = 100 self.current_image_index = self.w_index else: while l > self.max_word_len: self.w_index = self.current_image_index - 1 if self.w_index < 0: self.w_index = len(self.words) - 1 self.word = ex.unival(self.words[self.w_index]) if self.word[0] != "<": l = len(self.word) else: l = 100 self.current_image_index = self.w_index if self.mainloop.lang.lang == "ru": self.wordp = ex.unival(self.wordsp[self.w_index]) else: self.wordp = self.word # change image and pronunciation img_src = "%s.jpg" % self.imgs[self.w_index] self.picture.change_image( os.path.join('art4apps', self.category, img_src)) self.picture.speaker_val = self.wordp self.picture.update_me = True # change label and pronunciation self.label.set_value(self.word) self.label.speaker_val = self.wordp self.label.update_me = True self.mainloop.redraw_needed[0] = True
def check_letter_name(self, text): if sys.version_info < (3, 0): try: val = ex.unival(text) except: val = text if len(val) == 1 and len(self.lang.letter_names) > 0: t = ex.unival(val.lower()) for i in range(len(self.lang.alphabet_lc)): if t == ex.unival(self.lang.alphabet_lc[i]): text = self.lang.letter_names[i] break else: if len(text) == 1 and len(self.lang.letter_names) > 0: t = text.lower() for i in range(len(self.lang.alphabet_lc)): if t == self.lang.alphabet_lc[i]: text = self.lang.letter_names[i] break return text
def check_letter_name(self, text): if sys.version_info < (3, 0): try: val = ex.unival(text) except: val = text if len(val) == 1 and len(self.lang.letter_names) > 0: t = ex.unival(val.lower()) for i in range(len(self.lang.alphabet_lc)): if t == ex.unival(self.lang.alphabet_lc[i]): text = self.lang.letter_names[i] break else: if len(text) == 1 and len(self.lang.letter_names) > 0: t = text.lower() for i in range(len(self.lang.alphabet_lc)): if t == self.lang.alphabet_lc[i]: text = self.lang.letter_names[i] break return text
def check_result(self): result = [" " for i in range(self.data[0])] if self.board.grid[2] == self.solution_grid: for i in range(len(self.board.ships)): if self.board.ships[i].grid_y == 2: result[ self.board.ships[i].grid_x] = self.board.ships[i].value result_s = ''.join(result).strip() if ex.unival(self.word) == ex.unival(result_s): self.auto_check() self.level.next_board() else: if self.auto: self.auto_check() else: self.level.try_again() else: if self.auto: self.auto_check_reset() else: self.level.try_again()
def check_result(self): result = [" " for i in range(self.alphabet_len)] if self.board.grid[0] == self.board.grid[self.data[1] - 2] == self.solution_grid: for i in range(len(self.board.ships)): if self.board.ships[i].grid_y == 0: result[self.board.ships[i].grid_x] = self.board.ships[i].value elif self.board.ships[i].grid_y == self.data[1] - 2: if self.last_block and not self.lang.ltr_text: result[self.data[0] + self.board.ships[i].grid_x - 1] = self.board.ships[i].value else: result[self.data[0] + self.board.ships[i].grid_x] = self.board.ships[i].value if ((self.lang.ltr_text and self.word == result) or ( not self.lang.ltr_text and ex.unival(self.word) == ex.unival("".join(result)))): # self.update_score(self.points) self.level.next_board() else: if self.points > 0: self.points -= 1 self.level.try_again() else: self.level.try_again()
def __init__(self, configo, path): self.locale_dir = unival(os.path.join(path, 'locale/')) if 'LC_MESSAGES' in vars(locale): # linux locale.setlocale(locale.LC_MESSAGES, '') else: # windows locale.setlocale(locale.LC_ALL, '') self.config = configo self.alphabet_26 = ["en_GB", "en_US", "pt_PT"] self.def_imported = False self.trans = dict() self.lang_titles = self.config.lang_titles self.all_lng = self.config.all_lng self.ok_lng = self.config.ok_lng
def __init__(self, configo): lib_dir = os.path.abspath(os.path.dirname(sys.argv[0])) self.locale_dir = unival(os.path.join(lib_dir, 'locale/')) if 'LC_MESSAGES' in vars(locale): # linux locale.setlocale(locale.LC_MESSAGES, '') else: # windows locale.setlocale(locale.LC_ALL, '') #locale.setlocale(locale.LC_MESSAGES, '') # use user's preferred locale self.config = configo self.alphabet_26 = ["en_GB", "en_US", "pt_PT"] self.def_imported = False self.trans = dict() self.lang_titles = self.config.lang_titles self.all_lng = self.config.all_lng self.ok_lng = self.config.ok_lng
def __init__(self, configo): lib_dir = os.path.abspath(os.path.dirname(sys.argv[0])) self.locale_dir = unival(os.path.join(lib_dir, 'locale/')) if 'LC_MESSAGES' in vars(locale): # linux locale.setlocale(locale.LC_MESSAGES, '') else: # windows locale.setlocale(locale.LC_ALL, '') #locale.setlocale(locale.LC_MESSAGES, '') # use user's preferred locale self.config = configo self.alphabet_26 = ["en_GB","en_US","pt_PT"] self.def_imported = False self.trans = dict() self.lang_titles = self.config.lang_titles self.all_lng = self.config.all_lng self.ok_lng = self.config.ok_lng
def time2str(h, m): 'takes 2 variables: h - hour, m - minute, returns time as a string, ie. five to seven - for 6:55' if m > 30: if h == 12: h = 1 else: h += 1 # if sys.version_info < (3, 0): if sys.version_info[0] < 3: if m == 0: return unival(n2txt(h)) elif m == 1: return r(unicode(" דקה אחרי", "utf-8")) + n2txt(h) elif m == 15: return r(unicode(" רבע אחרי", "utf-8")) + n2txt(h) elif m == 30: return r(unicode("חצי אחרי ", "utf-8")) + n2txt(h) elif m == 45: return r(unicode("רבע ל ", "utf-8")) + n2txt(h) elif m == 59: return r(unicode("דקה ל ", "utf-8")) + n2txt(h) elif m < 30: return n2txt(m) + r(unicode(" אחרי ", "utf-8")) + n2txt(h) elif m > 30: return n2txt(60 - m) + r(unicode(" ל ", "utf-8")) + n2txt(h) return "" else: if m == 0: return n2txt(h) elif m == 1: return r(" דקה אחרי") + n2txt(h) elif m == 15: return r(" רבע אחרי") + n2txt(h) elif m == 30: return r("חצי אחרי ") + n2txt(h) elif m == 45: return r("רבע ל ") + n2txt(h) elif m == 59: return r("דקה ל ") + n2txt(h) elif m < 30: return n2txt(m) + r(" אחרי ") + n2txt(h) elif m > 30: return n2txt(60 - m) + r(" ל ") + n2txt(h) return ""
def n2txt(n, twoliner=False): """takes a number from 1 - 99 and returns it back in a word form, ie: 63 returns 'sixty three'.""" if 0 < n < 30: return r(numbers[n - 1]) elif 30 <= n < 100: m = n % 10 tens = r(numbers2090[(n // 10) - 2]) if m == 0: return tens elif m > 0: ones = r(numbers[m - 1]) return tens + unival(" و ") + ones elif n == 0: return r("صفر") elif n == 100: return r("مائة") else: return ""
def create_card(self, active): val = ex.unival(active.value) if sys.version_info < (3, 0): self.say(val[0].encode("utf-8")) else: self.say(val[0]) self.board.units[0].value = val[0] if self.lang.has_cursive: self.board.units[1].value = val[0] indx = [0, 1] if self.lang.has_uc: if self.lang.has_cursive: indx = [0, 1, 2, 3] self.board.units[2].value = val[1] self.board.units[3].value = val[1] else: self.board.units[1].value = val[1] self.board.ships[self.abc_len].value = self.word_list[active.unit_id] self.board.ships[self.abc_len].speaker_val = self.pword_list[active.unit_id] self.board.ships[self.abc_len + 1].set_value(self.word_list[active.unit_id]) self.board.ships[self.abc_len + 1].speaker_val = self.pword_list[active.unit_id] if self.lang.has_cursive: indx2 = [self.abc_len, self.abc_len + 1, self.abc_len + 2] self.board.ships[self.abc_len + 2].set_value(self.word_list[active.unit_id]) self.board.ships[self.abc_len + 2].speaker_val = self.pword_list[active.unit_id] else: indx2 = [self.abc_len, self.abc_len + 1] img_src = os.path.join('fc', "fc%03i.jpg" % self.frame_flow[active.unit_id]) self.slide.change_image(img_src) self.board.active_ship = -1 self.slide.update_me = True for i in indx: self.board.units[i].update_me = True for i in indx2: self.board.ships[i].update_me = True self.mainloop.redraw_needed[0] = True
def __init__(self, wnd, l, t, w, h, caption, img_src1, fsubmit, fargs): pygame.sprite.Sprite.__init__(self) self.wnd = wnd self.w = w self.h = h self.l = l self.t = t self.fsubmit = fsubmit self.fargs = fargs self.caption = ex.unival(caption) self.hover = False self.color = (255, 255, 255, 0) self.image = pygame.Surface([self.w, self.h], flags=pygame.SRCALPHA) self.rect = self.image.get_rect() self.rect.topleft = [self.l, self.t] self.img_src1 = img_src1 self.active_img = None self.load_images()
def check_result(self): if self.board.grid[0] == self.solution_grid: ships = [] # collect value and x position on the grid from ships list for i in range(self.data[2]): ships.append([self.board.ships[i].grid_x, self.board.ships[i].value]) ships_sorted = sorted(ships) correct = True for i in range(self.data[2]): if i < self.data[2] - 1: if ships_sorted[i][1] != ex.unival(self.alphabet[self.indexes[i]]): correct = False if correct: self.auto_check() self.level.next_board() else: self.auto_check() else: self.auto_check_reset()
def __init__(self, configo, path): self.locale_dir = unival(os.path.join(path, 'locale/')) if not os.path.isdir(self.locale_dir): self.locale_dir = "/usr/share/locale/" if 'LC_MESSAGES' in vars(locale): # linux locale.setlocale(locale.LC_MESSAGES, '') else: # windows locale.setlocale(locale.LC_ALL, '') self.config = configo self.alphabet_26 = ["en_GB", "en_US", "pt_PT"] self.def_imported = False self.trans = dict() self.lang_titles = self.config.lang_titles self.lang_progress = self.config.lang_progress self.all_lng = self.config.all_lng self.ok_lng = self.config.ok_lng self.tts_disabled_lngs = [] # will be overridden with data from xml self.xml_langs = classes.xml_conn.XMLLangs()
def render_textrect(self, string, font, rect, text_color, background_color, justification=0): """Returns a surface containing the passed text string, reformatted to fit within the given rect, word-wrapping as necessary. The text will be anti-aliased. Takes the following arguments: string - the text you wish to render. \n begins a new line. font - a Font object rect - a rectstyle giving the size of the surface requested. text_color - a three-byte tuple of the rgb value of the text color. ex (0, 0, 0) = BLACK background_color - a three-byte tuple of the rgb value of the surface. justification - 0 (default) left-justified 1 horizontally centered 2 right-justified Returns the following values: Success - a surface object with the text rendered onto it. Failure - raises a TextRectException if the text won't fit onto the surface. """ final_lines = [] string = ex.unival(string) requested_lines = string.splitlines() # Create a series of lines that will fit on the provided # rectangle. for requested_line in requested_lines: if font.size(requested_line)[0] > rect.width: words = requested_line.split(' ') # if any of our words are too long to fit, return. for word in words: if font.size(word)[0] >= rect.width: print("The word " + word + " is too long to fit in the rect passed.") # raise TextRectException, "The word " + word + " is too long to fit in the rect passed." # Start a new line accumulated_line = "" for word in words: test_line = accumulated_line + word + " " # Build the line while the words fit. if font.size(test_line)[0] < rect.width: accumulated_line = test_line else: final_lines.append(accumulated_line) accumulated_line = word + " " final_lines.append(accumulated_line) else: final_lines.append(requested_line) # Let's try to write the text out on the surface. surface = pygame.Surface(rect.size) surface.fill(background_color) accumulated_height = 0 for line in final_lines: if accumulated_height + font.size(line)[1] >= rect.height: print("Once word-wrapped, the text string was too tall to fit in the rect.") # raise TextRectException, "Once word-wrapped, the text string was too tall to fit in the rect." if line != "": tempsurface = font.render(line, 1, text_color) if justification == 0: surface.blit(tempsurface, (0, accumulated_height)) elif justification == 1: surface.blit(tempsurface, ((rect.width - tempsurface.get_width()) / 2, accumulated_height)) elif justification == 2: surface.blit(tempsurface, (rect.width - tempsurface.get_width(), accumulated_height)) else: print("Invalid justification argument: " + str(justification)) # raise TextRectException, "Invalid justification argument: " + str(justification) accumulated_height += font.size(line)[1] return surface
def create_game_objects(self, level = 1): if not self.lang.has_uc: self.level.lvl_count = 8 if self.level.lvl > self.level.lvl_count: self.level.lvl = self.level.lvl_count self.vis_buttons = [1,1,1,1,1,1,1,1,0] self.mainloop.info.hide_buttonsa(self.vis_buttons) s = random.randrange(190, 225) v = random.randrange(230, 255) h = random.randrange(0, 255) color0 = ex.hsv_to_rgb(h,40,230) #highlight 1 font_color = ex.hsv_to_rgb(h,255,140) self.alphabet_lc = self.lang.alphabet_lc self.alphabet_uc = self.lang.alphabet_uc self.alphabet_len = len(self.alphabet_lc) if self.alphabet_len % 2 == 0: self.alphabet_width = self.alphabet_len // 2 self.last_block = False else: self.alphabet_width = self.alphabet_len // 2 + 1 self.last_block = True #number of letters to find nlf = [0,0,0,0] aw = self.alphabet_width nlf[1] = aw if aw % 2 == 0: if (aw//2)%2 == 0: nlf[0] = aw // 2 else: nlf[0] = aw // 2 + 1 else: if (aw//2)%2 == 0: nlf[0] = aw // 2 + 1 else: nlf[0] = aw // 2 nlf[2] = nlf[0] + nlf[1] nlf[3] = aw * 2 - 4 if self.mainloop.m.game_variant == 0: if self.level.lvl == 1: data = [self.alphabet_width,6,self.alphabet_lc,0,nlf[0]] elif self.level.lvl == 2: data = [self.alphabet_width,6,self.alphabet_lc,0,nlf[1]] elif self.level.lvl == 3: data = [self.alphabet_width,6,self.alphabet_lc,0,nlf[2]] elif self.level.lvl == 4: data = [self.alphabet_width,6,self.alphabet_lc,0,nlf[3]] elif self.level.lvl == 5: data = [self.alphabet_width,6,self.alphabet_lc,1,nlf[0]] elif self.level.lvl == 6: data = [self.alphabet_width,6,self.alphabet_lc,1,nlf[1]] elif self.level.lvl == 7: data = [self.alphabet_width,6,self.alphabet_lc,1,nlf[2]] elif self.level.lvl == 8: data = [self.alphabet_width,6,self.alphabet_lc,1,nlf[3]] elif self.mainloop.m.game_variant == 1: if self.level.lvl == 1: data = [self.alphabet_width,6,self.alphabet_uc,0,nlf[0]] elif self.level.lvl == 2: data = [self.alphabet_width,6,self.alphabet_uc,0,nlf[1]] elif self.level.lvl == 3: data = [self.alphabet_width,6,self.alphabet_uc,0,nlf[2]] elif self.level.lvl == 4: data = [self.alphabet_width,6,self.alphabet_uc,0,nlf[3]] elif self.level.lvl == 5: data = [self.alphabet_width,6,self.alphabet_uc,1,nlf[0]] elif self.level.lvl == 6: data = [self.alphabet_width,6,self.alphabet_uc,1,nlf[1]] elif self.level.lvl == 7: data = [self.alphabet_width,6,self.alphabet_uc,1,nlf[2]] elif self.level.lvl == 8: data = [self.alphabet_width,6,self.alphabet_uc,1,nlf[3]] self.points = data[4] // 5 + (self.level.lvl+3) // 4 self.chapters = [1,4,8] self.data = data self.layout.update_layout(data[0],data[1]) self.board.level_start(data[0],data[1],self.layout.scale) self.word = self.data[2][:] word_len = self.alphabet_len if not self.lang.ltr_text: sx = "".join(self.word) sx = ex.unival(sx) self.word = sx[data[0]-1:0:-1] + sx[0] self.word += sx[word_len:data[0]-1:-1] chosen_indexes = [] index_list_org = [x for x in range(self.alphabet_len)] index_list = [x for x in range(self.alphabet_len)] lowered = [] for i in range(data[4]):#picking letters to lower index = random.randrange(0,len(index_list)) chosen_indexes.append(index_list[index]) lowered.append(index_list[index]) del(index_list[index]) random.shuffle(lowered) color = ((255,255,255)) #create table to store 'binary' solution self.solution_grid = [1 for x in range(data[0])] x = 0 y = 0 if data[4] < data[0]: x2 = (data[0]-len(lowered))//2 x3 = 0 else: x2 = 0 x3 = (data[0]-(len(lowered)-data[0]))//2#(word_len-(data[0]-len(lowered)))//2 y2 = 2 j = 0 h_step = 255 // self.alphabet_len for i in range(self.alphabet_len): picked = False if i in lowered: picked = True if data[3] == 1: s = 100 else: if self.lang.ltr_text: if picked: h = round(h_step*lowered[j]) else: h = round(h_step*index_list_org[i]) else: if picked: h = round(h_step*(self.alphabet_len - lowered[j])) else: h = round(h_step*(self.alphabet_len - index_list_org[i])) number_color = ex.hsv_to_rgb(h,s,v) #highlight 1 #change y if picked: if j < data[0]: xj = x2 + j else: xj = x3 + j-data[0] y2 = 3 caption = self.word[lowered[j]] self.board.add_unit(xj,y2,1,1,classes.board.Letter,caption,number_color,"",0) self.board.add_door(x,y,1,1,classes.board.Door,"",color,"") self.board.units[j].door_outline = True self.board.ships[i].highlight = False self.board.ships[i].outline_highlight = True j += 1 else: caption = self.word[i] self.board.add_unit(x,y,1,1,classes.board.Letter,caption,number_color,"",0) self.board.ships[i].immobilize() x += 1 if x >= data[0]: if not self.last_block: x = 0 else: if self.lang.ltr_text: x = 0 else: x = 1 y = data[1]-2 for each in self.board.units: self.board.all_sprites_list.move_to_front(each) if self.last_block: #if odd number of letters - add an empty square at the end if self.lang.ltr_text: x = data[0]-1 else: x = 0 #red self.board.add_unit(x,data[1]-2,1,1,classes.board.Label,"",color0,"",0) instruction = self.d["Complete abc"] self.board.add_unit(0,data[1]-1,data[0],1,classes.board.Letter,instruction,color0,"",5) self.board.ships[-1].font_color = font_color self.board.ships[-1].immobilize() self.board.ships[-1].speaker_val = self.dp["Complete abc"] self.board.ships[-1].speaker_val_update = False self.outline_all(0,1)
def create_game_objects(self, level = 1): self.board.draw_grid = False color = (234,218,225) #ex.hsv_to_rgb(225,15,235) self.color = color border_color = (105,12,100) letter_bg = (255,230,255) white = (255,255,255) font_color = (100,12,100) footer_font = (100,100,100) data = [19,13] if self.lang.lang == "pl": data = [26,13] elif self.lang.lang == "ru": data = [23,13] elif self.lang.lang == "uk": data = [21,13] #stretch width to fit the screen size x_count = self.get_x_count(data[1],even=True) if x_count > data[0]: data[0] = x_count self.data = data self.vis_buttons = [1,1,1,1,1,1,1,0,0] self.mainloop.info.hide_buttonsa(self.vis_buttons) self.layout.update_layout(data[0],data[1]) scale = self.layout.scale self.board.level_start(data[0],data[1],scale) base_len = data[0] - 2#(img_left - 1) * 2 + img_size img_size = 4 img_left = (base_len - img_size)//2 + 1 img_top = 2 gv = self.mainloop.m.game_variant if gv == 0: category = "animals" self.imgs = ['cow', 'turkey', 'shrimp', 'wolf', 'panther', 'panda', 'magpie', 'clam', 'pony', 'mouse', 'pug', 'koala', 'frog', 'ladybug', 'gorilla', 'llama', 'vulture', 'hamster', 'bird', 'starfish', 'crow', 'parakeet', 'caterpillar', 'tiger', 'hummingbird', 'piranha', 'pig', 'scorpion', 'fox', 'leopard', 'iguana', 'dolphin', 'bat', 'chick', 'crab', 'hen', 'wasp', 'chameleon', 'whale', 'hedgehog', 'fawn', 'moose', 'bee', 'viper', 'shrike', 'donkey', 'guinea_pig', 'sloth', 'horse', 'penguin', 'otter', 'bear', 'zebra', 'ostrich', 'camel', 'antelope', 'lemur', 'pigeon', 'lama', 'mole', 'ray', 'ram', 'skunk', 'jellyfish', 'sheep', 'shark', 'kitten', 'deer', 'snail', 'flamingo', 'rabbit', 'oyster', 'beaver', 'sparrow', 'dove', 'eagle', 'beetle', 'hippopotamus', 'owl', 'cobra', 'salamander', 'goose', 'kangaroo', 'dragonfly', 'toad', 'pelican', 'squid', 'lion_cub', 'jaguar', 'duck', 'lizard', 'rhinoceros', 'hyena', 'ox', 'peacock', 'parrot', 'elk', 'alligator', 'ant', 'goat', 'baby_rabbit', 'lion', 'squirrel', 'opossum', 'chimp', 'doe', 'gopher', 'elephant', 'giraffe', 'spider', 'puppy', 'jay', 'seal', 'rooster', 'turtle', 'bull', 'cat', 'lamb', 'rat', 'slug', 'buffalo', 'blackbird', 'swan', 'lobster', 'dog', 'mosquito', 'snake', 'chicken', 'anteater'] elif gv == 1: category = "sport" self.imgs = ['judo', 'pool', 'ride', 'stretch', 'helmet', 'ice_skating', 'walk', 'ran', 'run', 'swim', 'hop', 'hike', 'boxing', 'hockey', 'race', 'throw', 'skate', 'win', 'squat', 'ski', 'golf', 'whistle', 'torch', 'sailing', 'stand', 'tennis', 'jump', 'rowing', 'jog', 'rope'] elif gv == 2: category = "body" self.imgs = ['teeth', 'cheek', 'ankle', 'knee', 'toe', 'muscle', 'mouth', 'feet', 'hand', 'elbow', 'hair', 'eyelash', 'beard', 'belly_button', 'thumb', 'breast', 'nostril', 'nose', 'hip', 'arm', 'eyebrow', 'fist', 'neck', 'wrist', 'throat', 'eye', 'leg', 'spine', 'ear', 'finger', 'foot', 'braid', 'face', 'back', 'chin', 'bottom', 'thigh', 'belly'] elif gv == 3: category = "people" self.imgs = ['girl', 'male', 'son', 'mates', 'friends', 'baby', 'child', 'dad', 'mom', 'twin_boys', 'brothers', 'man', 'mother', 'grandfather', 'family', 'female', 'wife', 'husband', 'bride', 'madam', 'grandmother', 'couple', 'lad', 'twin_girls', 'tribe', 'boy', 'sisters', 'woman', 'lady'] elif gv == 4: category = "actions" self.imgs = ['lick', 'slam', 'beg', 'fell', 'scratch', 'touch', 'sniff', 'see', 'climb', 'dig', 'howl', 'sleep', 'explore', 'draw', 'hug', 'teach', 'nap', 'clay', 'catch', 'clap', 'cry', 'sing', 'meet', 'sell', 'peck', 'beat', 'kneel', 'find', 'dance', 'cough', 'cut', 'think', 'bark', 'speak', 'cheer', 'bake', 'write', 'punch', 'strum', 'study', 'plow', 'dream', 'post', 'dive', 'whisper', 'sob', 'shake', 'feed', 'crawl', 'camp', 'spill', 'clean', 'scream', 'tear', 'float', 'pull', 'ate', 'kiss', 'sit', 'hatch', 'blink', 'hear', 'smooch', 'play', 'wash', 'chat', 'drive', 'drink', 'fly', 'juggle', 'bit', 'sweep', 'look', 'knit', 'lift', 'fetch', 'read', 'croak', 'stare', 'eat'] elif gv == 5: category = "construction" self.imgs = ['lighthouse', 'door', 'circus', 'church', 'kennel', 'temple', 'smoke', 'chimney', 'brick', 'well', 'street', 'castle', 'store', 'staircase', 'school', 'farm', 'bridge', 'dam', 'pyramid', 'barn', 'mill', 'window', 'cabin', 'step', 'shop', 'shed', 'roof', 'steeple', 'garage', 'mosque', 'hospital', 'tent', 'house', 'wall', 'bank', 'shutter', 'hut'] elif gv == 6: category = "nature" self.imgs = ['land', 'cliff', 'hill', 'canyon', 'rock', 'sea', 'lake', 'coast', 'shore', 'mountain', 'pond', 'peak', 'lava', 'cave', 'dune', 'island', 'forest', 'desert', 'iceberg'] elif gv == 7: category = "jobs" self.imgs = ['clown', 'engineer', 'priest', 'vet', 'judge', 'chef', 'athlete', 'librarian', 'juggler', 'police', 'plumber', 'badge', 'queen', 'farmer', 'magic', 'knight', 'doctor', 'bricklayer', 'cleaner', 'teacher', 'hunter', 'soldier', 'musician', 'lawyer', 'fisherman', 'princess', 'fireman', 'nun', 'chief', 'pirate', 'cowboy', 'electrician', 'nurse', 'king', 'president', 'office', 'carpenter', 'jockey', 'worker', 'mechanic', 'pilot', 'actor', 'cook', 'student', 'butcher', 'accountant', 'prince', 'pope', 'sailor', 'boxer', 'ballet', 'coach', 'astronaut', 'painter', 'anaesthesiologist', 'scientist'] elif gv == 8: category = "clothes_n_accessories" self.imgs = ['jewellery', 'sock', 'jacket', 'heel', 'smock', 'shorts', 'pocket', 'necklace', 'sweatshirt', 'uniform', 'raincoat', 'trousers', 'sunglasses', 'coat', 'pullover', 'shirt', 'sandals', 'suit', 'pyjamas', 'skirt', 'zip', 'shoes', 'jewel', 'tie', 'slippers', 'gloves', 'hat', 'sleeve', 'cap', 'swimming_suit', 'sneaker', 'vest', 'glasses', 'shoelace', 'patch', 'scarf', 'shoe', 'button', 'dress', 'sash', 'shoe_sole', 'robe', 'pants', 'kimono', 'overalls'] elif gv == 9: category = "fruit_n_veg" self.imgs = ['carrot', 'blackberries', 'celery', 'turnip', 'cacao', 'peach', 'melon', 'grapefruit', 'broccoli', 'grapes', 'spinach', 'fig', 'kernel', 'radish', 'tomato', 'kiwi', 'asparagus', 'olives', 'cucumbers', 'beans', 'strawberry', 'peppers', 'raspberry', 'apricot', 'potatoes', 'peas', 'cabbage', 'cherries', 'squash', 'blueberries', 'pear', 'orange', 'pumpkin', 'avocado', 'garlic', 'onion', 'apple', 'lime', 'cauliflower', 'mango', 'lettuce', 'lemon', 'aubergine', 'artichokes', 'plums', 'leek', 'bananas', 'papaya'] elif gv == 10: category = "transport" self.imgs = ['sail', 'taxi', 'car', 'bike', 'raft', 'pedal', 'bus', 'handlebar', 'boat', 'truck', 'sleigh', 'carpet', 'motorcycle', 'train', 'ship', 'van', 'canoe', 'rocket', 'mast', 'sledge', 'bicycle'] elif gv == 11: category = "food" self.imgs = ['candy', 'sausage', 'hamburger', 'steak', 'fudge', 'doughnut', 'coconut', 'rice', 'ice_cream', 'jelly', 'yoghurt', 'dessert', 'pretzel', 'peanut', 'jam', 'feast', 'cookie', 'bacon', 'spice', 'coffee', 'pie', 'lemonade', 'chocolate', 'water_bottle', 'lunch', 'ice', 'sugar', 'sauce', 'soup', 'juice', 'fries', 'cake', 'mashed_potatoes', 'tea', 'bun', 'cheese', 'beef', 'sandwich', 'slice', 'sprinkle', 'pizza', 'flour', 'gum', 'spaghetti', 'roast', 'drink', 'stew', 'spread', 'meat', 'milk', 'meal', 'corn', 'bread', 'walnut', 'egg', 'hot_dog', 'ham'] self.words = self.d["a4a_%s" % category] self.level.games_per_lvl = 10 self.w_index = random.randint(0,len(self.words)-1) self.word = ex.unival(self.words[self.w_index]) #print(len(self.dp["a4a_animals"])) if self.mainloop.lang.lang == "ru" and gv > 12: self.wordsp = eval("self.dp['a4a_%s']" % category) self.wordp = ex.unival(self.wordsp[self.w_index]) else: self.wordp = self.word img_src = "%s.jpg" % self.imgs[self.w_index] w_len = len(self.word) n_letters = self.level.lvl + 1 if self.level.lvl == 3: if n_letters >= w_len: n_letters = w_len - 1 if n_letters > w_len or self.level.lvl == 5: n_letters = w_len #frame around image caption if self.mainloop.scheme is not None: clx = self.mainloop.scheme.u_color border_color = self.mainloop.scheme.u_font_color if self.mainloop.scheme_code == "BW": border_color = (253,253,253) else: clx = white #n_letters = 6 self.points = (n_letters//2) + 1 #frame around image self.board.add_door(img_left - 1,1,img_size+2,img_size+3,classes.board.Door,"",white,"",font_size = 2) self.board.units[-1].image.set_colorkey(None) #self.board.units[-1].set_outline(color = border_color, width = 1) self.board.add_door(1,img_size+3,base_len,3,classes.board.Door,"",clx,"",font_size = 2) self.board.units[-1].image.set_colorkey(None) #self.board.units[-1].set_outline(color = border_color, width = 1) #temp frame around word w = len(self.word) l = (data[0] - w) // 2 #dummy frame hiding bottome line of the image frame self.board.add_door(img_left - 1,img_size + img_top + 1,img_size +2,1,classes.board.Door,"",clx,"",font_size = 2) self.board.units[-1].image.set_colorkey(None) self.board.add_unit(img_left,img_top,img_size,img_size,classes.board.ImgShip,self.wordp,color,os.path.join('art4apps', category,img_src)) self.board.ships[-1].immobilize() choice_list = self.word[:] index_list = [x for x in range(w_len)] lowered_ind = [0 for x in range(w_len)] lowered = [] for i in range(n_letters):#picking letters to lower index = random.randrange(0,len(index_list)) lowered.append(choice_list[index_list[index]]) lowered_ind[index_list[index]] = 1 del(index_list[index]) random.shuffle(lowered) color = (255,255,255) #create table to store 'binary' solution self.solution_grid = [0 for x in range(data[0])] x = l y = img_size + img_top + 2 self.sol_grid_y = y x2 = (data[0]-len(lowered))//2 y2 = img_size + img_top + 5 j = 0 for i in range(len(self.word)): picked = False if lowered_ind[i] == 1: picked = True h = 0 number_color = letter_bg self.solution_grid[x] = 1 #change y if picked: caption = lowered[j] self.board.add_unit(x2+j,y2,1,1,classes.board.Letter,caption,number_color,"",0) self.board.add_door(x,y,1,1,classes.board.Door,"",color,"") self.board.units[-1].door_outline = True self.board.units[-1].perm_outline_color = border_color self.board.units[-1].perm_outline_width = 1 self.board.ships[-1].highlight = False self.board.ships[-1].outline_highlight = True self.board.ships[-1].set_outline(color = border_color, width = 1) self.board.ships[-1].font_color = font_color self.board.ships[-1].readable = False j += 1 else: caption = self.word[i] self.board.add_unit(x,y,1,1,classes.board.Letter,caption,number_color,"",0) self.board.ships[-1].draggable = False self.board.ships[-1].highlight = False self.board.ships[-1].outline_highlight = False self.board.ships[-1].set_outline(color = border_color, width = 2) self.board.ships[-1].font_color = font_color self.board.ships[-1].readable = False x += 1 for i in range(3, 3+n_letters): self.board.all_sprites_list.move_to_front(self.board.units[i]) footer_caption = self.lang.d["art4apps"] self.board.add_unit(0,data[1]-1,data[0],1,classes.board.Label,footer_caption,white,"",27) self.board.units[-1].font_color = footer_font
def create_game_objects(self, level=1): self.board.draw_grid = False color = (234, 218, 225) self.color = color border_color = ex.hsv_to_rgb(self.mainloop.cl.color_sliders[5][0] * 16, 200, 200) letter_bg = ex.hsv_to_rgb(self.mainloop.cl.color_sliders[5][0] * 16, 30, 255) font_color = ex.hsv_to_rgb(self.mainloop.cl.color_sliders[5][0] * 16, 255, 150) arrow_color = ex.hsv_to_rgb(self.mainloop.cl.color_sliders[5][0] * 16, 200, 200) img_top = 1 gv = self.mainloop.m.game_variant if gv == 0: category = "animals" self.imgs = [ 'cow', 'turkey', 'shrimp', 'wolf', 'panther', 'panda', 'magpie', 'clam', 'pony', 'mouse', 'pug', 'koala', 'frog', 'ladybug', 'gorilla', 'llama', 'vulture', 'hamster', 'bird', 'starfish', 'crow', 'parakeet', 'caterpillar', 'tiger', 'hummingbird', 'piranha', 'pig', 'scorpion', 'fox', 'leopard', 'iguana', 'dolphin', 'bat', 'chick', 'crab', 'hen', 'wasp', 'chameleon', 'whale', 'hedgehog', 'fawn', 'moose', 'bee', 'viper', 'shrike', 'donkey', 'guinea_pig', 'sloth', 'horse', 'penguin', 'otter', 'bear', 'zebra', 'ostrich', 'camel', 'antelope', 'lemur', 'pigeon', 'lama', 'mole', 'ray', 'ram', 'skunk', 'jellyfish', 'sheep', 'shark', 'kitten', 'deer', 'snail', 'flamingo', 'rabbit', 'oyster', 'beaver', 'sparrow', 'dove', 'eagle', 'beetle', 'hippopotamus', 'owl', 'cobra', 'salamander', 'goose', 'kangaroo', 'dragonfly', 'toad', 'pelican', 'squid', 'lion_cub', 'jaguar', 'duck', 'lizard', 'rhinoceros', 'hyena', 'ox', 'peacock', 'parrot', 'elk', 'alligator', 'ant', 'goat', 'baby_rabbit', 'lion', 'squirrel', 'opossum', 'chimp', 'doe', 'gopher', 'elephant', 'giraffe', 'spider', 'puppy', 'jay', 'seal', 'rooster', 'turtle', 'bull', 'cat', 'rat', 'slug', 'buffalo', 'blackbird', 'swan', 'lobster', 'dog', 'mosquito', 'snake', 'chicken', 'anteater' ] elif gv == 1: category = "sport" self.imgs = [ 'judo', 'pool', 'ride', 'stretch', 'helmet', 'ice_skating', 'walk', 'run', 'swim', 'hop', 'hike', 'boxing', 'hockey', 'race', 'throw', 'skate', 'win', 'squat', 'ski', 'golf', 'whistle', 'torch', 'sailing', 'stand', 'tennis', 'jump', 'rowing', 'jog', 'rope' ] elif gv == 2: category = "body" self.imgs = [ 'teeth', 'cheek', 'ankle', 'knee', 'toe', 'muscle', 'mouth', 'feet', 'hand', 'elbow', 'hair', 'eyelash', 'beard', 'belly_button', 'thumb', 'breast', 'nostril', 'nose', 'hip', 'arm', 'eyebrow', 'fist', 'neck', 'wrist', 'throat', 'eye', 'leg', 'spine', 'ear', 'finger', 'foot', 'braid', 'face', 'back', 'chin', 'bottom', 'thigh', 'belly' ] elif gv == 3: category = "people" self.imgs = [ 'girl', 'male', 'son', 'mates', 'friends', 'baby', 'child', 'dad', 'mom', 'twin_boys', 'brothers', 'man', 'mother', 'grandfather', 'family', 'female', 'wife', 'husband', 'bride', 'madam', 'grandmother', 'couple', 'lad', 'twin_girls', 'tribe', 'boy', 'sisters', 'woman', 'lady' ] elif gv == 4: category = "actions" self.imgs = [ 'lick', 'slam', 'beg', 'fell', 'scratch', 'touch', 'sniff', 'see', 'climb', 'dig', 'howl', 'sleep', 'explore', 'draw', 'hug', 'teach', 'nap', 'clay', 'catch', 'clap', 'cry', 'sing', 'meet', 'sell', 'peck', 'beat', 'kneel', 'find', 'dance', 'cough', 'cut', 'think', 'bark', 'speak', 'cheer', 'bake', 'write', 'punch', 'strum', 'study', 'plow', 'dream', 'post', 'dive', 'whisper', 'sob', 'shake', 'feed', 'crawl', 'camp', 'spill', 'clean', 'scream', 'tear', 'float', 'pull', 'ate', 'kiss', 'sit', 'hatch', 'blink', 'hear', 'smooch', 'play', 'wash', 'chat', 'drive', 'drink', 'fly', 'juggle', 'bit', 'sweep', 'look', 'knit', 'lift', 'fetch', 'read', 'croak', 'stare', 'eat' ] elif gv == 5: category = "construction" self.imgs = [ 'lighthouse', 'door', 'circus', 'church', 'kennel', 'temple', 'smoke', 'chimney', 'brick', 'well', 'street', 'castle', 'store', 'staircase', 'school', 'farm', 'bridge', 'dam', 'pyramid', 'barn', 'mill', 'window', 'cabin', 'step', 'shop', 'shed', 'roof', 'steeple', 'garage', 'mosque', 'hospital', 'tent', 'house', 'wall', 'bank', 'shutter', 'hut' ] elif gv == 6: category = "nature" self.imgs = [ 'land', 'cliff', 'hill', 'canyon', 'rock', 'sea', 'lake', 'coast', 'shore', 'mountain', 'pond', 'peak', 'lava', 'cave', 'dune', 'island', 'forest', 'desert', 'iceberg' ] elif gv == 7: category = "jobs" self.imgs = [ 'clown', 'engineer', 'priest', 'vet', 'judge', 'chef', 'athlete', 'librarian', 'juggler', 'police', 'plumber', 'badge', 'queen', 'farmer', 'magic', 'knight', 'doctor', 'bricklayer', 'cleaner', 'teacher', 'hunter', 'soldier', 'musician', 'lawyer', 'fisherman', 'princess', 'fireman', 'nun', 'pirate', 'cowboy', 'electrician', 'nurse', 'king', 'president', 'office', 'carpenter', 'jockey', 'worker', 'mechanic', 'pilot', 'actor', 'cook', 'student', 'butcher', 'accountant', 'prince', 'pope', 'sailor', 'boxer', 'ballet', 'coach', 'astronaut', 'painter', 'anaesthesiologist', 'scientist' ] elif gv == 8: category = "clothes_n_accessories" self.imgs = [ 'jewellery', 'sock', 'jacket', 'heel', 'smock', 'shorts', 'pocket', 'necklace', 'sweatshirt', 'uniform', 'raincoat', 'trousers', 'sunglasses', 'coat', 'pullover', 'shirt', 'sandals', 'suit', 'pyjamas', 'skirt', 'zip', 'shoes', 'jewel', 'tie', 'slippers', 'gloves', 'hat', 'sleeve', 'cap', 'swimming_suit', 'sneaker', 'vest', 'glasses', 'shoelace', 'patch', 'scarf', 'shoe', 'button', 'dress', 'sash', 'shoe_sole', 'robe', 'pants', 'kimono', 'overalls' ] elif gv == 9: category = "fruit_n_veg" self.imgs = [ 'carrot', 'blackberries', 'celery', 'turnip', 'cacao', 'peach', 'melon', 'grapefruit', 'broccoli', 'grapes', 'spinach', 'fig', 'kernel', 'radish', 'tomato', 'kiwi', 'asparagus', 'olives', 'cucumbers', 'beans', 'strawberry', 'peppers', 'raspberry', 'apricot', 'potatoes', 'peas', 'cabbage', 'cherries', 'squash', 'blueberries', 'pear', 'orange', 'pumpkin', 'avocado', 'garlic', 'onion', 'apple', 'lime', 'cauliflower', 'mango', 'lettuce', 'lemon', 'aubergine', 'artichokes', 'plums', 'leek', 'bananas', 'papaya' ] elif gv == 10: category = "transport" self.imgs = [ 'sail', 'taxi', 'car', 'bike', 'raft', 'pedal', 'bus', 'handlebar', 'boat', 'truck', 'sleigh', 'carpet', 'motorcycle', 'train', 'ship', 'van', 'canoe', 'rocket', 'mast', 'sledge', 'bicycle' ] elif gv == 11: category = "food" self.imgs = [ 'candy', 'sausage', 'hamburger', 'steak', 'fudge', 'doughnut', 'coconut', 'rice', 'ice_cream', 'jelly', 'yoghurt', 'dessert', 'pretzel', 'peanut', 'jam', 'feast', 'cookie', 'bacon', 'spice', 'coffee', 'pie', 'lemonade', 'chocolate', 'water_bottle', 'lunch', 'ice', 'sugar', 'sauce', 'soup', 'juice', 'fries', 'cake', 'mashed_potatoes', 'tea', 'bun', 'cheese', 'beef', 'sandwich', 'slice', 'sprinkle', 'pizza', 'flour', 'gum', 'spaghetti', 'roast', 'stew', 'spread', 'meat', 'milk', 'meal', 'corn', 'bread', 'walnut', 'egg', 'hot_dog', 'ham' ] self.category = category self.words = self.d["a4a_%s" % category] self.current_image_index = -1 self.max_image_index = len(self.words) - 1 l = 100 self.max_word_len = 35 while l > self.max_word_len: self.w_index = self.current_image_index + 1 if self.w_index > len(self.words) - 1: self.w_index = 0 self.word = ex.unival(self.words[self.w_index]) if self.word[0] != "<": l = len(self.word) else: l = 100 self.current_image_index = self.w_index if self.mainloop.lang.lang == "ru": self.wordsp = eval("self.dp['a4a_%s']" % category) self.wordp = ex.unival(self.wordsp[self.w_index]) else: self.wordp = self.word img_src = "%s.jpg" % self.imgs[self.w_index] w_len = len(self.word) self.mainloop.redraw_needed = [True, True, True] data = [14, 8] img_w_size = 4 img_h_size = 4 # stretch width to fit the screen size x_count = self.get_x_count(data[1], even=True) if x_count > data[0]: data[0] = x_count self.data = data self.board.set_animation_constraints(0, data[0], 0, data[1]) self.vis_buttons = [0, 0, 0, 0, 1, 0, 1, 0, 0] self.mainloop.info.hide_buttonsa(self.vis_buttons) self.layout.update_layout(data[0], data[1]) scale = self.layout.scale self.board.level_start(data[0], data[1], scale) self.board.board_bg.update_me = True self.board.board_bg.line_color = (20, 20, 20) base_len = data[0] - 2 img_left = (base_len - img_w_size) // 2 + 1 color_bg = (255, 255, 255) l = (data[0] - w_len) // 2 self.left_offset = l self.board.add_unit(img_left, img_top, img_w_size, img_h_size, classes.board.ImgShip, self.wordp, color_bg, os.path.join('art4apps', category, img_src)) self.picture = self.board.ships[-1] self.picture.immobilize() self.picture.highlight = False self.picture.outline_highlight = False self.picture.animable = False self.picture.outline = False self.picture.is_door = False self.picture.speaker_val = self.wordp self.picture.speaker_val_update = False self.board.add_unit(1, img_h_size + img_top + 1, data[0] - 2, 1, classes.board.Letter, self.word, letter_bg, "", 0) self.label = self.board.ships[-1] self.label.draggable = False self.label.highlight = False self.label.outline_highlight = False self.label.set_outline(color=border_color, width=2) self.label.font_color = font_color self.label.readable = True self.label.speaker_val = self.wordp self.label.speaker_val_update = False self.board.add_unit(img_left - 3, 2, 2, 2, classes.board.ImgCenteredShip, "", (0, 0, 0, 0), img_src='nav_l_mt.png', alpha=True) self.board.ships[-1].set_tint_color(arrow_color) self.lt = self.board.ships[-1] self.board.add_unit(img_left + 5, 2, 2, 2, classes.board.ImgCenteredShip, "", (0, 0, 0, 0), img_src='nav_r_mt.png', alpha=True) self.board.ships[-1].set_tint_color(arrow_color) self.rt = self.board.ships[-1] for each in self.board.ships: each.immobilize()
def __init__(self, android): self.font_multiplier = 1 self.font_line_height_adjustment = 1 self.font_start_at_adjustment = 0 self.font_variant = 0 self.version = ver self.avail_version = "" self.update_available = False self.settings_changed = False self.fs_width = 1024 self.fs_height = 768 self.debug_screen_size = None # [900,600] # size_limits - don't let window resizing get out of hand [min_w, min_h, max_w, max_h] self.size_limits = [838, 570, 2000, 2000] # [670,480,2000,2000] #800 - minimum to fit all buttons, 2000 - with over 2000 pixels each way pygame is not redrawing very well # set total size of OS panels and window decorations on both sides - used in windowed version. Not so much important now with resizing enabled. # this will not be auto-detected self.os_panels_w = 2 # sum of widths of non-hiding vertical Panels (if any) and window border (1px on each side). self.os_panels_h = 52 # sum of heights of non-hiding horizontal panels (ie. menu bar(s) + application bar + window bar + border, etc.). # the game will 'remember' at what level each game has been left and it will save this data for next session if the save_levels is left at True # to reset the game - remove the level_data.txt file check below for the location of these files - it will be recreated next time you close the game # if the pickle has been saved with python3 then python2 will not be able to open it and will reset all levels to 1 # the data is automatically saved to file every time you switch game and on exit. self.save_levels = True # the following 2 settings will be overridden by configuration file # to change any of these do this in the in-game preferences, except fullscreen if there's no config file the value below will be used. self.fullscreen = False # self.read_inst = False #no longer used self.check_updates = True self.user_age_group = 0 # default group - showing all games - TO DO: will be overridden by data stored in database self.max_age = 7 # Window title self.window_caption = "eduActiv8 - v " + self.version self.db_file_name = 'eduactiv8.db' """ #file names paths to level and language files $XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored. If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used. $XDG_CONFIG_HOME defines the base directory relative to which user specific configuration files should be stored. If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used. """ if android is None: p = sys.platform directory = os.path.dirname( os.path.abspath(os.path.expanduser("~/.config/eduactiv8/"))) self.window_pos = (3, 30) if p == "linux" or p == "linux2": # self.window_pos = (10,30) self.platform = "linux" try: xdg_data_home = os.environ.get('XDG_DATA_HOME') except: xdg_data_home = None if xdg_data_home is None or xdg_data_home == "": home = os.environ.get('HOME') directory = os.path.join(home, '.local', 'share', 'eduactiv8') else: directory = os.path.join(xdg_data_home, 'eduactiv8') elif p == "win32" or p == "cygwin": #windows or other non linux operating system self.platform = "windows" elif p == "darwin": self.platform = "macos" self.window_pos = (0, 0) self.os_panels_w = 0 # sum of widths of non-hiding vertical Panels (if any) and window border (1px on each side). self.os_panels_h = 120 self.file_db = os.path.join(directory, self.db_file_name) else: # android folder creation self.platform = "android" self.window_pos = (0, 0) directory = "assets" self.file_db = os.path.join(directory, self.db_file_name) try: if not os.path.exists(directory): os.makedirs(directory) except: print( "Error - can't create directory. The game data won't be saved." ) # default settings self.loaded_settings = False """ lang, sounds, espeak, screenw, screenh """ # [0 language, 1 talkative, 2 untranslated languages, 3 full screen, 4 user_name, 5 screen_w, 6 screen_h] self.settings = dict() try: import pyfribidi self.fribidi_loaded = True self.frididi = pyfribidi s = ex.unival('العربية') self.arabic = self.frididi.log2vis(s) except: self.fribidi_loaded = False self.frididi = None self.arabic = "Arabic" self.set_font_family() if self.fribidi_loaded: self.lang_titles = [ "English", "American English", "Català", "Deutsch", "Español", "Français", "Italiano", "Lakȟótiyapi", "Polski", "Português", "Suomalainen", "Ελληνικά", "Русский", "Српски", "Українська", "תירבע", self.arabic ] self.all_lng = [ "en_GB", "en_US", "ca", "de", "es_ES", "fr", "it", "lkt", "pl", "pt_PT", "fi", "el", "ru", "sr", "uk", "he", "ar" ] self.ok_lng = [ "en_GB", "en_US", "ca", "de", "es_ES", "fr", "it", "lkt", "pl", "pt_PT", "fi", "el", "ru", "sr", "uk", "he" ] else: self.lang_titles = [ "English", "American English", "Català", "Deutsch", "Español", "Français", "Italiano", "Lakȟótiyapi", "Polski", "Português", "Suomalainen", "Ελληνικά", "Русский", "Српски", "Українська", "תירבע" ] self.all_lng = [ "en_GB", "en_US", "ca", "de", "es_ES", "fr", "it", "lkt", "pl", "pt_PT", "fi", "el", "ru", "sr", "uk", "he" ] self.ok_lng = [ "en_GB", "en_US", "ca", "de", "es_ES", "fr", "it", "lkt", "pl", "pt_PT", "fi", "el", "ru", "sr", "uk", "he" ] self.id2lng = { 1: "English", 5: "Català", 19: "Српски", 12: "Deutsch", 8: "Español", 16: "Ελληνικά", 17: "תירבע", 11: "Italiano", 20: "Lakȟótiyapi", 3: "Polski", 9: "Português", 13: "Русский", 15: "Suomalainen", 14: "Українська", 2: self.arabic, 10: "Français" } self.id2imgsuffix = { 1: "", 5: "", 18: "ru", 12: "", 8: "", 16: "el", 17: "he", 11: "", 20: "", 3: "", 9: "", 13: "ru", 15: "", 14: "ru", 2: "ar", 10: "" } """
def create_game_objects(self, level=1): self.board.draw_grid = False if not self.lang.has_uc: self.level.lvl_count = 8 if self.level.lvl > self.level.lvl_count: self.level.lvl = self.level.lvl_count self.vis_buttons = [0, 1, 1, 1, 1, 0, 1, 1, 1] self.mainloop.info.hide_buttonsa(self.vis_buttons) v = 255 h = random.randrange(0, 255) color0 = ex.hsv_to_rgb(h, 40, 230) # highlight 1 lvl_data = self.mainloop.xml_conn.get_level_data( self.mainloop.m.game_dbid, self.mainloop.config.user_age_group, self.level.lvl) self.chapters = self.mainloop.xml_conn.get_chapters( self.mainloop.m.game_dbid, self.mainloop.config.user_age_group) self.alphabet_lc = self.lang.alphabet_lc self.alphabet_uc = self.lang.alphabet_uc self.alphabet_len = len(self.alphabet_lc) if self.alphabet_len % 2 == 0: self.alphabet_width = self.alphabet_len // 2 self.last_block = False else: self.alphabet_width = self.alphabet_len // 2 + 1 self.last_block = True # number of letters to find self.font_size = 0 if self.mainloop.lang.lang == "lkt": self.font_size = 1 if self.mainloop.m.game_variant == 0: data = [self.alphabet_width, 5, self.alphabet_lc] else: data = [self.alphabet_width, 5, self.alphabet_uc] data.extend(lvl_data) nlf = min(int(self.alphabet_len * data[4] / 100), self.alphabet_len) self.data = data self.board.set_animation_constraints(0, data[0], 0, data[1]) self.layout.update_layout(data[0], data[1]) self.board.level_start(data[0], data[1], self.layout.scale) self.unit_mouse_over = None self.units = [] self.word = self.data[2][:] word_len = self.alphabet_len if not self.lang.ltr_text: sx = "".join(self.word) sx = ex.unival(sx) self.word = sx[data[0] - 1:0:-1] + sx[0] self.word += sx[word_len:data[0] - 1:-1] chosen_indexes = [] index_list_org = [x for x in range(self.alphabet_len)] index_list = [x for x in range(self.alphabet_len)] lowered = [] for i in range(nlf): # picking letters to lower index = random.randrange(0, len(index_list)) chosen_indexes.append(index_list[index]) lowered.append(index_list[index]) del (index_list[index]) random.shuffle(lowered) # create table to store 'binary' solution self.solution_grid = [1 for x in range(data[0])] x = 0 y = 0 if nlf < data[0]: x2 = (data[0] - len(lowered)) // 2 x3 = 0 else: x2 = 0 x3 = (data[0] - (len(lowered) - data[0])) // 2 y2 = 2 j = 0 h_step = 255 // self.alphabet_len s = 128 self.positions = [] for i in range(self.alphabet_len): self.positions.append((x, y)) x += 1 if x >= data[0]: if not self.last_block: x = 0 else: if self.lang.ltr_text: x = 0 else: x = 1 y = data[1] - 1 x = 0 y = 0 if self.mainloop.scheme is None: dc_img_src = os.path.join('unit_bg', "universal_sq_dc.png") else: dc_img_src = None bg_img_src = os.path.join('unit_bg', "universal_sq_bg.png") bg_door_img_src = os.path.join('unit_bg', "universal_sq_door.png") for i in range(self.alphabet_len): picked = False if i in lowered: picked = True if data[3] == 1: door_color = ex.hsv_to_rgb(h, s, v) else: if self.lang.ltr_text: door_color = ex.hsv_to_rgb(h_step * i, s, v) else: door_color = ex.hsv_to_rgb( h_step * (self.alphabet_len - i), s, v) if self.lang.ltr_text: if picked: h = round(h_step * lowered[j]) else: h = round(h_step * index_list_org[i]) else: if picked: h = round(h_step * (self.alphabet_len - lowered[j])) else: h = round(h_step * (self.alphabet_len - index_list_org[i])) number_color = ex.hsv_to_rgb(h, self.mainloop.cl.bg_color_s, self.mainloop.cl.bg_color_v) font_color = [ ex.hsv_to_rgb(h, self.mainloop.cl.font_color_s, self.mainloop.cl.font_color_v), ] fg_number_color = ex.hsv_to_rgb(h, self.mainloop.cl.fg_hover_s, self.mainloop.cl.fg_hover_v) if picked: if j < data[0]: xj = x2 + j else: xj = x3 + j - data[0] y2 = 3 caption = self.word[lowered[j]] self.board.add_universal_unit(grid_x=xj, grid_y=y2, grid_w=1, grid_h=1, txt=caption, fg_img_src=bg_img_src, bg_img_src=bg_img_src, dc_img_src=dc_img_src, bg_color=(0, 0, 0, 0), border_color=None, font_color=font_color, bg_tint_color=number_color, fg_tint_color=fg_number_color, txt_align=(0, 0), font_type=self.font_size, multi_color=False, alpha=True, immobilized=False, fg_as_hover=True) self.units.append(self.board.ships[-1]) # add new door self.board.add_universal_unit(grid_x=x, grid_y=y, grid_w=1, grid_h=1, txt=None, fg_img_src=None, bg_img_src=bg_door_img_src, dc_img_src=None, bg_color=(0, 0, 0, 0), border_color=None, font_color=None, bg_tint_color=door_color, fg_tint_color=None, txt_align=(0, 0), font_type=10, multi_color=False, alpha=True, immobilized=True, mode=2) self.board.ships[i].idx = i self.board.ships[i].checkable = True self.board.ships[i].init_check_images() self.board.ships[i].home_location = self.positions[lowered[j]] j += 1 else: caption = self.word[i] self.board.add_universal_unit(grid_x=x, grid_y=y, grid_w=1, grid_h=1, txt=caption, fg_img_src=None, bg_img_src=bg_img_src, dc_img_src=dc_img_src, bg_color=(0, 0, 0, 0), border_color=None, font_color=font_color, bg_tint_color=number_color, fg_tint_color=None, txt_align=(0, 0), font_type=self.font_size, multi_color=False, alpha=True, immobilized=True) self.board.ships[i].idx = i x += 1 if x >= data[0]: if not self.last_block: x = 0 else: if self.lang.ltr_text: x = 0 else: x = 1 y = data[1] - 1 for each in self.board.units: self.board.all_sprites_list.move_to_front(each) if self.last_block: # if odd number of letters - add an empty square at the end if self.lang.ltr_text: x = data[0] - 1 else: x = 0 self.board.add_unit(x, data[1] - 1, 1, 1, classes.board.Label, "", color0, "", 0) self.outline_all(0, 1)
def get_lang_attr(self): filename = os.path.join(self.locale_dir, self.lang, "LC_MESSAGES", "pysiogame.mo") #filename = "locale/%s/LC_MESSAGES/pysiogame.mo" % self.lang try: #print("Opening message file %s for locale %s" % (filename, self.lang) ) self.trans[self.lang] = gettext.GNUTranslations(open( filename, "rb" ) ) except IOError: print("Locale not found. Using default messages") self.trans[self.lang] = gettext.NullTranslations() self.trans[self.lang].install() import i18n.custom.default self.oi18n = i18n.custom.default.I18n() self.ltr_text = True self.ltr_numbers = True self.ltr_math = True self.has_uc = True self.has_cursive = True font_variant = 0 self.ico_suffix = "" self.lang_id = 0 # used to identify the language in database - do not reorganize numbers when adding new language if self.lang == 'en_US': import i18n.custom.en_us import i18n.custom.word_lists.en_us_di import i18n.custom.kbrd.en_us import i18n.custom.kbrd.en_course #self.voice = ["-s 170","-a 100","-p 80","-ven-us+m1"] self.voice = ["-ven-us+m1"] self.di = i18n.custom.word_lists.en_us_di.di self.lang_file = i18n.custom.en_us self.kbrd = i18n.custom.kbrd.en_us self.kbrd_course_mod = i18n.custom.kbrd.en_course self.lang_id = 1 elif self.lang == 'pl': import i18n.custom.pl import i18n.custom.word_lists.pl_di import i18n.custom.kbrd.pl import i18n.custom.kbrd.pl_course #self.voice = ["-s 160","-a 100","-p 80","-vpl+m1"] #"-g 5", self.voice = ["-vpl+m1"] self.di = i18n.custom.word_lists.pl_di.di self.lang_file = i18n.custom.pl self.kbrd = i18n.custom.kbrd.pl self.kbrd_course_mod = i18n.custom.kbrd.pl_course self.lang_id = 3 elif self.lang == 'sk': import i18n.custom.sk import i18n.custom.word_lists.sk_di #self.voice = ["-s 160","-a 100","-p 80","-vpl+m1"] #"-g 5", self.voice = ["-vsk+m1"] self.di = i18n.custom.word_lists.sk_di.di self.lang_file = i18n.custom.sk self.lang_id = 4 elif self.lang == 'ca': import i18n.custom.ca import i18n.custom.word_lists.ca_di self.voice = ["-vca+m1"] self.di = i18n.custom.word_lists.ca_di.di self.lang_file = i18n.custom.ca self.lang_id = 5 elif self.lang == 'da': import i18n.custom.da import i18n.custom.word_lists.da_di self.voice = ["-vda+m1"] self.di = i18n.custom.word_lists.da_di.di self.lang_file = i18n.custom.da self.lang_id = 6 elif self.lang == 'nl': import i18n.custom.nl import i18n.custom.word_lists.nl_di self.voice = ["-vnl+m1"] self.di = i18n.custom.word_lists.nl_di.di self.lang_file = i18n.custom.nl self.lang_id = 7 elif self.lang == 'es_ES': import i18n.custom.es import i18n.custom.word_lists.es_di self.voice = ["-ves+m1"] self.di = i18n.custom.word_lists.es_di.di self.lang_file = i18n.custom.es self.lang_id = 8 elif self.lang == 'pt_PT': import i18n.custom.pt import i18n.custom.word_lists.pt_di self.voice = ["-vpt-pt+m1"] self.di = i18n.custom.word_lists.pt_di.di self.lang_file = i18n.custom.pt self.lang_id = 9 elif self.lang == 'fr': import i18n.custom.fr import i18n.custom.word_lists.fr_di self.voice = ["-vfr+m1"] self.di = i18n.custom.word_lists.fr_di.di self.lang_file = i18n.custom.fr self.lang_id = 10 elif self.lang == 'it': import i18n.custom.it import i18n.custom.word_lists.it_di self.voice = ["-vit+m1"] self.di = i18n.custom.word_lists.it_di.di self.lang_file = i18n.custom.it self.lang_id = 11 elif self.lang == 'de': import i18n.custom.de import i18n.custom.word_lists.de_di self.voice = ["-vde+m1"] self.di = i18n.custom.word_lists.de_di.di self.lang_file = i18n.custom.de self.lang_id = 12 elif self.lang == 'ru': import i18n.custom.ru import i18n.custom.word_lists.ru_di import i18n.custom.kbrd.ru import i18n.custom.kbrd.ru_course #self.voice = ["-s 130","-a 100","-p 80","-vru+m1"] #self.voice = ["-vru+m1"] s 150 -vru self.voice = ["-s 150","-vru"] self.di = i18n.custom.word_lists.ru_di.di self.lang_file = i18n.custom.ru self.kbrd = i18n.custom.kbrd.ru self.kbrd_course_mod = i18n.custom.kbrd.ru_course self.time2spk = self.lang_file.time2spk self.time2officialstr = self.lang_file.time2officialstr self.time2officialspk = self.lang_file.time2officialspk self.ico_suffix = "ru" self.lang_id = 13 elif self.lang == 'uk': import i18n.custom.uk import i18n.custom.word_lists.uk_di import i18n.custom.kbrd.uk import i18n.custom.kbrd.uk_course self.voice = None self.di = i18n.custom.word_lists.uk_di.di self.lang_file = i18n.custom.uk self.kbrd = i18n.custom.kbrd.uk self.kbrd_course_mod = i18n.custom.kbrd.uk_course self.ico_suffix = "ru" self.lang_id = 14 elif self.lang == 'fi': import i18n.custom.fi import i18n.custom.word_lists.fi_di self.voice = ["-vfi+m1"] self.di = i18n.custom.word_lists.fi_di.di self.lang_file = i18n.custom.fi self.lang_id = 15 elif self.lang == 'el': #Greek import i18n.custom.el import i18n.custom.word_lists.el_di import i18n.custom.kbrd.el import i18n.custom.kbrd.el_course self.voice = ["-vel+m1"] self.di = i18n.custom.word_lists.el_di.di self.lang_file = i18n.custom.el self.kbrd = i18n.custom.kbrd.el self.kbrd_course_mod = i18n.custom.kbrd.el_course self.ico_suffix = "el" self.lang_id = 16 elif self.lang == 'he': #Hebrew import i18n.custom.he import i18n.custom.word_lists.he_di self.voice = ["-ven+m1"]#None self.di = i18n.custom.word_lists.he_di.di self.lang_file = i18n.custom.he self.time2spk = self.lang_file.time2spk self.ltr_text = False self.has_uc = False self.has_cursive = False self.alpha = i18n.custom.he.alpha self.n2spk = self.lang_file.n2spk #font_variant = 1 self.ico_suffix = "he" self.lang_id = 17 elif self.lang == 'ar': #Arabic import i18n.custom.ar import i18n.custom.word_lists.ar_di self.voice = None self.di = i18n.custom.word_lists.ar_di.di self.lang_file = i18n.custom.ar self.ltr_text = False self.has_uc = False self.has_cursive = False self.alpha = i18n.custom.ar.alpha self.n2spk = self.lang_file.n2spk self.ico_suffix = "ar" self.lang_id = 2 elif self.lang == 'te_ST': import i18n.custom.te_st import i18n.custom.word_lists.te_st_di self.voice = ["-ven+m1"] self.di = i18n.custom.word_lists.te_st_di.di self.lang_file = i18n.custom.te_st self.lang_id = 1 else:# self.lang == 'en_GB': import i18n.custom.en_gb import i18n.custom.word_lists.en_gb_di import i18n.custom.kbrd.en_gb import i18n.custom.kbrd.en_course self.voice = ["-ven+m1"] self.di = i18n.custom.word_lists.en_gb_di.di self.lang_file = i18n.custom.en_gb self.kbrd = i18n.custom.kbrd.en_gb self.kbrd_course_mod = i18n.custom.kbrd.en_course self.lang_id = 1 if self.lang in ["ar","he"]: self.config.font_multiplier = 1.1 self.config.font_line_height_adjustment = 1.5 self.config.font_start_at_adjustment = 5 else: self.config.font_multiplier = 1 self.config.font_line_height_adjustment = 1 self.config.font_start_at_adjustment = 0 if self.lang not in ["en_gb","en_us","pl","ru","el","uk"]: import i18n.custom.kbrd.en_gb import i18n.custom.kbrd.en_course self.kbrd = i18n.custom.kbrd.en_gb self.kbrd_course_mod = i18n.custom.kbrd.en_course self.d = dict() self.b = dict() self.dp = dict() self.kbrd_course = self.kbrd_course_mod.course self.d.update(self.oi18n.d) self.d.update(self.lang_file.d) self.b.update(self.oi18n.b) self.numbers = self.lang_file.numbers self.numbers2090 = self.lang_file.numbers2090 self.n2txt = self.lang_file.n2txt self.time2str = self.lang_file.time2str self.solid_names = self.oi18n.solid_names self.shape_names = self.oi18n.shape_names self.letter_names = self.lang_file.letter_names self.config.set_font_family(font_variant) if not self.ltr_text: for each_d in [self.d, self.b]: for key in each_d.keys(): if isinstance(each_d[key], list): for index in range(len(each_d[key])): if sys.version_info < (3, 0): if isinstance(each_d[key][index], basestring): each_d[key][index] = reverse(each_d[key][index], self.alpha, self.lang) else: if isinstance(each_d[key][index], str): each_d[key][index] = reverse(each_d[key][index], self.alpha, self.lang) else: each_d[key] = reverse(each_d[key], self.alpha, self.lang) for each in [self.solid_names, self.shape_names]: for index in range(len(each)): if sys.version_info < (3, 0): if isinstance(each[index], basestring): each[index] = reverse(each[index], self.alpha, self.lang) else: if isinstance(each[index], str): each[index] = reverse(each[index], self.alpha, self.lang) self.dp.update(self.d) #if self.lang == 'ru' or self.lang == 'he': self.dp.update(self.lang_file.dp) if self.lang == "he": s = unival(self.d['abc_flashcards_word_sequence'][0]) if len(s) > 0: if s[0] == unival("א"): self.d['abc_flashcards_word_sequence'] = self.d['abc_flashcards_word_sequencer'] self.alphabet_lc = self.lang_file.alphabet_lc self.alphabet_uc = self.lang_file.alphabet_uc self.accents_lc = self.lang_file.accents_lc self.accents_uc = self.lang_file.accents_uc
def __init__(self): self.font_multiplier = 1 self.font_line_height_adjustment = 1 self.font_start_at_adjustment = 0 self.font_variant = 0 self.version = ver self.settings_changed = False self.fs_width = 1024 self.fs_height = 768 #size_limits - don't let window resizing get out of hand [min_w, min_h, max_w, max_h] self.size_limits = [800,480,2000,2000] #[670,480,2000,2000] #800 - minimum to fit all buttons, 2000 - with over 2000 pixels each way pygame is not redrawing very well #set total size of OS panels and window decorations on both sides - used in windowed version. Not so much important now with resizing enabled. #this will not be auto-detected self.os_panels_w = 2 #sum of widths of non-hiding vertical Panels (if any) and window border (1px on each side). self.os_panels_h = 52 #sum of heights of non-hiding horizontal panels (ie. menu bar(s) + application bar + window bar + border, etc.). #the game will 'remember' at what level each game has been left and it will save this data for next session if the save_levels is left at True #to reset the game - remove the level_data.txt file check below for the location of these files - it will be recreated next time you close the game #if the pickle has been saved with python3 then python2 will not be able to open it and will reset all levels to 1 #the data is automatically saved to file every time you switch game and on exit. self.save_levels = True #the following 2 settings will be overridden by configuration file #to change any of these do this in the in-game preferences, except fullscreen if there's no config file the value below will be used. self.fullscreen = False #self.read_inst = False #no longer used self.google_trans_languages = False self.user_age_group = 0 # default group - showing all games - TO DO: will be overridden by data stored in database #Window title self.window_caption = "pySioGame - v " + self.version """ #file names paths to level and language files $XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored. If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used. $XDG_CONFIG_HOME defines the base directory relative to which user specific configuration files should be stored. If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used. """ p = sys.platform if p == "linux" or p == "linux2": self.window_pos = (3,30) #self.window_pos = (10,30) self.platform = "linux" try: xdg_data_home = os.environ.get('XDG_DATA_HOME') except: xdg_data_home = None if xdg_data_home is None or xdg_data_home == "": home = os.environ.get('HOME') directory = os.path.join(home,'.local','share', 'pysiogame') else: directory = os.path.join(xdg_data_home, 'pysiogame') self.file_db = os.path.join(directory, 'pysiogame3.db') else: #if p == "darwin" or p == "win32" or p == "cygwin": self.window_pos = (3,30) self.platform = "windows" directory = os.path.dirname(os.path.abspath(os.path.expanduser("~/.config/pysiogame/"))) self.file_db = os.path.join(directory, 'pysiogame3.db') try: if not os.path.exists(directory): os.makedirs(directory) except: print("Error - can't create directory. The game data won't be saved.") #default settings self.loaded_settings = False """ lang, sounds, espeak, screenw, screenh """ #[0 language, 1 talkative, 2 untranslated languages, 3 full screen, 4 user_name, 5 screen_w, 6 screen_h] self.settings = dict() try: import pyfribidi self.fribidi_loaded = True self.frididi = pyfribidi s = ex.unival('العربية') self.arabic = self.frididi.log2vis(s) except: self.fribidi_loaded = False self.frididi = None self.arabic = "Arabic" self.set_font_family() if self.fribidi_loaded: self.lang_titles = ["English", "American English", "Català", "Español", "Ελληνικά", "תירבע", "Italiano", "Polski", "Português", "Русский", "Suomalainen","Українська",self.arabic,"Dansk","Deutsch","Français","Nederlands", "Slovenčina", "Test Language"] self.all_lng = ["en_GB", "en_US", "ca", "es_ES", "el","he","it", "pl" ,"pt_PT","ru","fi","uk","ar","da","de","fr","nl","sk","te_ST"] self.ok_lng = ["en_GB", "en_US", "ca", "es_ES", "el","he","it", "pl" ,"pt_PT", "ru", "fi","uk"] else: self.lang_titles = ["English", "American English", "Català", "Español", "Ελληνικά", "תירבע", "Italiano", "Polski", "Português", "Русский", "Suomalainen","Українська","Dansk","Deutsch","Français","Nederlands", "Slovenčina", "Test Language"] self.all_lng = ["en_GB", "en_US", "ca", "es_ES", "el","he","it", "pl" ,"pt_PT","ru","fi","uk","da","de","fr","nl","sk","te_ST"] self.ok_lng = ["en_GB", "en_US", "ca", "es_ES", "el","he","it", "pl" ,"pt_PT", "ru", "fi","uk"] self.id2lng = {1:"English", 5:"Català", 8:"Español", 16:"Ελληνικά", 17:"תירבע", 11:"Italiano", 3:"Polski", 9:"Português", 13:"Русский", 15:"Suomalainen",14:"Українська",2:self.arabic,6:"Dansk",12:"Deutsch",10:"Français",7:"Nederlands", 4:"Slovenčina"} self.id2imgsuffix = {1:"", 5:"", 8:"", 16:"el", 17:"he", 11:"", 3:"", 9:"", 13:"ru", 15:"",14:"ru",2:"ar",6:"",12:"",10:"",7:"", 4:""}
def display_text(self): if self.value is not None and self.show_value: if not self.multi_color: if sys.version_info < (3, 0): if isinstance(self.value, basestring): # if a passed argument is a string turn it into a 1 item list if self.font.size(self.value)[0] < self.rect.w - self.margin_x or not self.text_wrap: value = [self.value] else: # else enter extra line breaks if len(self.value) > 5: line = "" test_line = "" word = "" value = [] try: valx = unicode(self.value, "utf-8") except UnicodeDecodeError: valx = self.value except TypeError: valx = self.value linelen = len(valx) for i in range(linelen): if valx[i] == "\n": test_line = "" + word word = "" value.append(line) line = "" + test_line elif valx[i] == " " or i == linelen - 1: test_line = test_line + word + valx[i] if self.font.size(test_line)[0] < self.rect.w - self.margin_x: line = "" + test_line word = "" else: test_line = "" + word + valx[i] word = "" value.append(line) line = "" + test_line else: word += valx[i] if len(test_line) > 0: value.append(test_line) else: value = [self.value] else: value = self.value else: if isinstance(self.value, str): # if a passed argument is a string turn it into a 1 item list if self.font.size(self.value)[0] < self.rect.w - self.margin_x or not self.text_wrap: value = [self.value] else: # else enter extra line breaks if len(self.value) > 5: line = "" test_line = "" word = "" value = [] valx = self.value linelen = len(valx) for i in range(linelen): if valx[i] == "\n": test_line = "" + word word = "" value.append(line) line = "" + test_line elif valx[i] == " " or i == linelen - 1: test_line = test_line + word + valx[i] if self.font.size(test_line)[0] < self.rect.w - self.margin_x: line = "" + test_line word = "" else: test_line = "" + word + valx[i] word = "" value.append(line) line = "" + test_line else: word += valx[i] if len(test_line) > 0: value.append(test_line) else: value = [self.value] else: value = self.value lv = len(value) for i in range(lv): if sys.version_info < (3, 0): try: val = unicode(value[i], "utf-8") except UnicodeDecodeError: val = value[i] except TypeError: val = value[i] else: val = value[i] try: text = self.font.render("%s" % val, 1, self.font_colors[0]) except: pass if self.txt_align == 0: font_x = ((self.board.scale * self.grid_w - self.font.size(val)[0]) // 2) elif self.txt_align == 1: font_x = 5 elif self.txt_align == 2: font_x = self.board.scale * self.grid_w - self.font.size(val)[0] - 5 if lv == 1: font_y = ((self.board.scale * self.grid_h - self.font.size(val)[1]) // 2) elif lv == self.grid_h: # number of items is equal to grid height of an object - distribute lines equally in each grid square font_y = ((self.board.scale - self.font.size(val)[1]) // 2) + self.board.scale * i else: if self.txt_valign == 0: # lv - total line_h = self.font.size(value[0])[ 1] / self.board.mainloop.config.font_line_height_adjustment line_margin = 0 step = line_h + line_margin center = (self.board.scale * self.grid_h) // 2 start_at = center - ( step * lv - line_margin) // 2 - self.board.mainloop.config.font_start_at_adjustment font_y = start_at + step * i else: line_h = self.font.size(value[0])[ 1] / self.board.mainloop.config.font_line_height_adjustment line_margin = 0 step = line_h + line_margin start_at = 5 font_y = start_at + step * i try: self.image.blit(text, (font_x, font_y)) except: pass else: # multi-color if self.show_value: val = ex.unival(self.value) if self.txt_align == 0: font_x = ((self.board.scale * self.grid_w - self.font.size(val)[0]) // 2) elif self.txt_align == 1: font_x = 5 elif self.txt_align == 2: font_x = self.board.scale * self.grid_w - self.font.size(val)[0] - 5 font_y = ((self.board.scale * self.grid_h - self.font.size(val)[1]) // 2) for i in range(len(self.coltxt[0])): text = self.font.render("%s" % (self.coltxt[1][i]), 1, self.font_colors[self.coltxt[0][i]]) self.image.blit(text, (font_x + self.coltxt[2][i], font_y))
def render_textrect(self, string, font, rect, text_color, background_color, justification=0): """Returns a surface containing the passed text string, reformatted to fit within the given rect, word-wrapping as necessary. The text will be anti-aliased. Takes the following arguments: string - the text you wish to render. \n begins a new line. font - a Font object rect - a rectstyle giving the size of the surface requested. text_color - a three-byte tuple of the rgb value of the text color. ex (0, 0, 0) = BLACK background_color - a three-byte tuple of the rgb value of the surface. justification - 0 (default) left-justified 1 horizontally centered 2 right-justified Returns the following values: Success - a surface object with the text rendered onto it. Failure - raises a TextRectException if the text won't fit onto the surface. """ final_lines = [] string = ex.unival(string) requested_lines = string.splitlines() # Create a series of lines that will fit on the provided # rectangle. for requested_line in requested_lines: if font.size(requested_line)[0] > rect.width: words = requested_line.split(' ') # if any of our words are too long to fit, return. for word in words: if font.size(word)[0] >= rect.width: print("The word " + word + " is too long to fit in the rect passed.") # raise TextRectException, "The word " + word + " is too long to fit in the rect passed." # Start a new line accumulated_line = "" for word in words: test_line = accumulated_line + word + " " # Build the line while the words fit. if font.size(test_line)[0] < rect.width: accumulated_line = test_line else: final_lines.append(accumulated_line) accumulated_line = word + " " final_lines.append(accumulated_line) else: final_lines.append(requested_line) # Let's try to write the text out on the surface. surface = pygame.Surface(rect.size) surface.fill(background_color) accumulated_height = 0 for line in final_lines: if accumulated_height + font.size(line)[1] >= rect.height: print("Once word-wrapped, the text string was too tall to fit in the rect.") # raise TextRectException, "Once word-wrapped, the text string was too tall to fit in the rect." if line != "": tempsurface = font.render(line, 1, text_color) if justification == 0: surface.blit(tempsurface, (0, accumulated_height)) elif justification == 1: surface.blit(tempsurface, ((rect.width - tempsurface.get_width()) / 2, accumulated_height)) elif justification == 2: surface.blit(tempsurface, (rect.width - tempsurface.get_width(), accumulated_height)) else: print("Invalid justification argument: " + str(justification)) # raise TextRectException, "Invalid justification argument: " + str(justification) accumulated_height += font.size(line)[1] return surface
def __init__(self, board, grid_x=0, grid_y=0, grid_w=1, grid_h=1, txt=None, fg_img_src=None, bg_img_src=None, dc_img_src=None, bg_color=(0, 0, 0, 0), border_color=None, font_colors=None, bg_tint_color=None, fg_tint_color=None, dc_tint_color=None, txt_align=(0, 0), font_type=0, multi_color=False, alpha=True, immobilized=False, fg_as_hover=False, dc_as_hover=False, mode=0): pygame.sprite.Sprite.__init__(self) self.grid_x = grid_x self.grid_y = grid_y self.grid_w = grid_w self.grid_h = grid_h self.grid_last_x = grid_x self.grid_last_y = grid_y self.alpha = alpha self.board = board self.margin_x = self.board.scale * 0.2 self.immobilized = immobilized self.fg_as_hover = fg_as_hover self.dc_as_hover = dc_as_hover self.bg_color = bg_color self.border_color = border_color self.font_colors = font_colors # needs to be a list self.bg_tint_color = bg_tint_color self.fg_tint_color = fg_tint_color self.dc_tint_color = dc_tint_color self.color = bg_color # alias self.bg_img_src = bg_img_src self.fg_img_src = fg_img_src self.dc_img_src = dc_img_src self.use_blit_mask = False self.txt = txt self.txt_align = txt_align[0] # align: 0 - centered, 1 - left, 2 - right self.txt_valign = txt_align[1] # align: 0 - centered, 1 - top self.font_type = font_type self.multi_color = multi_color self.initcolor = self.bg_color self.allow_brightening = True self.decolorable = False self.mirror = False self.mode = mode self.speaker_val_update = False if txt is not None: self.speaker_val = txt self.value = ex.unival(txt) else: self.speaker_val = "" self.value = txt self.draggable = True self.animable = True self.show_value = True self.readable = False self.audible = False # use true to enable sounds on unit move self.outline_highlight = False self.update_me = True self.hidden = False self.hover = False self.check_display = None # None - none, True - correct, False - wrong self.checkable = False # scale font size: self.font = self.board.font_sizes[self.font_type] self.text_wrap = True self.img_src2 = None self.init_pow = 2 self.highlight = False self.keyable = True self.id = 0 self.manual_painting = None self.manual_painting_layer = 0 self.unit_id = len(self.board.ships) self.init_images()
def create_game_objects(self, level=1): self.board.draw_grid = False color = (234, 218, 225) self.color = color self.auto = False white = (255, 255, 255) img_top = 1 gv = self.mainloop.m.game_variant if gv == 0: category = "animals" self.imgs = ['cow', 'turkey', 'shrimp', 'wolf', 'panther', 'panda', 'magpie', 'clam', 'pony', 'mouse', 'pug', 'koala', 'frog', 'ladybug', 'gorilla', 'llama', 'vulture', 'hamster', 'bird', 'starfish', 'crow', 'parakeet', 'caterpillar', 'tiger', 'hummingbird', 'piranha', 'pig', 'scorpion', 'fox', 'leopard', 'iguana', 'dolphin', 'bat', 'chick', 'crab', 'hen', 'wasp', 'chameleon', 'whale', 'hedgehog', 'fawn', 'moose', 'bee', 'viper', 'shrike', 'donkey', 'guinea_pig', 'sloth', 'horse', 'penguin', 'otter', 'bear', 'zebra', 'ostrich', 'camel', 'antelope', 'lemur', 'pigeon', 'lama', 'mole', 'ray', 'ram', 'skunk', 'jellyfish', 'sheep', 'shark', 'kitten', 'deer', 'snail', 'flamingo', 'rabbit', 'oyster', 'beaver', 'sparrow', 'dove', 'eagle', 'beetle', 'hippopotamus', 'owl', 'cobra', 'salamander', 'goose', 'kangaroo', 'dragonfly', 'toad', 'pelican', 'squid', 'lion_cub', 'jaguar', 'duck', 'lizard', 'rhinoceros', 'hyena', 'ox', 'peacock', 'parrot', 'elk', 'alligator', 'ant', 'goat', 'baby_rabbit', 'lion', 'squirrel', 'opossum', 'chimp', 'doe', 'gopher', 'elephant', 'giraffe', 'spider', 'puppy', 'jay', 'seal', 'rooster', 'turtle', 'bull', 'cat', 'rat', 'slug', 'buffalo', 'blackbird', 'swan', 'lobster', 'dog', 'mosquito', 'snake', 'chicken', 'anteater'] elif gv == 1: category = "sport" self.imgs = ['judo', 'pool', 'ride', 'stretch', 'helmet', 'ice_skating', 'walk', 'run', 'swim', 'hop', 'hike', 'boxing', 'hockey', 'race', 'throw', 'skate', 'win', 'squat', 'ski', 'golf', 'whistle', 'torch', 'sailing', 'stand', 'tennis', 'jump', 'rowing', 'jog', 'rope'] elif gv == 2: category = "body" self.imgs = ['teeth', 'cheek', 'ankle', 'knee', 'toe', 'muscle', 'mouth', 'feet', 'hand', 'elbow', 'hair', 'eyelash', 'beard', 'belly_button', 'thumb', 'breast', 'nostril', 'nose', 'hip', 'arm', 'eyebrow', 'fist', 'neck', 'wrist', 'throat', 'eye', 'leg', 'spine', 'ear', 'finger', 'foot', 'braid', 'face', 'back', 'chin', 'bottom', 'thigh', 'belly'] elif gv == 3: category = "people" self.imgs = ['girl', 'male', 'son', 'mates', 'friends', 'baby', 'child', 'dad', 'mom', 'twin_boys', 'brothers', 'man', 'mother', 'grandfather', 'family', 'female', 'wife', 'husband', 'bride', 'madam', 'grandmother', 'couple', 'lad', 'twin_girls', 'tribe', 'boy', 'sisters', 'woman', 'lady'] elif gv == 4: category = "actions" self.imgs = ['lick', 'slam', 'beg', 'fell', 'scratch', 'touch', 'sniff', 'see', 'climb', 'dig', 'howl', 'sleep', 'explore', 'draw', 'hug', 'teach', 'nap', 'clay', 'catch', 'clap', 'cry', 'sing', 'meet', 'sell', 'peck', 'beat', 'kneel', 'find', 'dance', 'cough', 'cut', 'think', 'bark', 'speak', 'cheer', 'bake', 'write', 'punch', 'strum', 'study', 'plow', 'dream', 'post', 'dive', 'whisper', 'sob', 'shake', 'feed', 'crawl', 'camp', 'spill', 'clean', 'scream', 'tear', 'float', 'pull', 'ate', 'kiss', 'sit', 'hatch', 'blink', 'hear', 'smooch', 'play', 'wash', 'chat', 'drive', 'drink', 'fly', 'juggle', 'bit', 'sweep', 'look', 'knit', 'lift', 'fetch', 'read', 'croak', 'stare', 'eat'] elif gv == 5: category = "construction" self.imgs = ['lighthouse', 'door', 'circus', 'church', 'kennel', 'temple', 'smoke', 'chimney', 'brick', 'well', 'street', 'castle', 'store', 'staircase', 'school', 'farm', 'bridge', 'dam', 'pyramid', 'barn', 'mill', 'window', 'cabin', 'step', 'shop', 'shed', 'roof', 'steeple', 'garage', 'mosque', 'hospital', 'tent', 'house', 'wall', 'bank', 'shutter', 'hut'] elif gv == 6: category = "nature" self.imgs = ['land', 'cliff', 'hill', 'canyon', 'rock', 'sea', 'lake', 'coast', 'shore', 'mountain', 'pond', 'peak', 'lava', 'cave', 'dune', 'island', 'forest', 'desert', 'iceberg'] elif gv == 7: category = "jobs" self.imgs = ['clown', 'engineer', 'priest', 'vet', 'judge', 'chef', 'athlete', 'librarian', 'juggler', 'police', 'plumber', 'badge', 'queen', 'farmer', 'magic', 'knight', 'doctor', 'bricklayer', 'cleaner', 'teacher', 'hunter', 'soldier', 'musician', 'lawyer', 'fisherman', 'princess', 'fireman', 'nun', 'pirate', 'cowboy', 'electrician', 'nurse', 'king', 'president', 'office', 'carpenter', 'jockey', 'worker', 'mechanic', 'pilot', 'actor', 'cook', 'student', 'butcher', 'accountant', 'prince', 'pope', 'sailor', 'boxer', 'ballet', 'coach', 'astronaut', 'painter', 'anaesthesiologist', 'scientist'] elif gv == 8: category = "clothes_n_accessories" self.imgs = ['jewellery', 'sock', 'jacket', 'heel', 'smock', 'shorts', 'pocket', 'necklace', 'sweatshirt', 'uniform', 'raincoat', 'trousers', 'sunglasses', 'coat', 'pullover', 'shirt', 'sandals', 'suit', 'pyjamas', 'skirt', 'zip', 'shoes', 'jewel', 'tie', 'slippers', 'gloves', 'hat', 'sleeve', 'cap', 'swimming_suit', 'sneaker', 'vest', 'glasses', 'shoelace', 'patch', 'scarf', 'shoe', 'button', 'dress', 'sash', 'shoe_sole', 'robe', 'pants', 'kimono', 'overalls'] elif gv == 9: category = "fruit_n_veg" self.imgs = ['carrot', 'blackberries', 'celery', 'turnip', 'cacao', 'peach', 'melon', 'grapefruit', 'broccoli', 'grapes', 'spinach', 'fig', 'kernel', 'radish', 'tomato', 'kiwi', 'asparagus', 'olives', 'cucumbers', 'beans', 'strawberry', 'peppers', 'raspberry', 'apricot', 'potatoes', 'peas', 'cabbage', 'cherries', 'squash', 'blueberries', 'pear', 'orange', 'pumpkin', 'avocado', 'garlic', 'onion', 'apple', 'lime', 'cauliflower', 'mango', 'lettuce', 'lemon', 'aubergine', 'artichokes', 'plums', 'leek', 'bananas', 'papaya'] elif gv == 10: category = "transport" self.imgs = ['sail', 'taxi', 'car', 'bike', 'raft', 'pedal', 'bus', 'handlebar', 'boat', 'truck', 'sleigh', 'carpet', 'motorcycle', 'train', 'ship', 'van', 'canoe', 'rocket', 'mast', 'sledge', 'bicycle'] elif gv == 11: category = "food" self.imgs = ['candy', 'sausage', 'hamburger', 'steak', 'fudge', 'doughnut', 'coconut', 'rice', 'ice_cream', 'jelly', 'yoghurt', 'dessert', 'pretzel', 'peanut', 'jam', 'feast', 'cookie', 'bacon', 'spice', 'coffee', 'pie', 'lemonade', 'chocolate', 'water_bottle', 'lunch', 'ice', 'sugar', 'sauce', 'soup', 'juice', 'fries', 'cake', 'mashed_potatoes', 'tea', 'bun', 'cheese', 'beef', 'sandwich', 'slice', 'sprinkle', 'pizza', 'flour', 'gum', 'spaghetti', 'roast', 'stew', 'spread', 'meat', 'milk', 'meal', 'corn', 'bread', 'walnut', 'egg', 'hot_dog', 'ham'] self.words = self.d["a4a_%s" % category] self.level.games_per_lvl = 10 l = 100 max_word_len = 20 while l > max_word_len: self.w_index = random.randint(0, len(self.words) - 1) self.word = ex.unival(self.words[self.w_index]) if self.word[0] != "<": l = len(self.word) else: l = 100 if self.mainloop.lang.lang == "ru": self.wordsp = eval("self.dp['a4a_%s']" % category) self.wordp = ex.unival(self.wordsp[self.w_index]) else: self.wordp = self.word if self.mainloop.m.game_var2 == 0: img_src = "%s.jpg" % self.imgs[self.w_index] elif self.mainloop.m.game_var2 == 1: img_src = "speaker_icon.png" w_len = len(self.word) self.mainloop.redraw_needed = [True, True, True] if w_len % 2 == 0: even = True data = [w_len, 10] img_w_size = 4 else: even = False data = [w_len, 10] img_w_size = 5 img_h_size = 4 # stretch width to fit the screen size x_count = self.get_x_count(data[1], even=even) if x_count > data[0]: data[0] = x_count self.data = data self.board.set_animation_constraints(0, data[0], 0, data[1]) self.vis_buttons = [0, 1, 1, 1, 1, 0, 1, 0, 0] self.mainloop.info.hide_buttonsa(self.vis_buttons) self.layout.update_layout(data[0], data[1]) scale = self.layout.scale self.board.level_start(data[0], data[1], scale) self.unit_mouse_over = None self.units = [] self.board.board_bg.update_me = True self.board.board_bg.line_color = (20, 20, 20) base_len = data[0] - 2 img_left = (base_len - img_w_size) // 2 + 1 n_letters = self.level.lvl + 1 if self.level.lvl == 3: if n_letters >= w_len: n_letters = w_len - 1 if n_letters > w_len or self.level.lvl == 5: n_letters = w_len color_bg = (255, 255, 255) # frame around image caption if self.mainloop.scheme is not None: clx = self.mainloop.scheme.u_color if self.mainloop.scheme.dark: color_bg = (0, 0, 0) else: clx = white l = (data[0] - w_len) // 2 self.left_offset = l # frame around image - white/ clx self.board.add_door(img_left - 1, 1, img_w_size + 2, img_h_size + 3, classes.board.Door, "", white, "", font_size=2) self.board.units[-1].image.set_colorkey(None) self.board.units[-1].is_door = False self.board.add_door(1, img_w_size + 3, base_len, 3, classes.board.Door, "", clx, "", font_size=2) self.board.units[-1].image.set_colorkey(None) self.board.units[-1].is_door = False # dummy frame hiding bottom line of the image frame self.board.add_door(img_left - 1, img_w_size + img_top + 1, img_h_size + 2, 1, classes.board.Door, "", clx, "", font_size=2) self.board.units[-1].image.set_colorkey(None) self.board.units[-1].is_door = False if self.mainloop.m.game_var2 == 0: self.board.add_unit(img_left, img_top, img_w_size, img_h_size, classes.board.ImgCenteredShip, self.wordp, color_bg, os.path.join('art4apps', category, img_src)) elif self.mainloop.m.game_var2 == 1: self.mainloop.sb.toggle_espeak(True) self.board.add_unit(img_left, img_top, img_w_size, img_h_size, classes.board.ImgCenteredShip, self.wordp, color_bg, img_src, alpha=True) self.board.ships[-1].immobilize() self.board.ships[-1].highlight = False self.board.ships[-1].outline_highlight = False self.board.ships[-1].animable = False self.board.ships[-1].outline = False self.board.units[-1].is_door = False choice_list = self.word[:] index_list = [x for x in range(w_len)] lowered_ind = [0 for x in range(w_len)] lowered = [] for i in range(n_letters): # picking letters to lower index = random.randrange(0, len(index_list)) lowered.append(choice_list[index_list[index]]) lowered_ind[index_list[index]] = 1 del (index_list[index]) random.shuffle(lowered) # set images and colors if self.mainloop.scheme is None: dc_img_src = os.path.join('unit_bg', "universal_sq_dc.png") else: dc_img_src = None h = random.randint(0, 255) bg_img_src = os.path.join('unit_bg', "universal_sq_bg.png") bg_door_img_src = os.path.join('unit_bg', "universal_sq_door.png") door_bg_tint = ex.hsv_to_rgb(h, self.mainloop.cl.door_bg_tint_s, self.mainloop.cl.door_bg_tint_v) number_color = ex.hsv_to_rgb(h, self.mainloop.cl.bg_color_s, self.mainloop.cl.bg_color_v) font_color = [ex.hsv_to_rgb(h, self.mainloop.cl.font_color_s, self.mainloop.cl.font_color_v), ] fg_number_color = ex.hsv_to_rgb(h, self.mainloop.cl.fg_hover_s, self.mainloop.cl.fg_hover_v) # create table to store 'binary' solution self.solution_grid = [0 for x in range(data[0])] x = l y = img_h_size + img_top + 1 self.sol_grid_y = y x2 = (data[0] - len(lowered)) // 2 y2 = img_h_size + img_top + 3 j = 0 for i in range(len(self.word)): picked = False if lowered_ind[i] == 1: picked = True self.solution_grid[x] = 1 # change y if picked: caption = lowered[j] self.board.add_universal_unit(grid_x=x2 + j, grid_y=y2, grid_w=1, grid_h=1, txt=caption, fg_img_src=bg_img_src, bg_img_src=bg_img_src, dc_img_src=dc_img_src, bg_color=(0, 0, 0, 0), border_color=None, font_color=font_color, bg_tint_color=number_color, fg_tint_color=fg_number_color, txt_align=(0, 0), font_type=0, multi_color=False, alpha=True, immobilized=False, fg_as_hover=True) self.units.append(self.board.ships[-1]) # empty slot self.board.add_universal_unit(grid_x=x, grid_y=y, grid_w=1, grid_h=1, txt=None, fg_img_src=None, bg_img_src=bg_door_img_src, dc_img_src=None, bg_color=(0, 0, 0, 0), border_color=None, font_color=None, bg_tint_color=door_bg_tint, fg_tint_color=None, txt_align=(0, 0), font_type=10, multi_color=False, alpha=True, immobilized=True, mode=2) self.board.ships[-1].readable = False self.board.ships[-1].checkable = True self.board.ships[-1].init_check_images() j += 1 else: caption = self.word[i] self.board.add_universal_unit(grid_x=x, grid_y=y, grid_w=1, grid_h=1, txt=caption, fg_img_src=None, bg_img_src=bg_img_src, dc_img_src=dc_img_src, bg_color=(0, 0, 0, 0), border_color=None, font_color=font_color, bg_tint_color=number_color, fg_tint_color=fg_number_color, txt_align=(0, 0), font_type=0, multi_color=False, alpha=True, immobilized=True, fg_as_hover=False) self.board.ships[-1].readable = False self.board.ships[-1].checkable = True self.board.ships[-1].init_check_images() x += 1 for i in range(3, 3 + n_letters): self.board.all_sprites_list.move_to_front(self.board.units[i]) if self.mainloop.m.game_var2 == 1: self.mainloop.speaker.say(self.wordp)
def create_game_objects(self, level=1): self.board.draw_grid = False self.vis_buttons = [1, 1, 1, 1, 1, 1, 1, 1, 0] self.mainloop.info.hide_buttonsa(self.vis_buttons) s = 70 v = 230 h = random.randrange(0, 255, 5) color0 = ex.hsv_to_rgb(h, 40, 230) font_color = ex.hsv_to_rgb(h, 255, 140) # data = [x_count, y_count, letter_count, top_limit, ordered] if self.level.lvl == 1: data = [11, 6, 3, True, 1] elif self.level.lvl == 2: data = [11, 6, 3, False, 1] elif self.level.lvl == 3: data = [11, 6, 5, True, 1] elif self.level.lvl == 4: data = [11, 6, 5, False, 1] elif self.level.lvl == 5: data = [11, 6, 7, True, 1] elif self.level.lvl == 6: data = [11, 6, 7, False, 1] elif self.level.lvl == 7: data = [11, 6, 9, True, 1] elif self.level.lvl == 8: data = [11, 6, 9, False, 1] elif self.level.lvl == 9: data = [11, 6, 11, True, 1] elif self.level.lvl == 10: data = [11, 6, 11, False, 1] self.chapters = [1, 3, 5, 7, 9, 10] self.points = (data[2] + 2) // 3 + self.level.lvl // 4 self.data = data self.board.set_animation_constraints(0, data[0], 0, data[1] - 1) self.layout.update_layout(data[0], data[1]) self.board.level_start(data[0], data[1], self.layout.scale) if self.mainloop.m.game_variant == 0: if self.lang.ltr_text: self.alphabet = self.lang.alphabet_lc else: ts = "".join(self.lang.alphabet_lc) ts = ex.unival(ts) self.alphabet = ts[::-1] elif self.mainloop.m.game_variant == 1: self.alphabet = self.lang.alphabet_uc self.alph_len = len(self.alphabet) self.num_list = [] self.indexes = [] self.choice_indexes = [x for x in range(self.alph_len)] if data[3] == True: choice_list = [x for x in range(self.alph_len - data[2])] index = random.randrange(0, len(choice_list)) n = 0 for i in range(data[2]): self.num_list.append(choice_list[index] + n) self.indexes.append(index + n) n += 1 else: choice_list = [x for x in range(self.alph_len)] for i in range(data[2]): index = random.randrange(0, len(choice_list)) self.num_list.append(choice_list[index]) self.indexes.append(choice_list[index]) del (choice_list[index]) self.indexes.sort() shuffled = self.num_list[:] random.shuffle(shuffled) color = (255, 255, 255) # create table to store 'binary' solution self.solution_grid = [0 for x in range(data[0])] # find position of first door square x = (data[0] - data[2]) // 2 # add objects to the board for i in range(data[2]): self.board.add_door(x + i, 0, 1, 1, classes.board.Door, "", color, "") self.board.units[i].door_outline = True y = random.randrange(1, 5) number_color = ex.hsv_to_rgb(h, s, v) # highlight 1 caption = self.alphabet[shuffled[i]] self.board.add_unit(x + i, y, 1, 1, classes.board.Letter, caption, number_color, "", data[4]) self.board.ships[-1].font_color = font_color # self.board.ships[i].highlight = False self.board.ships[i].outline_highlight = True self.solution_grid[x + i] = 1 for each in self.board.units: self.board.all_sprites_list.move_to_front(each) instruction = self.d["Re-arrange alphabetical"] self.board.add_unit(0, 5, 11, 1, classes.board.Letter, instruction, color0, "", 7) self.board.ships[-1].immobilize() self.board.ships[-1].font_color = font_color self.board.ships[-1].speaker_val = self.dp["Re-arrange alphabetical"] self.board.ships[-1].speaker_val_update = False self.outline_all(0, 1)
def get_lang_attr(self): filename = os.path.join(self.locale_dir, self.lang, "LC_MESSAGES", "eduactiv8.mo") # filename = "locale/%s/LC_MESSAGES/eduactiv8.mo" % self.lang self.trans[self.lang] = gettext.GNUTranslations(open(filename, "rb")) try: # print("Opening message file %s for locale %s" % (filename, self.lang) ) self.trans[self.lang] = gettext.GNUTranslations(open(filename, "rb")) except IOError: print("Locale not found. Using default messages") self.trans[self.lang] = gettext.NullTranslations() self.trans[self.lang].install() import i18n.custom.default self.oi18n = i18n.custom.default.I18n() self.kbrd = None self.ltr_text = True self.ltr_numbers = True self.ltr_math = True self.has_uc = True self.has_cursive = True font_variant = 0 self.ico_suffix = "" self.lang_id = 0 # used to identify the language in database - do not reorganize numbers when adding new language if self.lang == 'en_US': import i18n.custom.en_us import i18n.custom.word_lists.en_us_di import i18n.custom.kbrd.en_us import i18n.custom.kbrd.en_course # self.voice = ["-s 170","-a 100","-p 80","-ven-us+m1"] self.voice = ["-ven-us+m1"] self.di = i18n.custom.word_lists.en_us_di.di self.lang_file = i18n.custom.en_us self.kbrd = i18n.custom.kbrd.en_us self.kbrd_course_mod = i18n.custom.kbrd.en_course self.lang_id = 1 elif self.lang == 'pl': import i18n.custom.pl import i18n.custom.word_lists.pl_di import i18n.custom.kbrd.pl import i18n.custom.kbrd.pl_course # self.voice = ["-s 160","-a 100","-p 80","-vpl+m1"] #"-g 5", self.voice = ["-vpl+m1"] self.di = i18n.custom.word_lists.pl_di.di self.lang_file = i18n.custom.pl self.kbrd = i18n.custom.kbrd.pl self.kbrd_course_mod = i18n.custom.kbrd.pl_course self.lang_id = 3 elif self.lang == 'sr': import i18n.custom.sr import i18n.custom.word_lists.sr_di # self.voice = ["-s 160","-a 100","-p 80","-vpl+m1"] #"-g 5", self.voice = ["-vsr+m1"] self.di = i18n.custom.word_lists.sr_di.di self.lang_file = i18n.custom.sr self.lang_id = 19 self.ico_suffix = "ru" self.has_cursive = False self.time2str_short = self.lang_file.time2str_short elif self.lang == 'ca': import i18n.custom.ca import i18n.custom.word_lists.ca_di self.voice = ["-vca+m1"] self.di = i18n.custom.word_lists.ca_di.di self.lang_file = i18n.custom.ca self.lang_id = 5 elif self.lang == 'es_ES': import i18n.custom.es import i18n.custom.word_lists.es_di self.voice = ["-ves+m1"] self.di = i18n.custom.word_lists.es_di.di self.lang_file = i18n.custom.es self.lang_id = 8 elif self.lang == 'pt_PT': import i18n.custom.pt import i18n.custom.word_lists.pt_di self.voice = ["-vpt-pt+m1"] self.di = i18n.custom.word_lists.pt_di.di self.lang_file = i18n.custom.pt self.lang_id = 9 elif self.lang == 'fr': import i18n.custom.fr import i18n.custom.word_lists.fr_di import i18n.custom.kbrd.fr import i18n.custom.kbrd.fr_course self.voice = ["-vfr+m1"] self.di = i18n.custom.word_lists.fr_di.di self.lang_file = i18n.custom.fr self.kbrd = i18n.custom.kbrd.fr self.kbrd_course_mod = i18n.custom.kbrd.fr_course self.lang_id = 10 elif self.lang == 'it': import i18n.custom.it import i18n.custom.word_lists.it_di self.voice = ["-vit+m1"] self.di = i18n.custom.word_lists.it_di.di self.lang_file = i18n.custom.it self.lang_id = 11 elif self.lang == 'de': import i18n.custom.de import i18n.custom.word_lists.de_di import i18n.custom.kbrd.de import i18n.custom.kbrd.de_course self.voice = ["-vde+m1"] self.di = i18n.custom.word_lists.de_di.di self.lang_file = i18n.custom.de self.kbrd = i18n.custom.kbrd.de self.kbrd_course_mod = i18n.custom.kbrd.de_course self.lang_id = 12 elif self.lang == 'ru': import i18n.custom.ru import i18n.custom.word_lists.ru_di import i18n.custom.kbrd.ru import i18n.custom.kbrd.ru_course # self.voice = ["-s 130","-a 100","-p 80","-vru+m1"] # self.voice = ["-vru+m1"] s 150 -vru self.voice = ["-s 150", "-vru"] self.di = i18n.custom.word_lists.ru_di.di self.lang_file = i18n.custom.ru self.kbrd = i18n.custom.kbrd.ru self.kbrd_course_mod = i18n.custom.kbrd.ru_course self.time2spk = self.lang_file.time2spk self.time2officialstr = self.lang_file.time2officialstr self.time2officialspk = self.lang_file.time2officialspk self.ico_suffix = "ru" self.lang_id = 13 elif self.lang == 'uk': import i18n.custom.uk import i18n.custom.word_lists.uk_di import i18n.custom.kbrd.uk import i18n.custom.kbrd.uk_course self.voice = None self.di = i18n.custom.word_lists.uk_di.di self.lang_file = i18n.custom.uk self.kbrd = i18n.custom.kbrd.uk self.kbrd_course_mod = i18n.custom.kbrd.uk_course self.ico_suffix = "ru" self.lang_id = 14 elif self.lang == 'fi': import i18n.custom.fi import i18n.custom.word_lists.fi_di self.voice = ["-vfi+m1"] self.di = i18n.custom.word_lists.fi_di.di self.lang_file = i18n.custom.fi self.lang_id = 15 elif self.lang == 'el': # Greek import i18n.custom.el import i18n.custom.word_lists.el_di import i18n.custom.kbrd.el import i18n.custom.kbrd.el_course self.voice = ["-vel+m1"] self.di = i18n.custom.word_lists.el_di.di self.lang_file = i18n.custom.el self.kbrd = i18n.custom.kbrd.el self.kbrd_course_mod = i18n.custom.kbrd.el_course self.ico_suffix = "el" self.lang_id = 16 elif self.lang == 'he': # Hebrew import i18n.custom.he import i18n.custom.word_lists.he_di self.voice = ["-ven+m1"] # None self.di = i18n.custom.word_lists.he_di.di self.lang_file = i18n.custom.he self.time2spk = self.lang_file.time2spk self.ltr_text = False self.has_uc = False self.has_cursive = False self.alpha = i18n.custom.he.alpha self.n2spk = self.lang_file.n2spk # font_variant = 1 self.ico_suffix = "he" self.lang_id = 17 elif self.lang == 'lkt': import i18n.custom.lkt import i18n.custom.word_lists.lkt_di self.voice = None self.has_cursive = False self.di = i18n.custom.word_lists.lkt_di.di self.lang_file = i18n.custom.lkt # self.alpha = i18n.custom.cn.alpha # self.n2spk = self.lang_file.n2spk self.ico_suffix = "" self.lang_id = 20 elif self.lang == 'te_ST': import i18n.custom.te_st import i18n.custom.word_lists.te_st_di self.voice = ["-ven+m1"] self.di = i18n.custom.word_lists.te_st_di.di self.lang_file = i18n.custom.te_st self.lang_id = 1 else: # self.lang == 'en_GB': import i18n.custom.en_gb import i18n.custom.word_lists.en_gb_di import i18n.custom.kbrd.en_gb import i18n.custom.kbrd.en_course self.voice = ["-ven+m1"] self.di = i18n.custom.word_lists.en_gb_di.di self.lang_file = i18n.custom.en_gb self.kbrd = i18n.custom.kbrd.en_gb self.kbrd_course_mod = i18n.custom.kbrd.en_course self.lang_id = 1 # languages that have not been translated are temporarily switched off """ elif self.lang == 'sk': import i18n.custom.sk import i18n.custom.word_lists.sk_di # self.voice = ["-s 160","-a 100","-p 80","-vpl+m1"] #"-g 5", self.voice = ["-vsk+m1"] self.di = i18n.custom.word_lists.sk_di.di self.lang_file = i18n.custom.sk self.lang_id = 4 elif self.lang == 'da': import i18n.custom.da import i18n.custom.word_lists.da_di self.voice = ["-vda+m1"] self.di = i18n.custom.word_lists.da_di.di self.lang_file = i18n.custom.da self.lang_id = 6 elif self.lang == 'nl': import i18n.custom.nl import i18n.custom.word_lists.nl_di self.voice = ["-vnl+m1"] self.di = i18n.custom.word_lists.nl_di.di self.lang_file = i18n.custom.nl self.lang_id = 7 elif self.lang == 'ar': # Arabic import i18n.custom.ar import i18n.custom.word_lists.ar_di self.voice = None self.di = i18n.custom.word_lists.ar_di.di self.lang_file = i18n.custom.ar self.ltr_text = False self.has_uc = False self.has_cursive = False self.alpha = i18n.custom.ar.alpha self.n2spk = self.lang_file.n2spk self.ico_suffix = "ar" self.lang_id = 2 elif self.lang == 'cn': import i18n.custom.cn import i18n.custom.word_lists.cn_di self.voice = None self.di = i18n.custom.word_lists.cn_di.di self.lang_file = i18n.custom.cn # self.alpha = i18n.custom.cn.alpha # self.n2spk = self.lang_file.n2spk self.ico_suffix = "" self.lang_id = 18 """ if self.lang in ["ar", "he"]: self.config.font_multiplier = 1.1 self.config.font_line_height_adjustment = 1.5 self.config.font_start_at_adjustment = 5 else: self.config.font_multiplier = 1 self.config.font_line_height_adjustment = 1 self.config.font_start_at_adjustment = 0 if self.kbrd is None: # self.lang not in ["en_gb","en_us","pl","ru","el","uk","fr"]: import i18n.custom.kbrd.en_gb import i18n.custom.kbrd.en_course self.kbrd = i18n.custom.kbrd.en_gb self.kbrd_course_mod = i18n.custom.kbrd.en_course self.d = dict() self.b = dict() self.dp = dict() self.kbrd_course = self.kbrd_course_mod.course self.d.update(self.oi18n.d) self.d.update(self.lang_file.d) self.b.update(self.oi18n.b) self.numbers = self.lang_file.numbers self.numbers2090 = self.lang_file.numbers2090 self.n2txt = self.lang_file.n2txt self.time2str = self.lang_file.time2str if self.lang in ["en_GB", "en_US", "pl"]: self.fract2str = self.lang_file.fract2str self.solid_names = self.oi18n.solid_names self.shape_names = self.oi18n.shape_names self.letter_names = self.lang_file.letter_names self.config.set_font_family(font_variant) if not self.ltr_text: for each_d in [self.d, self.b]: for key in each_d.keys(): if isinstance(each_d[key], list): for index in range(len(each_d[key])): if sys.version_info < (3, 0): if isinstance(each_d[key][index], basestring): each_d[key][index] = reverse(each_d[key][index], self.alpha, self.lang) else: if isinstance(each_d[key][index], str): each_d[key][index] = reverse(each_d[key][index], self.alpha, self.lang) else: each_d[key] = reverse(each_d[key], self.alpha, self.lang) for each in [self.solid_names, self.shape_names]: for index in range(len(each)): if sys.version_info < (3, 0): if isinstance(each[index], basestring): each[index] = reverse(each[index], self.alpha, self.lang) else: if isinstance(each[index], str): each[index] = reverse(each[index], self.alpha, self.lang) self.dp.update(self.d) # if self.lang == 'ru' or self.lang == 'he': self.dp.update(self.lang_file.dp) if self.lang == "he": s = unival(self.d['abc_flashcards_word_sequence'][0]) if len(s) > 0: if s[0] == unival("א"): self.d['abc_flashcards_word_sequence'] = self.d['abc_flashcards_word_sequencer'] self.alphabet_lc = self.lang_file.alphabet_lc self.alphabet_uc = self.lang_file.alphabet_uc self.accents_lc = self.lang_file.accents_lc self.accents_uc = self.lang_file.accents_uc
def create_game_objects(self, level=1): self.board.draw_grid = False self.vis_buttons = [0, 1, 1, 1, 1, 0, 1, 1, 1] self.mainloop.info.hide_buttonsa(self.vis_buttons) s = 70 v = 230 h = random.randrange(0, 255, 5) color0 = ex.hsv_to_rgb(h, 40, 230) font_color = ex.hsv_to_rgb(h, 255, 140) data = [11, 3] data.extend( self.mainloop.xml_conn.get_level_data( self.mainloop.m.game_dbid, self.mainloop.config.user_age_group, self.level.lvl)) self.chapters = self.mainloop.xml_conn.get_chapters( self.mainloop.m.game_dbid, self.mainloop.config.user_age_group) self.data = data self.board.set_animation_constraints(0, data[0], 0, data[1]) self.layout.update_layout(data[0], data[1]) self.board.level_start(data[0], data[1], self.layout.scale) if self.mainloop.m.game_variant == 0: if self.lang.ltr_text: self.alphabet = self.lang.alphabet_lc else: ts = "".join(self.lang.alphabet_lc) ts = ex.unival(ts) self.alphabet = ts[::-1] elif self.mainloop.m.game_variant == 1: self.alphabet = self.lang.alphabet_uc self.alph_len = len(self.alphabet) self.num_list = [] self.indexes = [] self.choice_indexes = [x for x in range(self.alph_len)] self.positionsd = {} #for i in range(self.alph_len - data[2]): # self.positions.append((i, 0)) if data[3] == True: choice_list = [x for x in range(self.alph_len - data[2])] index = random.randrange(0, len(choice_list)) for i in range(data[2]): self.num_list.append(choice_list[index] + i) self.indexes.append(index + i) self.positionsd[index + i] = i else: choice_list = [x for x in range(self.alph_len)] for i in range(data[2]): index = random.randrange(0, len(choice_list)) self.num_list.append(choice_list[index]) self.indexes.append(choice_list[index]) del (choice_list[index]) self.indexes.sort() shuffled = self.num_list[:] random.shuffle(shuffled) color = (255, 255, 255) # create table to store 'binary' solution self.solution_grid = [0 for x in range(data[0])] # find position of first door square x = (data[0] - data[2]) // 2 self.positions = [] for i in range(data[2]): self.positionsd[self.indexes[i]] = i self.positions.append([x + i, 0]) # add objects to the board for i in range(data[2]): self.board.add_door(x + i, 0, 1, 1, classes.board.Door, "", color, "") self.board.units[i].door_outline = True y = random.randrange(1, data[1]) number_color = ex.hsv_to_rgb(h, s, v) # highlight 1 caption = self.alphabet[shuffled[i]] self.board.add_unit(x + i, y, 1, 1, classes.board.Letter, caption, number_color, "", data[4]) self.board.ships[-1].font_color = font_color # self.board.ships[i].highlight = False self.board.ships[i].outline_highlight = True self.board.ships[i].checkable = True self.board.ships[i].init_check_images() self.board.ships[i].home_location = [ x + self.positionsd[shuffled[i]], 0 ] self.solution_grid[x + i] = 1 for each in self.board.units: self.board.all_sprites_list.move_to_front(each) """ instruction = self.d["Re-arrange alphabetical"] self.board.add_unit(0, 5, 11, 1, classes.board.Letter, instruction, color0, "", 7) self.board.ships[-1].immobilize() self.board.ships[-1].font_color = font_color self.board.ships[-1].speaker_val = self.dp["Re-arrange alphabetical"] self.board.ships[-1].speaker_val_update = False """ self.outline_all(0, 1)