Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/ls.py
blob: 82a19da9c688bfd002f9fec9cc0e3fe09debff89 (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
from las import listenspell



las = listenspell()
las.clearscreen()
las.playsound("begin")

########################################################################################
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

    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)

## 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
	    or any other key to answer"""
	    if reprint == True:
		print string
	    #las.saytext(string)
	    k = las.getkey()
	    if k == "1":
		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)
		    num_sample = num_sample - 1
		    if num_sample != 0:
			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))
	    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

########################################################################################
def shout(string):
    for character in string:
	print character + " "
	las.saytext(character)
########################################################################################
def getskilllevel():
# 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)




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()