Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function explode(str,char)
- local tbl = {}
- if char == "" then
- for i=1, str:len() do
- table.insert(tbl,str:sub(i,i))
- end
- return tbl
- elseif not str:find(char) then
- return {str}
- else
- local _,amt = str:gsub(char," ")
- for i=1, amt+1 do
- if str:find(char) then
- local x,y = str:find(char)
- local rep = str:sub(1,x-1)
- table.insert(tbl,rep)
- str = str:sub(y+1, str:len())
- else
- table.insert(tbl,str)
- end
- end
- end
- return tbl
- end
- local words = {
- "test",
- "scoopta",
- "cloudninja",
- "explode",
- "wubstep",
- "kitty",
- "gaming",
- "switchcraft",
- "programming",
- "download"
- }
- local chosenWord = words[math.random(1,#words)]
- local wTable = explode(chosenWord,"")
- local aTable = {}
- local solved = false
- local failed = false
- local gCorrect = 0
- for k,v in pairs(wTable) do
- aTable[k] = "_"
- end
- local function eval(inp)
- local correct = 0
- for k,v in pairs(wTable) do
- if string.lower(inp) == string.lower(v) then
- correct = correct+1
- wTable[k] = "_"
- aTable[k] = inp
- end
- end
- local count = 0
- for k,v in pairs(wTable) do
- if v == "_" then
- count = count+1
- end
- end
- if count == #wTable then
- solved = true
- end
- if correct < 1 then
- gCorrect = gCorrect+1
- end
- if gCorrect > 4 then
- failed = true
- end
- end
- term.clear()
- while solved ~= true do
- print()
- term.clear()
- term.setCursorPos(1,1)
- print(table.unpack(aTable))
- print(" Tries Left: "..(6-gCorrect))
- write("Enter a letter: ")
- local input = read()
- print()
- if input == chosenWord then
- solved = true
- elseif #input < 1 then
- write("Please Enter a letter (press a key to continue)")
- sleep(0.5)
- os.pullEvent("key_up")
- elseif failed then
- break
- else
- eval(input)
- end
- end
- if solved then
- term.clear()
- term.setCursorPos(1,1)
- print("Solved")
- print("Word was: "..chosenWord)
- elseif failed then
- term.clear()
- term.setCursorPos(1,1)
- print("Failed")
- print("Word was: "..chosenWord)
- end
Advertisement
Add Comment
Please, Sign In to add comment