Hi All.
I think I finished the word puzzle. I would appreciate it if you could reply for any mistakes.
Setup
Create a "Data" folder in the folder where your code file is located. Place all the image files you will download from the download link into the "Data" folder. Run your code.
Fixed
- The vocabulary dictionary has been renewed and now contains 5757 words. (Done)
- If there are 2 same letters in the word that the computer keeps in its memory, the result is produced incorrectly. (Done)
- Animation will be improved. (Done)
- The colors in the "letter boxes" must be on the keyboard.(Done)
- It will tell you how many guesses you have found the word that the computer keeps in its memory (Done)
- Settings window will be added (Done)
- Dark Theme will be added in settings window (Done)
- Hard Mode will be added in settings window (Done)
- Help window will be added (Done)
- There will be a brief description of the game in the Help section. (Done)
- While there is one letter A in the word, if there are 2 A's in the guess, one of them is green. (Done)
- Fonts will be edited. (WIP)
Download Pictures Link
[Login to see the link]
[Login to see the link]
[Login to see the link]
[Login to see the link]
[Login to see the link]
[Login to see the link]
[Login to see the link]
[Login to see the link]
[Login to see the link]
[Login to see the link]
[Login to see the link]
Code
-- Find English word for LuaRT
-- There are 5757 words in the file.
-----------------------------------
-- Computer Guess a word in Database
local file = sys.File("Data\\dictionary")
file:open("read")
local wordLine= math.random(1,5757*5)
wordLine= wordLine + 1 - math.fmod(wordLine,5)
file.position = wordLine
local computerWord = (tostring(file:read(5))):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 V 1.0","single", 600, 665)
local msgLabel= ui.Label(win, "",175,105,250,50)
local msgLabelHardMode= ui.Label(win, "",140,45)
local pictureHelp = ui.Picture(win, "Data\\help-24.ico", 515,15)
local pictureLuaRT = ui.Picture(win, "Data\\LuaRTWhite.png", 10,10)
local pictureSettings = ui.Picture(win, "Data\\settings-24.ico", 550,15)
win.bgcolor = 0xFFFFFF -- White
win:center()
msgLabel.bgcolor = 0x323232 -- Dark Black for themes
msgLabel.fgcolor = 0xFFFFFF -- White
msgLabel.fontsize = 22
msgLabel.textalign = "center"
msgLabel.visible = false
msgLabelHardMode.fgcolor = 0x000000
local winSettings = ui.Window("","single", 250, 300)
local checkboxLevel = ui.Checkbox(winSettings, "", 65, 50, 20, 20)
local checkboxDark = ui.Checkbox(winSettings, "", 65, 90, 20, 20)
local labelLevel = ui.Label(winSettings, "Hard Mode", 90, 52)
local labelDark = ui.Label(winSettings, "Dark Theme", 90, 92)
winSettings:center()
winSettings.bgcolor = 0xFFFFFF -- White
local httpLabel= ui.Label(win, "www.luart.org",140,15,100,30)
local buttonGithub = ui.Button(win, "Github", 285, 15 )
local buttonTwitter = ui.Button(win, "Twitter", 355, 15)
local buttonYoutube = ui.Button(win, "Youtube", 425, 15)
httpLabel.fontsize = 12
httpLabel.fgcolor = 0xFF0000
buttonGithub:loadicon("Data\\Github.ico")
buttonTwitter:loadicon("Data\\Twitter.ico")
buttonYoutube:loadicon("Data\\Youtube.ico")
local winHelp = ui.Window("","single", 413, 490)
local pictureLoad = ui.Picture(winHelp, "Help.png")
winHelp:center()
win:status("Copyright © 2023 Coskun .. coded with LuaRT")
win:show()
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 -- Light Grey
end
local function letter_onClick(self)
if entryIndex < 32 then
if self.text == "<--" then
if entryIndex > minwordBoxIndex then
entryIndex = entryIndex - 1
wordBox[entryIndex].text = ""
end
elseif self.text=="ENT" then
local hardModeGreen = 0
local hardModeYellow = 0
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
local temp1 = 0
local color={0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF} --White
for charGuess in each(guess) do
local repaitsGuess = repeats(guess, charGuess)
local repaitsComputerWord = repeats(computerWord, charGuess)
local temp2 = 0
temp1 = temp1 + 1
if #repaitsComputerWord < 1 then
color[temp1] = 0x787C7E --Dark Grey
elseif color[temp1] == 0xFFFFFF then
color = editColor(repaitsGuess,repaitsComputerWord,color)
end
if checkboxLevel.checked == true then --Hard Mod check same letters
if (minwordBoxIndex > 5) and (wordBox[temp1 + minwordBoxIndex - 6].bgcolor == 0x6AAA64) and (color[temp1] == 0x787C7E) then
color[temp1] = 0xFFFFFF
hardModeGreen = temp1
elseif (minwordBoxIndex > 5) and (wordBox[temp1 + minwordBoxIndex - 6].bgcolor == 0xC9B458) and (color[temp1] == 0x787C7E) then
if #repeats(guess, wordBox[temp1 + minwordBoxIndex - 6].text) < 1 then
color[temp1] = 0xFFFFFF
hardModeYellow = temp1
end
end
end
if temp1 == 5 then -- settings color of guess and show
if (hardModeGreen == 0) and (hardModeYellow == 0) then
for j=1, 5 do
animation_All_Directions(j + minwordBoxIndex - 1)
wordBox[j + minwordBoxIndex - 1].fgcolor = 0xFFFFFF -- White
wordBox[j + minwordBoxIndex - 1].bgcolor = color[j]
ui.update(80)
end
end
end
end
if (guess ~= computerWord) and entryIndex > 29 then
msgLabel.visible = true
msgLabel.x = 175
msgLabel.y = 105
msgLabel.text = " Word= "..computerWord
entryIndex = 32
end
if not (hardModeGreen > 0 or hardModeYellow > 0) then -- Keyboard renklerini aciyoruz
for i= minwordBoxIndex, maxwordBoxIndex do
for j=1, #keyboard do
if keyboard[j].text == wordBox[i].text then
keyboard[j].bgcolor = wordBox[i].bgcolor
end
end
end
minwordBoxIndex = minwordBoxIndex + 5
maxwordBoxIndex = maxwordBoxIndex + 5
end
if minwordBoxIndex > 5 then
checkboxLevel.enabled = false
labelLevel.enabled = false
end
else
msgLabel.visible = true
msgLabel.text = "Not in word list"
animation_Left_Right(minwordBoxIndex)
ui.update(600)
msgLabel.visible = false
end
if guess == computerWord then
msgLabel.visible = true
entryIndex = 32
if minwordBoxIndex == 6 then
msgLabel.text = " GENIUS !!"
elseif minwordBoxIndex == 11 then
msgLabel.text = " Magnificent "
elseif minwordBoxIndex == 16 then
msgLabel.text = " Impressive "
elseif minwordBoxIndex == 21 then
msgLabel.text = " Splendid "
elseif minwordBoxIndex == 26 then
msgLabel.text = " Great"
elseif minwordBoxIndex == 31 then
msgLabel.text = " Phew"
end
end
else
msgLabel.visible = true
msgLabel.text = "Not enough letter"
animation_Left_Right(minwordBoxIndex)
ui.update(600)
msgLabel.visible = false
end
if hardModeGreen > 0 then
msgLabel.visible = true
msgLabel.x = 170
msgLabel.y = 105
msgLabel.text = tostring(hardModeGreen).."st letter must be "..wordBox[hardModeGreen + minwordBoxIndex-6].text
animation_Left_Right(minwordBoxIndex)
ui.update(600)
msgLabel.visible = false
elseif hardModeYellow > 0 then
msgLabel.visible = true
msgLabel.x = 160
msgLabel.y = 105
msgLabel.text = "Guess must contain "..wordBox[hardModeYellow + minwordBoxIndex - 6].text
animation_Left_Right(minwordBoxIndex)
ui.update(600)
msgLabel.visible = false
end
elseif entryIndex < maxwordBoxIndex + 1 then
wordBox[entryIndex].text= self.text
entryIndex = entryIndex + 1
end
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
function repeats(_guess, _letter)
local temp1 = 0
local tableRepeat ={}
for _char in each(_guess) do
temp1 = temp1 + 1
if _letter == _char then
table.insert(tableRepeat, temp1)
end
end
return tableRepeat
end
function editColor(_repaitsGuess, _repaitsComputerWord, _color)
for i=1, #_repaitsGuess do
_color[_repaitsGuess[i]] = 0xC9B458 --Yellow
for j = 1, #_repaitsComputerWord do
if _repaitsGuess[i] == _repaitsComputerWord[j] then
_color[_repaitsGuess[i]] = 0x6AAA64 --Green
end
end
end
local temp = #_repaitsGuess - #_repaitsComputerWord
for i = 1, #_repaitsGuess do
if _color[_repaitsGuess[i]] == 0xC9B458 and (temp > 0) then --Yellow
_color[_repaitsGuess[i]] = 0x787C7E --Dark Grey
temp = temp - 1
end
if temp < 1 then
break
end
end
return _color
end
function checkboxDark:onClick()
if self.checked == true then
win.bgcolor = 0x222020
winSettings.bgcolor = 0x222020
winHelp.bgcolor = 0x222020
labelLevel.fgcolor = 0xFFFFFF
labelDark.fgcolor = 0xFFFFFF
pictureLoad:load("Data\\HelpDark.png")
pictureLuaRT:load("Data\\LuaRTBlack.png")
msgLabelHardMode.fgcolor = 0xFFF52F
else
win.bgcolor = 0xFFFFFF
winSettings.bgcolor = 0xFFFFFF
winHelp.bgcolor = 0xFFFFFF
labelLevel.fgcolor = 0x222020
labelDark.fgcolor = 0x222020
pictureLoad:load("Data\\Help.png")
pictureLuaRT:load("Data\\LuaRTWhite.png")
msgLabelHardMode.fgcolor = 0x004080
end
end
checkboxDark:onClick()
function checkboxLevel:onClick()
if self.checked == true then
msgLabelHardMode.text = "** Hard Mode **"
else
msgLabelHardMode.text = ""
end
end
function labelLevel:onHover(x,y)
self.tooltip = "Hard Mode can only be changed at startup."
end
function httpLabel:onClick()
sys.cmd('start "" "https://www.luart.org" ')
end
function pictureHelp:onClick()
win:showmodal(winHelp)
end
function pictureSettings:onClick()
win:showmodal(winSettings)
end
function buttonGithub:onClick()
sys.cmd('start "" "https://github.com/samyeyo ')
end
function buttonTwitter:onClick()
sys.cmd('start "" "https://twitter.com/__LuaRT__ ')
end
function buttonYoutube:onClick()
sys.cmd('start "" "https://www.youtube.com/channel/UCS4DTQ3-6xKmkVrFr8Xxc7Q')
end
function animation_All_Directions(_i)
local temp1 = -3
local temp2 = -1
for i= 1, 4 do
if i==1 or i==3 then
temp1 = -3
temp2 = -1
else
temp1 = 3
temp2 = 1
end
wordBox[_i].x = wordBox[_i].x + temp1
wordBox[_i].y = wordBox[_i].y + temp2
ui.update(60)
end
end
function animation_Left_Right(_minwordBoxIndex)
local temp = -5
for i= 1, 12 do
if i==1 or i==3 or i==5 or i==7 or i==9 or i==11 then
temp = -3
else
temp = 3
end
wordBox[_minwordBoxIndex].x = wordBox[_minwordBoxIndex].x + temp
wordBox[_minwordBoxIndex + 1].x = wordBox[_minwordBoxIndex + 1].x + temp
wordBox[_minwordBoxIndex + 2].x = wordBox[_minwordBoxIndex + 2].x + temp
wordBox[_minwordBoxIndex + 3].x = wordBox[_minwordBoxIndex + 3].x + temp
wordBox[_minwordBoxIndex + 4].x = wordBox[_minwordBoxIndex + 4].x + temp
ui.update(20)
end
end
repeat
ui.update()
until not win.visible