from las import Listenspell ######################################################################################## def play_word(wordid): elem = las.get_word_info(wordid, "word") #get a word from the list pronounelem = las.get_word_info(wordid, "phnm") #get a pronounciation from the list if elem != pronounelem: # determine whether to bother pronouncing a description print "Spell..." # say the explanation if the word is ambiguous. las.say_text("Spell... ... " + elem + "... " + pronounelem) else: print "Spell... " las.say_text("Spell... ... " + elem) ## get an answer print 'Press $ to answer or spacebar to get a clue. Press * to quit' k = las.get_key() #las.saytext(k) if k == "*": las.exit_game() if k == " ": # if the user wants a clue cluemode = True reprint = True while(cluemode): string = """press 1 for definition 2 for Sample 3 to repete the word 4 for word length * to quit or any other key to answer""" if reprint == True: print string #las.saytext(string) k = las.get_key() if k == "1": reprint = True definition = las.get_word_info(wordid, "def") for (pos, definition) in definition: print pos + " : " + definition elif k == "2": usage = las.get_word_info(wordid, "usage") num_sample = len(usage) if num_sample == 0: print "No usage in the database" reprint = True for (sample) in usage: las.say_text(sample) reprint = False num_sample = num_sample - 1 if num_sample != 0: reprint = True print "To get another sample press 'n' or anyother key to answer" k = las.get_key() if k != 'n': break elif k == "3": las.say_text(elem) reprint = False elif k == "4": print "Word Length:" + str(len(elem)) elif k =="*": las.exit_game() else: cluemode = False answer = raw_input( "Your answer: " ) answer = answer.strip() las.say_text("You typed\n") shout(answer) if answer == elem: las.say_text("Correct") las.ans_correct(wordid) return True else: las.ans_incorrect(wordid) las.say_text("Incorrect") print "Incorrect. The correct spelling is.. " las.say_text("The correct spelling is..\n") shout(elem) return False ######################################################################################## def shout(string): for character in string: print character + " " las.say_text(character) ######################################################################################## def get_skill_level(): # get a skill level print 'Enter skill level between 1 and 9, or * to quit' las.say_text("Skill level") k = las.get_key() if k == "*": las.exit_game() # quit the program print k las.say_text(k) skill_level = int(k) + 3 las.set_skill_level( skill_level) if __name__=='__main__': las = Listenspell("dict.db") las.clear_screen() las.play_sound("begin") gameover = False while gameover == False: levelsize = 7 # this stays constant throughout get_skill_level() wordidlist = las.load_wordid(levelsize + 3) # At max Three error possible num_words = len(wordidlist) las.clear_screen() #### MAIN LOOP las.play_sound("begin") for index in range(num_words): ## print pronouncedict ## print pronouncedictstring ## print pronouncelist wordid = wordidlist[index] result = play_word(wordid) print "Your score is " + str(las.get_points()) if result == True: if las.get_words_correct == 7: print "Very good." print "If you want to play game again with another level press % or any other key to quit" k = las.get_key() if k == '%': break # Restart game with next level else: las.exit_game() if las.get_words_correct == 7: continue # Restart game with next level else: gameover = True las.say_text("Game Over") print "Game Over." las.exit_game()