I don’t play games, but I try to code parts of them just for something to do. So here’s a start to some word game that’s going around. It’s up to you to create a larger wordTab of 5 letter words. Use the parameter sliders to change the size and position of the board to fit your device. Once you get it set, you can enter those values into the parameter default so you don’t have to do it again. Just start entering letters. A green background means that letter is in the right position. A yellow background means the letter is somewhere in the word. There’s no kind of edits, so things might go wrong. There’s also no ending code when you run out of spaces or match the word. When you start, a random word is picked from the table for you to match.
Edit: Made some changes. Colors don’t update until a line is filled in.
viewer.mode=OVERLAY
function setup()
parameter.integer("size",20,100,85)
parameter.integer("xOffset",50,700,200)
parameter.integer("yOffset",50,700,400)
wordTab={"wrong","seven","right","bring","chase","angle","break","great"}
word=wordTab[math.random(#wordTab)]
rectMode(CENTER)
tab={}
for x=1,5 do
tab[x]={}
for y=1,6 do
tab[x][y]=""
end
end
strokeWidth(4)
showKeyboard()
xPos,yPos=1,6
lineNbr=7
end
function draw()
background()
fontSize(size*.7)
for x=1,5 do
for y=6,1,-1 do
fill(180)
checkLetters(x,y)
rect(x*size+xOffset,y*size+yOffset,size)
fill(255,0,0)
text(string.upper(tab[x][y]),x*size+xOffset,y*size+yOffset)
end
end
end
function checkLetters(x,y)
if y>=lineNbr then
if atPosition(tab[x][y],x) then
fill(0,255,0)
elseif inWord(tab[x][y]) then
fill(255,255,0)
end
end
end
function inWord(letter)
if letter~="" and string.find(word,letter)~=nil then
return true
end
return false
end
function atPosition(letter,pos)
if letter~="" and letter==string.sub(word,pos,pos) then
return true
end
return false
end
function keyboard(key)
tab[xPos][yPos]=key
xPos=xPos+1
if xPos>5 then
lineNbr=yPos
xPos=1
if yPos>0 then
yPos=yPos-1
end
end
end