-- Find English word for LuaRT
-- There are 488 words in the file.
-----------------------------------
-- Computer Guess a word in Database
local file = sys.File("EnglishWords_S.txt")
file:open("read")
local wordLine= math.random(1,488*5)
wordLine= wordLine + 1 - math.fmod(wordLine,5)
file.position = wordLine
local computerWord = (tostring(file:read(5))):upper()
local words= tostring(file:read()):upper()
file.position = 1
local keyboard= {}
local wordBox= {}
local entryIndex= 1
local keyboard_Y = 410
local wordBox_Y = 0
local minwordBoxIndex = 1
local maxwordBoxIndex = 5
local keyword={"Q","W","E","R","T","Y","U","I","O","P",
"A","S","D","F","G","H","J","K","L",
"ENT","Z","X","C","V","B","N","M","<--"}
local ui = require "ui"
local win = ui.Window("Find My Word Beta V0.1","single", 600, 640)
local msgLabel= ui.Label(win, "",215,20)
win.bgcolor = 0xFFFFFF
msgLabel.bgcolor = 0x323232
msgLabel.fgcolor = 0xFFFFFF
msgLabel.fontsize = 16
--msgLabel.textalign = "center"
msgLabel.visible = false
for i=1,30 do -- Word
if i==1 or i==6 or i==11 or i==16 or i==21 or i==26 then
wordBox_Y= wordBox_Y + 65
wordBox[i] = ui.Label(win, "",140, wordBox_Y,60,60)
else
wordBox[i] = ui.Label(win, "",wordBox[i-1].x+65, wordBox[i-1].y,60,60)
end
wordBox[i].fontsize = 30
wordBox[i].textalign = "center"
wordBox[i].bgcolor = 0xE5E5E5
end
function animation(_i)
wordBox[_i].bgcolor = 0xCCCED1
ui.update(200)
end
local function letter_onClick(self)
if self.text == "<--" then
if entryIndex > minwordBoxIndex then
entryIndex = entryIndex - 1
wordBox[entryIndex].text = ""
end
elseif self.text=="ENT" then
if entryIndex == maxwordBoxIndex + 1 then
local guess = ""
for i = minwordBoxIndex, maxwordBoxIndex do
guess = guess..wordBox[i].text
end
local temp3,temp4 = string.find(tostring(file:read()):upper(), guess)
file.position = 1
if (temp3) and (temp4) then
for i= minwordBoxIndex, maxwordBoxIndex do
wordBox[i].fgcolor= 0xFFFFFF -- White
animation(i)
wordBox[i].bgcolor= 0x787C7E -- Dark Grey
end
if guess == computerWord then
msgLabel.visible = true
msgLabel.text = " Yes!!! Great"
entryIndex = 31
end
local temp1 = 0
for char1 in each(guess) do
local temp2 = 0
temp1 = temp1 + 1
for char2 in each(computerWord) do
temp2 = temp2 + 1
if char1 == char2 then
if temp1 == temp2 then
wordBox[temp1 + minwordBoxIndex - 1].bgcolor = 0x6AAA64 --Green
else
wordBox[temp1 + minwordBoxIndex - 1].bgcolor = 0XC9B458 --Yellow
end
end
end
end
if entryIndex > 29 then
msgLabel.visible = true
msgLabel.text = " USAGE !"
entryIndex = 31
end
minwordBoxIndex = minwordBoxIndex + 5
maxwordBoxIndex = maxwordBoxIndex + 5
else
msgLabel.visible = true
msgLabel.text = "Not in word list"
ui.update(1300)
msgLabel.visible = false
end
else
msgLabel.visible = true
msgLabel.text = "Not enough letter"
ui.update(1300)
msgLabel.visible = false
end
elseif entryIndex < maxwordBoxIndex + 1 then
wordBox[entryIndex].text= self.text
entryIndex = entryIndex + 1
end
end
for i=1,28 do -- Keyboard
if i == 1 then
keyboard_Y = keyboard_Y + 55
label = ui.Label(win, keyword[i], 75, keyboard_Y, 40, 50)
elseif i == 11 then
keyboard_Y = keyboard_Y + 55
label = ui.Label(win, keyword[i], 95, keyboard_Y, 40, 50)
elseif i == 20 then
keyboard_Y = keyboard_Y + 55
label = ui.Label(win, keyword[i], 55, keyboard_Y, 80, 50)
elseif i == 21 then
label = ui.Label(win, keyword[i], 140, keyboard_Y, 40, 50)
elseif i == 28 then
label = ui.Label(win, keyword[i], keyboard[i-1].x + 45, keyboard[i-1].y, 80, 50)
else
label = ui.Label(win, keyword[i], keyboard[i-1].x + 45, keyboard[i-1].y, 40, 50)
end
label.onClick = letter_onClick
keyboard[#keyboard+1] = label
keyboard[i].textalign = "center"
keyboard[i].bgcolor = 0xE5E5E5
keyboard[i].fontsize = 20
end
win:show()
repeat
ui.update()
until not win.visible
Edits:
- database file updated.. "EnglishWords_S.txt"
- now word predictions work correctly.
To Do List
- If there are 2 same letters in the word that the computer keeps in its memory, the result is produced incorrectly. (to be fixed)
- Animation will be improved. (WIP)
- It will tell you how many guesses you have found the word that the computer keeps in its memory (WIP)
- Fonts will be reset (WIP)
new file download [[Login to see the link]
](https://)