Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/ls.py
diff options
context:
space:
mode:
Diffstat (limited to 'ls.py')
-rw-r--r--ls.py269
1 files changed, 133 insertions, 136 deletions
diff --git a/ls.py b/ls.py
index 6871e61..52b0a34 100644
--- a/ls.py
+++ b/ls.py
@@ -1,156 +1,153 @@
-from las import listenspell
+from las import Listenspell
########################################################################################
-def playword(wordid):
- elem = las.getwordinfo(wordid, "word") #get a word from the list
- pronounelem = las.getwordinfo(wordid, "phnm") #get a pronounciation from the list
+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.saytext("Spell... ... " + elem + "... " + pronounelem)
- else:
- print "Spell... "
- las.saytext("Spell... ... " + elem)
+ 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.getkey()
- #las.saytext(k)
- if k == "*":
- las.exitgame()
-
- 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.getkey()
- if k == "1":
+ 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
- definition = las.getwordinfo(wordid, "def")
- for (pos, definition) in definition:
- print pos + " : " + definition
- elif k == "2":
- usage = las.getwordinfo(wordid, "usage")
- num_sample = len(usage)
- if num_sample == 0:
- print "No usage in the database"
- reprint = True
- for (sample) in usage:
- las.saytext(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.getkey()
- if k != 'n': break
- elif k == "3":
- las.saytext(elem)
- reprint = False
- elif k == "4":
- print "Word Length:" + str(len(elem))
- elif k =="*":
- las.exitgame()
- else:
- cluemode = False
-
- answer = raw_input( "Your answer: " )
- answer = answer.strip()
- las.saytext("You typed\n")
- shout(answer)
- if answer == elem:
- las.saytext("Correct")
- las.ans_correct(wordid)
- return True
- else:
- las.ans_incorrect(wordid)
- las.saytext("Incorrect")
- print "Incorrect. The correct spelling is.. "
- las.saytext("The correct spelling is..\n")
- shout(elem)
- return False
+ 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.saytext(character)
+ for character in string:
+ print character + " "
+ las.say_text(character)
########################################################################################
-def getskilllevel():
+def get_skill_level():
# get a skill level
- print 'Enter skill level between 1 and 9, or * to quit'
- las.saytext("Skill level")
- k = las.getkey()
- if k == "*":
- las.exitgame() # quit the program
- print k
- las.saytext(k)
-
- skill_level = int(k) + 3
-
- las.setskill_level( 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()
- las.clearscreen()
- las.playsound("begin")
-
- gameover = False
- while gameover == False:
- levelsize = 7 # this stays constant throughout
-
- getskilllevel()
- wordidlist = las.load_wordid(levelsize + 3) # At max Three error possible
- num_words = len(wordidlist)
- las.clearscreen()
-
- #### MAIN LOOP
-
- las.playsound("begin")
-
-
- for index in range(num_words):
-
- ## print pronouncedict
- ## print pronouncedictstring
- ## print pronouncelist
- wordid = wordidlist[index]
- result = playword(wordid)
- print "Your score is " + str(las.getpoints())
-
- if result == True:
- if las.getwords_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.getkey()
- if k == '%':
- break # Restart game with next level
- else:
- las.exitgame()
-
- if las.getwords_correct == 7:
- continue # Restart game with next level
- else:
- gameover = True
- las.saytext("Game Over")
- print "Game Over."
- las.exitgame()
+ las = Listenspell()
+ 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.getpoints())
+
+ 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()