def __init__(self, args, server_address): self.server, self.port = server_address.server, server_address.port self.rcpt = args.rcpt self.path = args.path self.credentials = Credentials(args) self.security = args.security.lower() self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.socket.settimeout(args.timeout) if self.security == "ssl": try: self.socket = ssl.wrap_socket(self.socket) self.connect() except (ssl.SSLError, socket.timeout): self.crush("Couldn't start SSL connection") self.ehlo() elif self.security == "empty": self.connect() self.ehlo() elif self.security == "tls": self.connect() self.start_tls() if not self.credentials.is_empty(): self.auth() self.letter = Letter(args, self.credentials.login) self.send()
def create_word(self, text): """ Create a word by creating a list of Letter objects :param str text: The word as a string """ for ch in text: self.char_list.append(Letter(ch)) self.width += self.char_list[-1].width
def levelUp(self): if self.lvlUp: if self.letterNum < 7: self.letterCounter += 1 if self.letterCounter == 5: self.letterIndex += 1 self.letterX -= 40 self.letters.append( Letter(self.letterX, 100, self.letterLst[self.letterIndex])) self.letterNum += 1 self.letterCounter = 0 else: self.letterTimer += 1 if self.letterTimer == 40: self.lvlUp = False self.letters = [] self.letterNum = 0 self.letterIndex = -1 self.letterTimer = 0 self.letterX = 0 for l in self.letters: l.move()
def do_comparisons(file_variable, bst): """ ------------------------------------------------------- Retrieves every letter in file_variable from bst. Generates comparisons in bst objects. ------------------------------------------------------- Preconditions: file_variable - the already open file containing data to evaluate (file) bst - the binary search tree containing 26 Letter objects to retrieve data from (BST) Postconditions: Each Letter object in bst contains the number of comparisons found by searching for that Letter object in file_variable. ------------------------------------------------------- """ file_variable.seek(0) line = file_variable.readline() while line != "": for letter in line: if letter != " " and letter.isalpha(): letter_obj = Letter(letter.upper()) value = bst.retrieve(letter_obj) line = file_variable.readline() return
def letter_generator(stats, az_settings, screen, letters): if stats.lives_left > 0: new_letter = Letter(az_settings, screen) letters.add(new_letter) else: letters.empty() stats.game_active = False pygame.mouse.set_visible(True)
def test_send_message(app): app.session.login(username="******", password="******") app.mail.create_letter( Letter( address="*****@*****.**", subject="Test letter", text="Hello!\nThis is testing " "letter for checking e-mail sending via Python.\nBest regards!")) assert app.mail.get_assertion_text( ) == "Ваше письмо отправлено. Перейти во Входящие"
def parsePredicate(pred, automaton_type=""): """ Parses given predicate string :param pred: predicate string :param automaton_type: compatibility with transducer parser :return: predicate object """ result = Letter() result.symbol = pred return result
def __init__(self): self.win_size = (800, 500) self.fps = 60 self.window = pygame.display.set_mode(self.win_size) self.bg_img = pygame.image.load("imgs/grassland.jpg") self.bg_img = pygame.transform.scale(self.bg_img, self.win_size) self.mistakes = 0 # other classes self.gallows = Gallows() self.letters = [Letter(value) for value in alphabet] # words to guess self.word = "PYTHON IS COOL" self.password = "" for letter in self.word: if letter.isalpha(): self.password += "-" elif letter.isspace(): self.password += " " self.font = pygame.font.Font('freesansbold.ttf', 40) self.font_word = self.font.render(self.password, True, (0, 0, 0))
def __init__(self, s): self.string = s self.bonds = [] self.objects = [] self.letters = [] self.length = len(s) self.intraStringUnhappiness = 0.0 if not self.length: return position = 0 from workspace import workspace for c in self.string.upper(): value = ord(c) - ord('A') letter = Letter(self, position + 1, self.length) letter.workspaceString = self letter.addDescription(slipnet.objectCategory, slipnet.letter) letter.addDescription(slipnet.letterCategory, slipnet.letters[value]) letter.describe(position + 1, self.length) workspace.buildDescriptions(letter) self.letters += [letter] position += 1
def __init__(self): self.letters = [Letter(c) for c in string.ascii_lowercase]
# 録画の設定 file_name = "scene3_variation_grows_1_toKanji" fourcc = cv2.VideoWriter_fourcc( *'mp4v') # SEE: https://gist.github.com/takuma7/44f9ecb028ff00e2132e out = cv2.VideoWriter( 'outputs/2018summer_art_project/{}.mp4'.format(file_name), fourcc, 30, (700, 400)) # 初期化 # bit_map_label_and_img = game_of_life_patterns.NUM_ALPH # bit_map_label_and_img = game_of_life_patterns.NUM_ALPH_KANA bit_map_label_and_img = game_of_life_patterns.NUM_ALPH_KANA_KANJI l1 = Letter(bit_map_label_and_img) l2 = Letter(bit_map_label_and_img) letter_height = l1.current_letter.shape[0] letter_width = l1.current_letter.shape[1] state = np.zeros((HEIGHT, WIDTH), dtype=np.int8) next_state = np.empty((HEIGHT, WIDTH), dtype=np.int8) state[5:5 + letter_height, 5:5 + letter_width] = l1.next() state[5:5 + letter_height, 35:35 + letter_width] = l2.next() visualizer.update(1 - state) # 1を黒, 0を白で表示する # visualizer.update(state) time.sleep(1)
def typing(): global time_count, time_text, game_round, player1, player2, endGame, player, gameOver loop = True startOver = True screen = P.display.set_mode((G.D_WIDTH,G.D_HEIGHT),0,32) gm = GameMenu(screen,[],G.BLACK) screenWord = Word([]) words = G.make_word_list() #change to certain list based on difficulty level wordList = map(lambda listword: Word.create_word(listword),words) nextWord = 0 currentWordToType = wordList[nextWord] currentWordLabel = currentWordToType.get_label() currentLetterCount = 0 letterWidth = 0 P.key.set_repeat(500,50) #so people can hold a key down BG_COLOR = G.BLACK LETTER_COLOR = G.DEF_LETTER_COLOR screenCenter = G.SCREEN_CENTER topCenter = G.TOP_CENTER topLeft = (topCenter[0]-200,topCenter[1]-50) topRight = (topCenter[0]+200,topCenter[1]-50) centerX = screenCenter[0] centerY = screenCenter[1] def draw_list(thingsToDraw): for (label,(x,y)) in thingsToDraw: G.draw(gm,label,(x,y)) thingsToDraw = [] lastLetter = None xDifferentials = [] P.time.set_timer(P.USEREVENT, 1000) # timer set for each second set_time() gm.screen.fill(BG_COLOR) # set initial background thingsToDraw.append((currentWordLabel,topCenter)) thingsToDraw.append((Word.create_word(time_text).get_label(),topRight)) thingsToDraw.append((Word.create_word('Health: {}'.format(player.health)).get_label(),topLeft)) thingsToDraw.append((Word.create_word(player.label).get_label(),(topCenter[0]-200,topCenter[1]-80))) draw_list(thingsToDraw) P.display.flip() while loop: currentWordToType = wordList[nextWord] currentWordLabel = currentWordToType.get_label() thingsToDraw[0] = (currentWordLabel,topCenter) for e in P.event.get(): gm.screen.fill(BG_COLOR) if e.type == P.QUIT: # exit the loop if input is quit loop = False startOver = False endGame = True break if e.type == P.USEREVENT: time_count -= 1 if time_count >= 10: time_text = "0:{}".format(time_count) elif time_count >= 0: time_text = "0:0{}".format(time_count) else: gm.screen.fill(BG_COLOR) thingsToDraw2 = [] if (game_round % 2 == 0): thingsToDraw2.append((Word.create_word('Round {} Over!'.format(game_round/2)).get_label(),screenCenter)) else: thingsToDraw2.append((Word.create_word("Next Player's Turn!").get_label(),screenCenter)) thingsToDraw2.append((Word.create_word('Press Enter To Continue').get_label(),(centerX,centerY-100))) thingsToDraw2.append((Word.create_word('You typed {} words'.format(player.index)).get_label(),(centerX,centerY+150))) if (game_round % 2 == 0): diff1 = player1.index - player2.index diff2 = player2.index - player1.index if (diff1 > diff2): player2.modifyHealth(diff2) thingsToDraw2.append((Word.create_word('Player 1 won the round').get_label(),(centerX,centerY+30))) if (diff2 > diff1): player1.modifyHealth(diff1) thingsToDraw2.append((Word.create_word('Player 2 won the round').get_label(),(centerX,centerY+30))) player1.resetIndex() player2.resetIndex() thingsToDraw2.append((Word.create_word('Your Health is {}'.format(player.health)).get_label(),(centerX,centerY+100))) game_round += 1 if (game_round % 2 == 0): player = player2 else: player = player1 draw_list(thingsToDraw2) P.display.update() loop = False sleep(0.5) break timeWord = Word.create_word(time_text) thingsToDraw[1] = (timeWord.get_label(),topRight) draw_list(thingsToDraw) P.display.update() if e.type == P.KEYDOWN: # on keypress if e.key in G.SPECIAL_KEYS: # for special key presses if e.key == P.K_ESCAPE: # exit loop if escape loop = False startOver = False endGame = True break if e.key == P.K_RETURN: # clear word typed so far if enter is pressed screenWord.clear() #label = screenWord.get_label() currentLetterCount = 0 xDifferentials = [] thingsToDraw = thingsToDraw[0:4] draw_list(thingsToDraw) P.display.update() if e.key == P.K_BACKSPACE: # remove letter from the word being typed if backspace #if currentLetterCount <= 0: # currentLetter = 0 thingsToDraw[2] = (Word.create_word('Health: {}'.format(player.health)).get_label(),topLeft) screenWord.remove_letter() #label = screenWord.get_label() offsetCenter = centerX + ((letterWidth * (screenWord.length - 1)) / 2) if xDifferentials != []: xDifferentials = xDifferentials[:-1] if xDifferentials != []: letterWidth = xDifferentials[len(xDifferentials)-1] else: letterWidth = 0 xDifferentials = map(lambda x: x - letterWidth, xDifferentials) thingsToDraw = thingsToDraw[0:4] for pos,letter in enumerate(screenWord.get_letters()): thingsToDraw.append((letter.get_label(),(offsetCenter-xDifferentials[pos],centerY-25))) draw_list(thingsToDraw) P.display.update() else: thingsToDraw = thingsToDraw[0:4] for pos,letter in enumerate(screenWord.get_letters()): thingsToDraw.append((letter.get_label(),(screenCenter-xDifferentials[pos],centerY-25))) draw_list(thingsToDraw) P.display.update() currentLetterCount -= 1 if currentLetterCount < 0: currentLetterCount = 0 else: pass elif e.key in range(0,255): if currentLetterCount == len(currentWordToType.get_text()): screenWord.clear() xDifferentials = [] nextWord += 1 currentLetterCount = 0 letterWidth = 0 thingsToDraw = thingsToDraw[0:4] draw_list(thingsToDraw) P.display.update() else: keyName = P.key.name(e.key) if P.key.get_mods() in (1,2) or P.key.get_mods() in (4097,4098): #checks for left shift and right shift keyName = keyName.upper() if currentLetterCount < currentWordToType.length and \ keyName == wordList[nextWord].get_text()[currentLetterCount]: LETTER_COLOR = G.GREEN thingsToDraw[2] = (Word.create_word('Health: {}'.format(player.health)).get_label(),topLeft) else: LETTER_COLOR = G.RED player.modifyHealth(-5) thingsToDraw[2] = (Word.create_word('Health: {}'.format(player.health)).get_label(),topLeft) if (player.health == 0): gm.screen.fill(BG_COLOR) thingsToDraw3 = [] thingsToDraw3.append((Word.create_word('Game Over!').get_label(),screenCenter)) thingsToDraw3.append((Word.create_word('Press Enter To Continue').get_label(),(centerX,centerY-100))) thingsToDraw3.append((Word.create_word('Your Health is 0').get_label(),(centerX,centerY+100))) if (player.label == "Player 1"): thingsToDraw3.append((Word.create_word("Player 2 Won!").get_label(),(centerX,centerY+30))) else: thingsToDraw3.append((Word.create_word("Player 1 Won!").get_label(),(centerX,centerY+30))) draw_list(thingsToDraw3) P.display.update() loop = False endGame = True sleep(0.5) break screenWord.add_letter( Letter(keyName,LETTER_COLOR) ) currentLetter = screenWord.get_letters()[currentLetterCount] letterWidth = currentLetter.get_width() xDifferentials = map(lambda x: x + letterWidth,xDifferentials) currentLetterCount += 1 xDifferentials.append(0) if (screenWord.equals(currentWordToType)): player.modifyIndex(1) thingsToDraw[2] = (Word.create_word('Health: {}'.format(player.health)).get_label(),topLeft) nextWord += 1 currentLetterCount = 0 letterWidth = 0 xDifferentials = [] screenWord.clear() if nextWord == len(wordList): G.draw(gm,Word.create_word('You Win!').get_label(),screenCenter) G.draw(gm,Word.create_word('Press Enter Key To Continue').get_label(),(centerX,centerY-100)) P.display.update() loop = False endGame = True break offsetCenter = centerX + ((letterWidth * (screenWord.length - 1)) / 2) thingsToDraw = thingsToDraw[0:4] for pos,letter in enumerate(screenWord.get_letters()): thingsToDraw.append((letter.get_label(),(offsetCenter - xDifferentials[pos],centerY-25))) thingsToDraw[0] = (wordList[nextWord].get_label(),topCenter) draw_list(thingsToDraw) P.display.update() while(startOver): sleep(0.5) for e in P.event.get(): if e.type == P.QUIT: # exit the loop if input is quit startOver = False endGame = True if e.type == P.KEYDOWN: if e.key == P.K_RETURN: startOver = False if e.key == P.K_ESCAPE: # exit loop if escape endGame = True if (player1.health == 0): player = player1 gameOver = True if (player2.health == 0): player = player2 gameOver = True if gameOver: gm.screen.fill(BG_COLOR) thingsToDraw3 = [] thingsToDraw3.append((Word.create_word('Game Over!').get_label(),screenCenter)) thingsToDraw3.append((Word.create_word('Press Enter To Continue').get_label(),(centerX,centerY-100))) thingsToDraw3.append((Word.create_word('Your Health is 0').get_label(),(centerX,centerY+100))) if (player.label == "Player 1"): thingsToDraw3.append((Word.create_word("Player 2 Won!").get_label(),(centerX,centerY+30))) else: thingsToDraw3.append((Word.create_word("Player 1 Won!").get_label(),(centerX,centerY+30))) draw_list(thingsToDraw3) P.display.update() sleep(0.5)
def fill_letter_bst(bst, data): for i in data: letter = Letter(i) bst.insert(letter) return
cipher_without_spaces = cipher_with_spaces.split(' ') freqDict = {} frequency2 = get_letter_frequency(cipher_with_spaces.replace(' ', '')) letters_total = len(cipher_with_spaces.replace(' ', '')) for letter, score in frequency2: freqDict[letter] = (score / float(letters_total)) * 100 del freqDict[' '] #################################### function letters = {} for letter in alphabet: newLetter = Letter(letter, freqDict[letter]) for otherLetter in LETTER_PERCENTAGE: prob = LETTER_PERCENTAGE[otherLetter] newLetter.set_probability(otherLetter, abs(freqDict[letter] - prob)) newLetter.set_frequency(dict(frequency2)[letter]) letters[letter] = newLetter ##################################### #words = list(set(cipher_without_spaces)) words = list(set(cipher_with_spaces)) words.sort(key=len) ######################################## three = get_words_with(3, words) two = get_words_with(2, words)
def __init__(self, input_text): self.input_text = input_text self.input_text_letters = [] for char in self.input_text: self.input_text_letters.append(Letter(char))
def create_word(stringWord, color=G.WHITE): letters = [] for letter in stringWord: letters.append(Letter(letter, color)) return Word(letters, stringWord)
import sys, os sys.path.append(os.pardir) # 親ディレクトリのファイルをインポートするための設定 import numpy as np from alifebook_lib.visualizers import MatrixVisualizer import game_of_life_patterns import time import cv2 from letter import Letter HEIGHT = 70 WIDTH = 70 l1 = Letter() l2 = Letter() l3 = Letter() l4 = Letter() def gen_rands(): return np.random.randint(-5, 6) letter_height = l1.current_letter.shape[0] letter_width = l1.current_letter.shape[1] # visualizerの初期化 (Appendix参照) visualizer = MatrixVisualizer(width=WIDTH * 5, height=HEIGHT * 5)
def gen_header(self): '''creates a new wave inside the stream''' rand_char = choice(alphabet2) rand_brg = -randint(NEW_LETTER_BRG_MIN, NEW_LETTER_BRG_MAX) return Letter(rand_char, rand_brg)
def __init__(self, letter_guess): self.letter_guess = Letter(letter_guess)
def parse(testfile): """ Parses given automaton in Timbuk format :param testfile: filename :return: automaton object """ if not testfile: print("No filename was given.") exit(1) parse_transitions = False alpha = set() automaton_type = "" states = set() final = set() transitions = {} start = set() epsilon_free = True with open(testfile) as filep: for line in filep: if parse_transitions and not line.isspace(): parts = line.split("->") """if '"' not in line: start.add(parts[1].strip()) continue""" if "(" not in line and ")" not in line: start.add(parts[1].strip()) continue end_state = parts[1].strip() if '"' in line: parts = parts[0].split("\"") predicate = parsePredicate(parts[1], automaton_type) else: if line.strip().startswith("("): predicate = Epsilon() epsilon_free = False parts = ["", "", parts[0]] else: symbol = parts[0].split("(")[0].strip() start_st = parts[0].split("(")[1] parts = ["", "", start_st] predicate = parsePredicate(symbol, automaton_type) start_state = parts[2].replace("(", "").replace(")", "").strip() if predicate not in transitions[start_state]: transitions[start_state][predicate] = [end_state] else: if end_state not in transitions[start_state][predicate]: transitions[start_state][predicate].append(end_state) continue if line.startswith("Ops "): for element in line.split(" ")[1:]: if not element.isspace(): if ":" in element: parts = element.split(":") if int(parts[1]) > 0 and not parts[0].isspace(): alpha.add(parts[0]) else: alpha.add(element) continue if line.startswith("Automaton "): if "@" in line: automaton_type = line.split("@")[1].strip() if automaton_type == "INFA": from in_notin_parser import parsePredicate from in_notin import InNotin label = InNotin() elif automaton_type == "LFA": from letter_parser import parsePredicate from letter import Letter label = Letter() elif automaton_type == "INT": from transducer_predicate import parsePredicate from transducer_predicate import TransPred label = TransPred() elif automaton_type == "GBA": from letter_parser import parsePredicate from letter import Letter label = Letter() else: automaton_type = "LFA" from letter_parser import parsePredicate from letter import Letter label = Letter() if line.startswith("States "): for element in line.split(" ")[1:]: if not element.isspace(): element = element.strip() states.add(element) transitions[element] = {} continue if line.startswith("Final States"): if automaton_type == "GBA": line = line[12:] final = [] for element in line.split(";"): new_set = set() for st in element.split(" "): if not st.isspace() and len(st): st = st.strip() new_set.add(st) if len(new_set): final.append(new_set) else: for element in line.split(" ")[2:]: if not element.isspace(): element = element.strip() final.add(element) continue if line.startswith("Transitions"): parse_transitions = True transitions_reduced = transitions.copy() for state in transitions: if not transitions[state]: del transitions_reduced[state] transitions = transitions_reduced automaton = type_to_class(automaton_type) automaton.alphabet = alpha automaton.states = states automaton.start = start automaton.final = final automaton.transitions = transitions automaton.automaton_type = automaton_type automaton.is_deterministic() automaton.label = label automaton.is_epsilon_free = epsilon_free check_result = automaton.check_automaton() if check_result != "OK": print("ERROR: " + testfile + " : " + check_result) exit(-1) if automaton.is_epsilon_free and automaton_type != "GBA": automaton = automaton.simple_reduce() return automaton
def render_letters(self): for char in self.text: self.letters.append(Letter(char, self.font))
from login import Myinfo from letter import Letter from naver_news import * from naver_sports import * if __name__ == '__main__': myinfo = Myinfo() myinfo.login() letter = Letter(session=myinfo.login_session) letter.find_army() title_list, content_list = naver_start() # title_list, content_list = sports_start() for i in range(len(title_list)): print(title_list[i]) letter.send_letter(title_list[i], content_list[i])
def spawn_letter(): ret = Letter(alphabet[random.randrange(0, 26, 1)]) # gives us x number between 30 and 610, in lanes 30 pixels wide ret.set_position(random.randrange(30, 610, 30), 0) return ret
font = pygame.font.Font(None, 36) clock = pygame.time.Clock() clock.tick(60) pygame.time.set_timer(pygame.USEREVENT, 1000) hf.game_bootloader() hf.load_splash_screen(screen, font) difficulty = Difficulty(screen, font, counter_starting_value) savefile = Savefile(settings.SAVE_LOCATION[difficulty.mode]) hf.ready_to_start(screen, font) counter = counter_starting_value hf.start_music() current_letter = Letter() current_letter.randomize_attributes(difficulty.letters) backGround = BackGround(settings.BACKGROUND_IMAGE, settings.BACKGROUND_IMAGE_STARTING_POINT) while True: for event in pygame.event.get(): if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE): savefile.save_file() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == settings.MATCHING_EVENTS_TO_LETTERS[ current_letter.value]: counter = counter_starting_value
def typing(): loop = True startOver = True screen = P.display.set_mode((G.D_WIDTH, G.D_HEIGHT), 0, 32) gm = GameMenu(screen, [], G.BLACK) screenWord = Word([]) words = G.make_word_list() wordList = map(lambda listword: Word.create_word(listword), words) nextWord = 0 currentWordToType = wordList[nextWord] currentWordLabel = currentWordToType.get_label() currentLetterCount = 0 letterWidth = 0 P.key.set_repeat(500, 50) #so people can hold a key down BG_COLOR = G.BLACK LETTER_COLOR = G.DEF_LETTER_COLOR screenCenter = G.SCREEN_CENTER topCenter = G.TOP_CENTER topLeft = (topCenter[0] - 200, topCenter[1] - 50) topRight = (topCenter[0] + 200, topCenter[1] - 50) centerX = screenCenter[0] centerY = screenCenter[1] def draw_list(thingsToDraw): for (label, (x, y)) in thingsToDraw: G.draw(gm, label, (x, y)) thingsToDraw = [] lastLetter = None xDifferentials = [] P.time.set_timer(P.USEREVENT, 1000) # timer set for each second difficulty_setting = G.DIFFICULTY_LEVEL if difficulty_setting == 1: timeCount = 60 timeText = "1:00" elif difficulty_setting == 2: timeCount = 30 timeText = "0:30" else: timeCount = 15 timeText = "0:15" score = G.SCORE gm.screen.fill(BG_COLOR) # set initial background thingsToDraw.append((currentWordLabel, topCenter)) thingsToDraw.append((Word.create_word(timeText).get_label(), topRight)) thingsToDraw.append( (Word.create_word('Score: {}'.format(score)).get_label(), topLeft)) draw_list(thingsToDraw) P.display.flip() while loop: currentWordToType = wordList[nextWord] currentWordLabel = currentWordToType.get_label() thingsToDraw[0] = (currentWordLabel, topCenter) for e in P.event.get(): gm.screen.fill(BG_COLOR) if e.type == P.QUIT: # exit the loop if input is quit loop = False startOver = False break if e.type == P.USEREVENT: timeCount -= 1 if timeCount >= 10: timeText = "0:{}".format(timeCount) elif timeCount >= 0: timeText = "0:0{}".format(timeCount) else: gm.screen.fill(BG_COLOR) thingsToDraw = [] thingsToDraw.append( (Word.create_word('Game Over!').get_label(), screenCenter)) thingsToDraw.append((Word.create_word( 'Press Any Key To Continue').get_label(), (centerX, centerY - 100))) thingsToDraw.append((Word.create_word( 'Your Score was {}'.format(score)).get_label(), (centerX, centerY + 100))) draw_list(thingsToDraw) P.display.update() loop = False sleep(0.5) break timeWord = Word.create_word(timeText) thingsToDraw[1] = (timeWord.get_label(), topRight) draw_list(thingsToDraw) P.display.update() if e.type == P.KEYDOWN: # on keypress if e.key in G.SPECIAL_KEYS: # for special key presses if e.key == P.K_ESCAPE: # exit loop if escape loop = False startOver = False break if e.key == P.K_RETURN: # clear word typed so far if enter is pressed screenWord.clear() #label = screenWord.get_label() currentLetterCount = 0 xDifferentials = [] thingsToDraw = thingsToDraw[0:3] draw_list(thingsToDraw) P.display.update() if e.key == P.K_BACKSPACE: # remove letter from the word being typed if backspace #if currentLetterCount <= 0: # currentLetter = 0 score -= 10 thingsToDraw[2] = (Word.create_word( 'Score: {}'.format(score)).get_label(), topLeft) screenWord.remove_letter() #label = screenWord.get_label() offsetCenter = centerX + ( (letterWidth * (screenWord.length - 1)) / 2) if xDifferentials != []: xDifferentials = xDifferentials[:-1] if xDifferentials != []: letterWidth = xDifferentials[ len(xDifferentials) - 1] else: letterWidth = 0 xDifferentials = map(lambda x: x - letterWidth, xDifferentials) thingsToDraw = thingsToDraw[0:3] for pos, letter in enumerate( screenWord.get_letters()): thingsToDraw.append( (letter.get_label(), (offsetCenter - xDifferentials[pos], centerY - 25))) draw_list(thingsToDraw) P.display.update() else: thingsToDraw = thingsToDraw[0:3] for pos, letter in enumerate( screenWord.get_letters()): thingsToDraw.append( (letter.get_label(), (screenCenter - xDifferentials[pos], centerY - 25))) draw_list(thingsToDraw) P.display.update() currentLetterCount -= 1 if currentLetterCount < 0: currentLetterCount = 0 # if e.key == P.K_SPACE: # screenWord.add_letter(Letter(' ')) # currentLetter = screenWord.get_letters()[currentLetterCount] # letterWidth = currentLetter.get_width() # xDifferentials = map(lambda x: x + letterWidth,xDifferentials) # currentLetterCount += 1 # xDifferentials.append(0) # if (screenWord.equals(currentWordToType)): # nextWord += 1 # currentLetterCount = 0 # letterWidth = 0 # xDifferentials = [] # screenWord.clear() # if nextWord == len(wordList): # G.draw(gm,Word.create_word('You Win!').get_label(),screenCenter) # G.draw(gm,Word.create_word('Press Any Key To Continue').get_label(),(centerX,centerY-100)) # P.display.update() # loop = False # break # offsetCenter = centerX + ((letterWidth * (screenWord.length - 1)) / 2) # thingsToDraw = thingsToDraw[0:3] # for pos,letter in enumerate(screenWord.get_letters()): # thingsToDraw.append((letter.get_label(),(offsetCenter - xDifferentials[pos],centerY-25))) # thingsToDraw[0] = (wordList[nextWord].get_label(),topCenter) # draw_list(thingsToDraw) # P.display.update() else: pass elif e.key in range(0, 255): if currentLetterCount == len(currentWordToType.get_text()): screenWord.clear() xDifferentials = [] nextWord += 1 currentLetterCount = 0 letterWidth = 0 thingsToDraw = thingsToDraw[0:3] draw_list(thingsToDraw) P.display.update() else: keyName = P.key.name(e.key) if P.key.get_mods() in (1, 2) or P.key.get_mods() in ( 4097, 4098): #checks for left shift and right shift keyName = keyName.upper() if currentLetterCount < currentWordToType.length and \ keyName == wordList[nextWord].get_text()[currentLetterCount]: LETTER_COLOR = G.GREEN score += 10 thingsToDraw[2] = (Word.create_word( 'Score: {}'.format(score)).get_label(), topLeft) else: LETTER_COLOR = G.RED score -= 10 thingsToDraw[2] = (Word.create_word( 'Score: {}'.format(score)).get_label(), topLeft) screenWord.add_letter(Letter(keyName, LETTER_COLOR)) currentLetter = screenWord.get_letters( )[currentLetterCount] letterWidth = currentLetter.get_width() xDifferentials = map(lambda x: x + letterWidth, xDifferentials) currentLetterCount += 1 xDifferentials.append(0) if (screenWord.equals(currentWordToType)): score += 30 thingsToDraw[2] = (Word.create_word( 'Score: {}'.format(score)).get_label(), topLeft) nextWord += 1 currentLetterCount = 0 letterWidth = 0 xDifferentials = [] screenWord.clear() if nextWord == len(wordList): G.draw( gm, Word.create_word('You Win!').get_label(), screenCenter) G.draw( gm, Word.create_word( 'Press Any Key To Continue').get_label( ), (centerX, centerY - 100)) P.display.update() loop = False break offsetCenter = centerX + ( (letterWidth * (screenWord.length - 1)) / 2) thingsToDraw = thingsToDraw[0:3] for pos, letter in enumerate(screenWord.get_letters()): thingsToDraw.append( (letter.get_label(), (offsetCenter - xDifferentials[pos], centerY - 25))) thingsToDraw[0] = (wordList[nextWord].get_label(), topCenter) draw_list(thingsToDraw) P.display.update() while (startOver): sleep(0.5) for e in P.event.get(): if e.type == P.QUIT: # exit the loop if input is quit startOver = False if e.type == P.KEYDOWN: startOver = False
import sys from word import Word from letter import Letter import pygame import Globals as G test_letter = Letter( 'a', G.WHITE, G.MONOSPACE_FONT, 30, (20, 20) ) #Letter constuctor based on pygame Font which takes in (text,color,font,size,(posx,posy)) font = pygame.font.Font(None, 30) def test_set_get_letter(): assert (test_letter.get_letter() == 'a') test_letter.set_letter('B') assert (test_letter.get_letter() == 'B') test_letter.set_letter('a') def test_set_get_label(): test_letter.set_label(G.WHITE) assert (test_letter.label == test_letter.get_label()) def test_set_position(): assert (test_letter.pos_x == 20 and test_letter.pos_y == 20) test_letter.set_position(0, 10) assert (test_letter.pos_x == 0 and test_letter.pos_y == 10)
rows = db.select_all_letters(conn) for row in rows: letter = convert_if_similar(row[1]) # ignore 'w' & 'W' if letter == 'w' or letter == 'W': continue image = row[2] drawn_in_free_mode = 0 try: drawn_in_free_mode = row[3] except IndexError: pass letters.append(Letter(author, letter, image, drawn_in_free_mode)) if len(rows) == 0: # indicate empty db print(database + ' is empty!') conn.close() # creating or opening output db file os.makedirs(DB_OUTPUT_FOLDER, exist_ok=True) conn = db.create_connection(DB_RESULT) db.drop_table(conn) db.create_table(conn) db.insert_all_letters(conn, letters)
def test_equals(): letter1 = Letter('a', G.WHITE, G.MONOSPACE_FONT, 20, (50, 50)) letter2 = Letter('b', G.WHITE, G.MONOSPACE_FONT, 30, (20, 20)) assert (test_letter.equals(letter1)) assert (test_letter.equals(letter2) == False)
# # WARNING: These emails will appear in the "Sent" folder of the email... So be # careful to either (a) not look in your sent folder, or (b) use an email that # you're not planning to login with. ################################################################################ smtp_user = '******' smtp_pass = '******' ################################################################################ # This the secret santa letter template that is used to send everyone the email. # Note that {santa} and {recipient} are automatically replaced by the secret # santa's name, and his/her recipient of their gift. ################################################################################ letter = Letter(from_name='Secret Santa', from_email=smtp_user, subject='Family Christmas', greeting="{santa}, you are {recipient}'s secret Santa!", body="") ################################################################################ # The complete list of all the secret santa's and their email addresses. ################################################################################ santas = [ Santa('Jan', '*****@*****.**'), Santa('Alisha', '*****@*****.**'), Santa('Pam', '*****@*****.**'), Santa('Mark', '*****@*****.**'), Santa('Nick', '*****@*****.**'), Santa('Erica', '*****@*****.**'), Santa('Luke', '*****@*****.**'), Santa('Sidney', '*****@*****.**'),
def addRandomLetter(): letters.append( Letter(unichr(97 + random(26)), random(width - 32), random(-200, -50), color(random(256), random(256), random(256))))