--Hangman v1.2 math.randomseed(timer.getMilliSecCounter()) a = 400 words = {} words[1] = {"Animals I","Cow","Chicken","Bird","Cat","Dog","Duck","Goose","Lion","Tiger","Horse","Snake","Mouse","Bear"} words[2] = {"Elements I","Hydrogen","Helium","Iron","Carbon","Gold","Silver","Nickel","Copper","Platinum","Nitrogen","Oxygen","Neon","Sodium"} words[3] = {"Food I", "Apple","Orange","Grapes","Eggs","Bread","Bagel","Donut","Cracker","Lettuce","Beef","Rice","Banana","Lemon","Pineapple"} words[4] = {"Boy Name","Robert","James","Zachary","Christopher","Johnathon","Kevin","William","Matthew","George","Harrison","Samuel","Alex","Edward","Dennis"} words[5] = {"Girl Name","Melinda","Sarah","Lydia","Leah","Sabrina","Chelsea","Annie","Christine","Megan","Lauren","Cynthia","Dorothy","Alice"} words[6] = {"Colors I","Red","Orange","Yellow","Green","Purple","Violet","Blue","Black","White","Gray","Pink"} words[7] = {"Tricky","Zygote","Rhythm","Ennui","Denim","Lynx","Fjord","Loquacious","Syzygy","Cwm","Khaki","cyanophycean","taciturn"} words[8] = {"Planets","Mercury","Venus","Earth","Mars","Saturn","Jupiter","Uranus","Neptune","Pluto"} words[9] = {"Famous People","Albert Einstein","Isaac Newton","Ludwig Beethoven","Michael Jackson","Justin Bieber","George Washington","Leo Tolstoy"} words[10] = {"Colors II","Cyan","Turquoise","Crimson","Magenta","Indigo","Maroon","Teal","Amber","Beige","Azure"} words[11] = {"Books","Moby Dick","War and Peace","Harry Potter","War of the Worlds","Gullivers Travels","Wizard of Oz","A Christmas Carol"} words[12] = {"Video Games","Halo","Call of Duty","Mario","Kirby","Legend of Zelda","Metroid","Uncharted","Wii","Skyrim","Minecraft","Starcraft"} words[13] = {"Elements II","Polonium","Lithium","Zinc","Phoshporous","Xenon","Hafnium","Silicon","Uranium","Indium","Einsteinium","Argon","Mercury","Cesium","Arsenic"} words[14] = {"Countries","USA","France","Canada","Belgium","United Kingdom","Russia","China","Mexico","Thailand","Egypt","Iraq","Brazil","Australia"} words[15] = {"Transportation","Bike","Car","Bus","Airplane","Subway","Pedestrian","Train","Motorcycle","Blimp","Trolley","Truck"} words[16] = {"Animals II","Giraffe","Parrot","Raccoon","Anaconda","Tarantula","Lobster","Hummingbird","Penguin"} words[17] = {"Food II","Tortilla","Salad","Spaghetti","Dumpling","Sandwich","Hamburger","Omelet","Lasagna","Cauliflower"} words[18] = {"Math","Addition","Subtraction","Multiplication","Division","Exponentials","Logarithms","Calculus","Algebra","Geometry","Trigonometry","Calculator"} words[19] = {"Drinks","Juice","Water","Coffee","Tea","Beer","Wine","Soda","Lemonade","Coca Cola","Milk"} textc = class() mode = 1 input = "" difficulty = 2 wordchosen = false function textc:init(xpos, ypos, value, numpos) self.x = xpos self.y = ypos self.text = value self.num = numpos end function on.paint(gc) gc:setColorRGB(0,0,0) gc:setFont("serif","r",12) --Game if mode == 2 then if not init then generateword() generateother() end gc:setFont("serif","b",15) gc:drawString(wintext.text,wintext.x,wintext.y) gc:drawString(dietext.text,dietext.x,dietext.y) gc:setFont("serif","r",12) for i,let in ipairs(blanks) do if i == 1 then gc:drawString(let,10,50) else gc:drawString(let,11*i+1,50) end end gc:drawString("Trash: "..trash,10,100) gc:drawString(category,20,20) gc:drawString("Lives: "..lives,150,20) gc:fillRect(270,180,30,5) gc:fillRect(290,30,3,150) gc:fillRect(255,30,35,3) --Drawing Hangman drawHangman(gc,lives) end --Menu if mode == 1 then if not init2 then selector = textc(25, 65, 1) difficulty = textc(a,a,"Everything",2) end gc:setColorRGB(0,0,0) gc:setFont("sansserif","r",12) gc:drawString("HANGMAN",30,30,"top") gc:setFont("serif","r",10) gc:drawString("Play",40,60,"top") gc:drawString("2 Player",40,75,"top") gc:drawString("About",40,90,"top") gc:drawString("Instructions",40,105,"top") gc:fillRect(selector.x,selector.y,10,10) if selector.text == 1 then shift(difficulty,120,60) gc:drawString(difficulty.text,difficulty.x,difficulty.y,"top") gc:fillPolygon({115,64,115,76,110,70,115,64}) gc:fillPolygon({185,64,185,76,190,70,185,64}) end drawHangman(gc,0) end --About Mode if mode == 4 then gc:drawString("Programmed by: cyanophycean314",30,20) gc:drawString("Sprites by: cyanophycean314",30,35) gc:drawString("Thanks to Omnimaga and Inspired-Lua!",30,80) end --Instructions if mode == 5 then gc:drawString("Press letters on the keypad to play",30,40) gc:drawString("Guess the word within 6 tries",30,57) gc:drawString("The word is in the category stated",30,74) gc:drawString("In two player, one person picks the word,",30,91) gc:drawString(" the other will try and guess.",30,108) gc:drawString("Letters - Guess letters",30,130) gc:drawString("Tab - New Puzzle",30,145) gc:drawString("Esc - Return to Menu",30,160) gc:drawString("Enter - Retry word",30,175) gc:setFont("sansserif","b",12) gc:drawString("HANGMAN",20,17) end --2 Player if mode == 3 then if wordchosen == false then gc:drawString("Please Choose a word, < 20 characters long",10,20) gc:drawString(">"..input,10,35) elseif wordchosen == true then if not init3 then wordsplit = split(customword) length = string.len(customword) generateother() end gc:setFont("serif","b",15) gc:drawString(wintext.text,wintext.x,wintext.y) gc:drawString(dietext.text,dietext.x,dietext.y) gc:setFont("serif","r",12) for i,let in ipairs(blanks) do if i == 1 then gc:drawString(let,10,50) else gc:drawString(let,11*i+1,50) end end gc:drawString("Trash: "..trash,10,100) gc:drawString("Custom",20,20) gc:drawString("Lives: "..lives,150,20) gc:fillRect(270,180,30,5) gc:fillRect(290,30,3,150) gc:fillRect(255,30,35,3) --Drawing Hangman drawHangman(gc,lives) end end gc:setFont("sansserif","r",8) gc:drawString("by cyanophycean314",3,210) end function on.charIn(key) if mode == 2 or (mode == 3 and wordchosen == true) then if not gameover and keyinlist(key, split("abcdefghijklmnopqrstuvwxyz")) then if not keyinlist(key, guessedlets) then inword = false for k, let2 in ipairs(wordsplit) do if key == string.lower(let2) then blanks[k] = let2 inword = true end end if inword == false then trash = trash..key.." " lives = lives - 1 if lives <= 0 then shift(dietext,50,150) gameover = true end end if inword == true then if keyinlist("_",blanks) == false then shift(wintext,50,150) gameover = true end end table.insert(guessedlets,key) end end if mode == 2 then init = true elseif mode == 3 then init3 = true end end if mode == 3 and wordchosen == false then if string.len(input) <= 19 then input = input..key end end platform.window:invalidate() end function on.arrowKey(dir) if mode == 1 then if dir == "up" then selector.y = selector.y - 15 selector.text = selector.text - 1 elseif dir == "down" then selector.y = selector.y + 15 selector.text = selector.text + 1 end if selector.text == 0 then selector.y = 110 selector.text = 4 elseif selector.text == 5 then selector.y = 65 selector.text = 1 end init2 = true if selector.text == 1 and (dir == "left" or dir == "right") then if dir == "left" then difficulty.num = difficulty.num - 1 elseif dir == "right" then difficulty.num = difficulty.num + 1 end if difficulty.num == 0 then difficulty.num = 3 elseif difficulty.num == 4 then difficulty.num = 1 end if difficulty.num == 1 then difficulty.text = "Easy" elseif difficulty.num == 2 then difficulty.text = "Everything" elseif difficulty.num == 3 then difficulty.text = "Tricky" end end end platform.window:invalidate() end function on.enterKey() --Menu if mode == 1 then mode = selector.text + 1 end if mode == 2 then if gameover == true then generateother() end end if mode == 3 and input ~= "" then wordchosen = true customword = input end platform.window:invalidate() end function on.backspaceKey() if mode == 3 and wordchosen == false then input = string.usub(input,0,string.len(input)-1) end platform.window:invalidate() end function on.escapeKey() if mode == 3 and wordchosen == true then wordchosen = false input = "" init3 = false else mode = 1 end platform.window:invalidate() end function generateword() if difficulty.num == 1 then wordcategory = words[math.random(6)] elseif difficulty.num == 3 then wordcategory = words[math.random(7,#words)] elseif difficulty.num == 2 then wordcategory = words[math.random(#words)] end category = wordcategory[1] word = wordcategory[math.random(2,#wordcategory)] wordsplit = split(word) length = string.len(word) end function generateother() blanks = {} trash = "" guessedlets = {} for i=1,length do if wordsplit[i] == " " then table.insert(blanks," ") else table.insert(blanks,"_") end end wintext = textc(a,a,"You have won") dietext = textc(a,a,"You have lost THE GAME") gameover = false lives = 6 end function on.tabKey() if mode == 2 then generateword() generateother() end platform.window:invalidate() end function keyinlist(key, list) for j, element in ipairs(list) do if key == element then return true end end return false end function split(str) strtabl = {} for j=1,string.len(str) do char = string.sub(str,j,j) table.insert(strtabl,char) end return strtabl end function shift(obj, newx, newy) obj.x, obj.y = newx, newy end function drawHangman(gc,asdf) gc:fillRect(270,180,30,5) gc:fillRect(290,30,3,150) gc:fillRect(255,30,35,3) if asdf < 6 then gc:drawLine(255,30,255,40) gc:drawArc(240,40,30,30,0,360) end if asdf < 5 then gc:drawLine(255,70,255,120) end if asdf < 4 then gc:drawLine(255,80,240,100) end if asdf < 3 then gc:drawLine(255,80,270,101) end if asdf < 2 then gc:drawLine(255,120,245,150) end if asdf < 1 then gc:drawLine(255,120,265,150) end end