blob: 52b0a342ed59952216dedddc7cb3d1d558cfe9bd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
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()
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()
|