Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Morse code "Teacher" program
- morse={"._","_...","_._.","_..",".",".._.","__.","....","..",".___","_._","._..","__","_.","___",".__.","__._","._.","...","_",".._","..._",".__","_.._","_.__","__..",".____","..___","...__","...._",".....","_....","__...","___..","____.","_____"}
- letters={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","1","2","3","4","5","6","7","8","9","0"}
- function hws()
- if fs.exists(".morsestats") and not fs.isDir(".morsestats") then
- r=fs.open(".morsestats","r")
- y=r.readLine()
- if tonumber(y) then
- hs=tonumber(y)
- else
- hs=0
- end
- r.close()
- else
- hs=0
- end
- return hs
- end
- function clear()
- shell.run("clear")
- end
- function menu(hs)
- clear()
- tab={"Learn","Test","Exit"," "," ","Highscore: "..hs,"By NNet Inc.(Sylvyrfysh) (C)2013. Full terms of use can be found at nnet.org/programs/tc/morse"}
- for t,y in pairs(tab) do
- print(y)
- end
- while true do
- e={os.pullEvent("mouse_click")}
- if e[4]>3 then
- else
- return tab[e[4]]
- end
- end
- end
- canRun=true
- while canRun do
- notBroken=true
- hs=hws()
- dothing=menu(hs)
- if dothing=="Learn" then
- prnts={}
- for t=1,#morse do
- table.insert(prnts,string.gsub(morse[t],"_","-").." = "..letters[t])
- end
- e,v=term.getSize()
- x=1
- while true do
- clear()
- for t=1,v-1 do
- print(prnts[x])
- x=x+1
- end
- write("Exit")
- p={os.pullEvent()}
- if p[1]=="mouse_scroll" then
- if p[2]==1 then
- x=19
- else
- x=1
- end
- elseif p[1]=="mouse_click" and p[4]==v then
- break
- end
- end
- elseif dothing=="Test" then
- clear()
- term.setCursorPos(1,1)
- print("Enter highest letter, or 'all' for all letters: ")
- u=read()
- if u=="all" then
- highest=#morse
- else
- for t,y in pairs(letters) do
- if y==u then
- highest=t
- break
- end
- highest=#morse
- end
- end
- clear()
- print("Press '-' for a long tap, or '.' for a short tap.")
- write("Loading.")
- for o=1,5 do
- write(".")
- sleep(1)
- end
- score=0
- while true do
- n=math.random(1,highest)
- clear()
- print(morse[n].." is: Or enter 'exit' to exit.")
- print("Score: "..score)
- term.setCursorPos(1,3)
- g=read()
- if g=="exit" then
- break
- else
- if g==letters[n] then
- score=score+1
- if score>hs then
- if notBroken then
- print("NEW HIGHSCORE!")
- end
- r=fs.open(".morsestats","w")
- r.write(score)
- r.close()
- notBroken=false
- end
- print("Great!")
- sleep(2)
- else
- print("Oops! That letter was "..letters[n])
- sleep(2)
- end
- end
- end
- elseif dothing=="Exit" then
- canRun=false
- clear()
- print("Thanks for using Morse by NNet(Sylvyrfysh)!")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement