Hi all.
I'm publishing a new simple game. It's actually a game that everyone plays in elementary school years. he is Hangman. Of course I changed it a little. Tomm is trying to catch Jerry. If you know the word in the computer's memory in 6 guesses, Tom will not be able to catch Jerry. Its description is in the Help section when you run the game.
SETUP
Create a "imga" 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.
[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]
[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]
-- HangMan for LuaRT
-- There are 47000 words in the database between 4 and 12 digits
-- (including the 4th and 12th digits)
-------------------------------------------------------------------
local file = sys.File("img\\word50724")
file:open("read")
local ui = require "ui"
local win = ui.Window("Find My Word Beta V 1.0","single", 600, 650)
local winHelp = ui.Window("","single", 403, 475)
win.bgcolor = 0xFFFFFF -- White
win:center()
win:show()
winHelp:center()
local pictureHelp = ui.Picture(win, "img\\help-24.ico", 530,15)
local pictureLuaRT = ui.Picture(win, "img\\LuaRT.png", 10,1)
local pictureHangManLoad = ui.Picture(win, "img\\a.png",2,50)
local pictureLoad = ui.Picture(winHelp, "img\\Help.png")
local buttonWeb = ui.Button(win, "www.luart.org", 150, 15)
local buttonGithub = ui.Button(win, "Github", 245, 15 )
local buttonTwitter = ui.Button(win, "Twitter", 315, 15)
local buttonYoutube = ui.Button(win, "Youtube", 385, 15)
buttonGithub:loadicon("img\\Github.ico")
buttonTwitter:loadicon("img\\Twitter.ico")
buttonYoutube:loadicon("img\\Youtube.ico")
win:status("Copyright © 2023 Coskun .. coded with LuaRT")
function findWord()
local wordLine= math.random(1,50724)
local count = 0
for word in file.lines do
count = count + 1
if count == wordLine then
word = word:sub(1, #word - 1) -- A space is added to the line read in file() jobs. we remove it
return word:upper() -- is converted to uppercase.
end
end
end
local computerWord = findWord()
local keyboard= {}
local wordBox= {}
local keyword={"Q","W","E","R","T","Y","U","I","O","P",
"A","S","D","F","G","H","J","K","L",
"Z","X","C","V","B","N","M"}
local keyboard_Y = 440
local wordBox_Y = 0
local wordBox_X = 0
local entry = 1
local level = 6 -- hard=4 , easy=9
local function letter_onClick(self)
local guess = ""
if entry == 1 then -- picture load
pictureHangManLoad:load("img\\b.png")
elseif entry == 2 then
pictureHangManLoad:load("img\\c.png")
elseif entry == 3 then
pictureHangManLoad:load("img\\d.png")
elseif entry == 4 then
pictureHangManLoad:load("img\\e.png")
elseif entry == 5 then
pictureHangManLoad:load("img\\f.png")
elseif entry == 6 then
pictureHangManLoad:load("img\\g.png")
end
if entry < level then -- if clicked key index less then max level time
findWord(self)
self.enabled = false
for i=1, #wordBox do
guess = guess..wordBox[i].text
end
if guess == computerWord then
pictureHangManLoad:load("img\\perfect.png")
animation_All_Directions()
keyboardDisabled()
end
else
keyboardDisabled()
end
end
for i=1,string.len(computerWord) do -- WordBox[]
if i==1 then
wordBox_Y= wordBox_Y + 425
wordBox[i] = ui.Label(win, "",70, wordBox_Y,30,30)
else
wordBox[i] = ui.Label(win, "",wordBox[i-1].x+35, wordBox[i-1].y,30,30)
end
wordBox[i].text="-"
wordBox[i].fontsize = 24
wordBox[i].textalign = "center"
wordBox[i].bgcolor = 0xFFFFFF -- white
end
for i=1, 26 do -- Keyboard[]
if i == 1 then
keyboard_Y = keyboard_Y + 45
label = ui.Label(win, keyword[i], 75, keyboard_Y, 40, 30)
elseif i == 11 then
keyboard_Y = keyboard_Y + 45
label = ui.Label(win, keyword[i], 95, keyboard_Y, 40, 30)
elseif i == 20 then
keyboard_Y = keyboard_Y + 45
label = ui.Label(win, keyword[i], 140, keyboard_Y, 40, 30)
else
label = ui.Label(win, keyword[i], keyboard[i-1].x + 45, keyboard[i-1].y, 40, 30)
end
label.onClick = letter_onClick
keyboard[#keyboard+1] = label
keyboard[i].textalign = "center"
keyboard[i].bgcolor = 0x99CCFF
keyboard[i].fontsize = 20
end
function findWord(_self)
local count = 0
local temp = false
for letter in each(computerWord) do
count = count + 1
if _self.text == letter then
wordBox[count].text = letter
animation_Left_Right(_self)
temp = true
end
end
if temp == false then
entry = entry + 1
end
end
function keyboardDisabled()
for j = 1, #keyboard do
keyboard[j].enabled = false
end
end
function buttonWeb:onClick()
sys.cmd('start "" "https://www.luart.org" ')
end
function pictureHelp:onClick()
win:showmodal(winHelp)
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()
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
for i=1, #wordBox do
wordBox[i].x = wordBox[i].x + temp1
wordBox[i].y = wordBox[i].y + temp2
ui.update(20)
end
end
end
function animation_Left_Right(_keyBox)
local temp = -5
for i= 1, 10 do
if i==1 or i==3 or i==5 or i==7 or i==9 then
temp = -3
else
temp = 3
end
_keyBox.x = _keyBox.x + temp
ui.update(20)
end
end
repeat
ui.update()
until not win.visible