Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.clear()
- term.setCursorPos(1,1)
- term.write("Enter in the secret word:")
- term.setCursorPos(1,2)
- local word = string.lower(string.match(read(),"%a+"))
- local chat = peripheral.wrap("chat_box_2")
- local correct = {}
- for i = 1,string.len(word),1 do
- correct[i] = false
- end
- local running = true
- local status = ""
- local retype = true
- local getstring = function(tbl,text)
- local out = ""
- for i = 1,table.maxn(tbl),1 do
- if tbl[i] then
- out = out .. string.sub(text,i,i)
- else
- out = out .. "_"
- end
- end
- return out
- end
- while running do
- if retype then
- if status ~= "" then
- chat.say(status)
- end
- chat.say("Hangman: " .. getstring(correct,word))
- chat.say("Enter in a letter from a-z to guess the word!")
- end
- retype = false
- local event,player,message = os.pullEvent("chat")
- if string.sub(message,1,1) == message then
- retype = true
- message = string.lower(string.sub(message,string.find(message,"%a")))
- if message then
- for i = 1,table.maxn(correct),1 do
- if message == string.sub(word,i,i) then
- correct[i] = true
- end
- end
- else
- status = "Please enter in a letter (a-z)"
- end
- end
- running = false
- for i = 1,string.len(message),1 do
- if not correct[i] then
- running = true
- end
- end
- if message == word then
- running = false
- end
- if not running then
- chat.say(player .. " won the game!")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement