--[[ -------------------------- -- Nonograms for Nspire -- -------------------------- CONTROLS: TAB - starts a new level, randomly chosen ENTER - marks a cell BACKSPACE - crosses out a cell CONTEXT MENU - opens the context menu ESC - closes the context menu c - checks the puzzle to see if is solved correctly or not h - hint r - resets the puzzle s - solves the puzzle ;) --]] -- ------- -- -- GLOBALS -- -- ------- -- xx = 15 -- # of columns yy = 15 -- # of files cSize = 9 -- size of the cells, in pixels offsetX = 120 -- Offset in X of everything, to easily move them from here offsetY = 70 -- Offset in Y of everything, to easily move them from here wwidth = 318 --platform.window:width() -- window's width wheight = 212 --platform.window:height() -- window's height CellOption = {empty=0, fill=1, cross=2, dot=3} MenuOption = { [1] = "Check \t c ", [2] = "Restart \t r ", [3] = "New \t tab ", [4] = "Pick \t p ", [5] = "Hint \t h ", [6] = "Solve \t s " } menu={ {"Nonograms", {MenuOption[1], function() on.charIn("c") end}, {MenuOption[2], function() on.charIn("r") end}, {MenuOption[3], function() on.tabKey() end}, {MenuOption[4], function() on.charIn("p") end}, {MenuOption[5], function() on.charIn("h") end}, {MenuOption[6], function() on.charIn("s") end}, } } toolpalette.register(menu) CheckWrong = "Sorry, incorrect." Description = { [1] = "It's a floppy disk!", [2] = "It's a football helmet!", [3] = "It's a palace!", [4] = "It's a clock!", [5] = "It's a lock and key!", [6] = "It's a camel jockey!", [7] = "It's Elvis!", [8] = "It's Africa!", [9] = "It's Tetris!", [10]= "It's a fish!", [11]= "It's a butterfly!", [12]= "It's the sun!", [13]= "It's a skunk!", [14]= "It's a mouse!", [15]= "It's a cementery!", [16]= "It's a lizard!", [17]= "It's an ape!", [18]= "It's a fisherman!", [19]= "It's a microscope!", [20]= "It's a strawberry!", [21]= "It's a fossil!", [22]= "It's a cockroach!", [23]= "It's a hot-air ballon!", [24]= "It's a goddamn furry!", [25]= "It's a baseball player!", [26]= "It's an old man!", [27]= "It's a faucet!", [28]= "It's a tadpole!", [29]= "It's Captain Tragedy!", [30]= "It's a deer!", [31]= "It's laughting online!", [32]= "It's a trophy!" } win = -1 mx = 1 my = 1 menu = false menm = 1 num = 1 puz = {} puzz = {} clues = {} clue_X = {} clue_Y = {} answer = {} -------------------------------------------------------------------------------- function create_puzzle() -------------------------------------------------------------------------------- -- Clues are set from inside out (down to up & right to left) puzz[1]={ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,0, -- [][][][][][][][][][][][][][]__ 1,0,0,1,1,1,1,1,1,1,1,1,0,0,1, -- []____[][][][][][][][][]____[] 1,0,0,1,1,1,1,1,0,0,1,1,0,0,1, -- []____[][][][][]____[][]____[] 1,0,0,1,1,1,1,1,0,0,1,1,0,0,1, -- []____[][][][][]____[][]____[] 1,0,0,1,1,1,1,1,0,0,1,1,0,0,1, -- []____[][][][][]____[][]____[] 1,0,0,1,1,1,1,1,1,1,1,1,0,0,1, -- []____[][][][][][][][][]____[] 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, -- []__________________________[] 1,0,1,1,1,1,1,1,1,1,1,1,1,0,1, -- []__[][][][][][][][][][][]__[] 1,0,1,0,0,0,0,0,0,0,0,0,1,0,1, -- []__[]__________________[]__[] 1,0,1,0,1,1,1,1,1,1,1,0,1,0,1, -- []__[]__[][][][][][][]__[]__[] 1,0,1,0,0,0,0,0,0,0,0,0,1,0,1, -- []__[]__________________[]__[] 1,0,1,0,1,1,1,1,1,1,1,0,1,0,1, -- []__[]__[][][][][][][]__[]__[] 1,0,1,0,0,0,0,0,0,0,0,0,1,0,1, -- []__[]__________________[]__[] 1,0,1,0,0,0,0,0,0,0,0,0,1,0,1, -- []__[]__________________[]__[] 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 } -- [][][][][][][][][][][][][][][] --clue_X[1]={{15}, {1,1}, {8,1}, {1,1,6}, {1,1,1,1,6}, {1,1,1,1,6}, {1,1,1,1,6}, {1,1,1,1,6}, {1,1,1,1,1,2}, {1,1,1,1,1,2}, {1,1,1,1,6}, {1,1,6}, {8,1}, {1,1}, {14}} --clue_Y[1]={{14}, {1,9,1}, {1,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0,0,1,1,1,0,0,1,1,0,1, 1,1,1,1,0,0,1,1,0,0,1,1,0,0,0, 1,1,1,1,1,0,0,0,0,1,1,0,0,0,1, 1,1,1,1,1,1,0,0,1,1,0,0,0,1,1, 1,1,1,1,1,1,1,1,1,0,0,0,1,1,1, 1,1,1,1,1,1,1,1,1,1,0,0,0,1,1, 1,1,1,1,1,1,1,1,1,1,1,0,0,0,1 } populate_clues(31) puzz[32]={ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,1,1,1,1,1,1,1,1,1,1,0,1,0, 1,1,0,1,1,1,1,1,1,1,1,1,1,0,1, 1,0,0,1,0,0,1,1,1,1,1,1,0,0,1, 1,1,0,0,1,0,1,1,1,1,1,0,0,0,1, 0,1,1,1,1,0,1,1,1,1,1,0,1,1,1, 0,0,0,0,1,0,1,1,1,1,1,1,0,0,0, 0,0,0,0,1,0,1,1,1,1,1,0,0,0,0, 0,0,0,1,1,0,1,1,1,1,1,1,1,0,0, 0,0,0,0,1,1,0,1,1,1,1,0,0,0,0, 0,0,0,0,0,1,1,1,1,1,0,0,0,0,0, 0,0,0,0,0,0,0,1,1,0,0,0,0,0,0, 0,0,0,0,0,0,1,1,1,1,0,0,0,0,0, 0,0,0,0,0,0,1,1,1,1,0,0,0,0,0, 0,0,0,0,0,1,1,1,1,1,1,0,0,0,0 } populate_clues(32) -- Populate puz[] for i=1,#puzz do puz[i] = puzz[i] end -- Populate clues[] for i=1, #clue_X do clues[i] = {clue_X[i],clue_Y[i]} end -- Check if the # of puzzles matches the # of clues if (#puz ~= #clues) then assert(false) end end -------------------------------------------------------------------------------- function populate_clues(puzzle) -------------------------------------------------------------------------------- clue_X[puzzle]={} clue_Y[puzzle]={} for i=1,xx do clue_X[puzzle][i] = {} end for i=1,yy do clue_Y[puzzle][i] = {} end -- Populate the clues in X for i=1, xx do pos = 1 counter = 0 for j=yy, 1, -1 do if puzz[puzzle][xx*(j-1)+i] == 1 then counter = counter + 1 else counter = 0 end if counter ~= 0 then clue_X[puzzle][i][pos] = counter else if clue_X[puzzle][i][pos] ~= nil then pos = pos + 1 end end end end -- Populate the clues in Y for i=1, yy do pos = 1 counter = 0 for j=xx, 1, -1 do if puzz[puzzle][yy*(i-1)+j] == 1 then counter = counter + 1 else counter = 0 end if counter ~= 0 then clue_Y[puzzle][i][pos] = counter else if clue_Y[puzzle][i][pos] ~= nil then pos = pos + 1 end end end end end -------------------------------------------------------------------------------- function check_grid(coord_X, coord_Y) -------------------------------------------------------------------------------- ----Checks if solution is correct for i=1, (coord_X*coord_Y) do if puzz[num][i] == 1 and answer[i] ~= CellOption.fill or puzz[num][i] == 0 and answer[i] == CellOption.fill then return 0 end end return 1 end -------------------------------------------------------------------------------- function solve_grid(coord_X, coord_Y) -------------------------------------------------------------------------------- for i=1, (coord_X*coord_Y) do answer[i] = puz[num][i] end end -------------------------------------------------------------------------------- function clear_grid(coord_X, coord_Y) -------------------------------------------------------------------------------- for i=1, (coord_X*coord_Y) do answer[i] = 0 end end -------------------------------------------------------------------------------- function clean_grid(coord_X, coord_Y) -------------------------------------------------------------------------------- for i=1, (coord_X*coord_Y) do if answer[i] == 2 then answer[i] = 0 end end end create_puzzle() clear_grid(xx,yy) -------------------------------------------------------------------------------- function on.paint(gc) -------------------------------------------------------------------------------- paint_cells(gc) paint_cell_clues(gc) paint_pointer(gc) gc:setFont("serif","b",24) if win==1 then local twidth = gc:getStringWidth(Description[num]) local theight = gc:getStringHeight(Description[num]) clean_grid(xx,yy) gc:setColorRGB(248,255,255) gc:fillRect((wwidth-twidth)/2, 14, twidth, theight) gc:setColorRGB(0,255,0) gc:drawString(Description[num], (wwidth-twidth)/2, 10,"top") timer.start(2) elseif win==0 then local twidth = gc:getStringWidth(CheckWrong) local theight = gc:getStringHeight(CheckWrong) gc:setColorRGB(255,0,0) gc:drawString(CheckWrong, (wwidth-twidth)/2 , 10,"top") timer.start(2) end if hint==1 then local twidth = gc:getStringWidth(Description[num]) local theight = gc:getStringHeight(Description[num]) gc:setColorRGB(248,255,255) gc:fillRect((wwidth-twidth)/2, 14, twidth, theight) gc:setColorRGB(0,255,0) gc:drawString(Description[num], (wwidth-twidth)/2, 10,"top") timer.start(2) hint=0 end -- Paint puzzle # gc:setColorRGB(120,120,120) gc:drawString('#' .. num, (wwidth-gc:getStringWidth(num)-gc:getStringWidth('#') ), wheight) paint_ctr_menu(gc) end -------------------------------------------------------------------------------- function paint_cells(gc) -------------------------------------------------------------------------------- for a=0,yy-1 do for b=1,xx do local m=answer[yy*(a)+b] ----draws answer grid if m==CellOption.empty then -- Empty gc:setColorRGB(255,255,255) gc:fillRect(cSize*(b-1)+offsetX,cSize*(a)+offsetY,cSize,cSize) gc:setColorRGB(0,0,255) gc:drawRect(cSize*(b-1)+offsetX,cSize*(a)+offsetY,cSize,cSize) elseif m==CellOption.fill then -- Fill gc:setColorRGB(0,0,255) gc:drawRect(cSize*(b-1)+offsetX,cSize*(a)+offsetY,cSize,cSize) gc:setColorRGB(0,128,255) gc:fillRect(cSize*(b-1)+offsetX+2,cSize*(a)+offsetY+2,(cSize-3),(cSize-3)) elseif m==CellOption.cross then -- Cross gc:setColorRGB(0,0,255) gc:drawRect(cSize*(b-1)+offsetX,cSize*(a)+offsetY,cSize,cSize) gc:setColorRGB(255,0,0) gc:drawLine(cSize*(b-2/3)+offsetX, cSize*(a+1/3)+offsetY, cSize*(b-1/3)+offsetX, cSize*(a+2/3)+offsetY) gc:drawLine(cSize*(b-2/3)+offsetX, cSize*(a+2/3)+offsetY, cSize*(b-1/3)+offsetX, cSize*(a+1/3)+offsetY) elseif m==CellOption.dot then -- dot gc:setColorRGB(0,0,255) gc:drawRect(cSize*(b-1)+offsetX,cSize*(a)+offsetY,cSize,cSize) gc:setColorRGB(0,255,0) gc:fillArc(cSize*(b-2/3)+offsetX, cSize*(a+1/3)+offsetY, cSize/2, cSize/2, 0, 360) end end end end -------------------------------------------------------------------------------- function paint_cell_clues(gc) -------------------------------------------------------------------------------- gc:setColorRGB(0,0,0) gc:setFont("serif","r",6) for v=1,xx do ----draws vertical clues for i,p in pairs(clues[num][1][v]) do gc:drawString(p, cSize*(v-1)+offsetX+2, offsetY-12*(i), "top") end end for h=1,yy do ----draws horizontal clues for i,p in pairs(clues[num][2][h]) do gc:drawString(p, offsetX-17*(i), cSize*(h-1)+offsetY-3, "top") end end end -------------------------------------------------------------------------------- function paint_pointer(gc) -------------------------------------------------------------------------------- ---- draws indicator gc:setColorRGB(180,0,0) gc:fillPolygon({(mx-1)*cSize+offsetX+1, (my-1)*cSize+offsetY+1, (mx-1)*cSize+offsetX+cSize-1, (my-1)*cSize+offsetY+1, (mx-1)*cSize+offsetX+(cSize/2), (my-1)*cSize+offsetY+(cSize/2), (mx-1)*cSize+offsetX+1, (my-1)*cSize+offsetY+1}) gc:setColorRGB(224,224,224) gc:drawLine((mx-0.5)*cSize+offsetX-1, 0, (mx-0.5)*cSize+offsetX-1, offsetY) gc:drawLine(0 , (my-0.5)*cSize+offsetY, offsetX, (my-0.5)*cSize+offsetY) end -------------------------------------------------------------------------------- function paint_ctr_menu(gc) -------------------------------------------------------------------------------- if menu then gc:setFont("serif","r",8) local height = gc:getStringHeight(MenuOption[1]) local gap = (height/2)+4 local width = gc:getStringWidth(MenuOption[1]) + gap ----draws menu gc:setColorRGB(170,204,204) gc:fillRect(0,0,width,(#MenuOption)*height) gc:setColorRGB(0,0,0) for i=1,(#MenuOption) do gc:drawRect(0,height*(i-1),width,height) end gc:setFont("serif","r",8) for i=1,(#MenuOption) do gc:drawString(MenuOption[i], gap, (i-1)*height, "top") end ----draws pointer gc:fillPolygon({ 0, (menm-1)*height, height/2, (menm-1)*height + height/2, 0, (menm)*height}) end end -------------------------------------------------------------------------------- function on.charIn(ch) -------------------------------------------------------------------------------- menu=false if ch=="c" then win = check_grid(xx,yy) elseif ch=="h" then hint=1 elseif ch=="s" then solve_grid(xx,yy) elseif ch=="r" then clear_grid(xx,yy) elseif ch=="p" then clear_grid(xx,yy) num = (num % #puz) +1 elseif ch=="1" then on.arrowKey("down") on.arrowKey("left") elseif ch=="2" then on.arrowKey("down") elseif ch=="3" then on.arrowKey("down") on.arrowKey("right") elseif ch=="4" then on.arrowKey("left") elseif ch=="5" then --on.enterKey() elseif ch=="6" then on.arrowKey("right") elseif ch=="7" then on.arrowKey("left") on.arrowKey("up") elseif ch=="8" then on.arrowKey("up") elseif ch=="9" then on.arrowKey("right") on.arrowKey("up") elseif ch=="0" then on.enterKey() elseif ch=="." then on.backspaceKey() elseif ch=="-" then on.returnKey() end platform.window:invalidate() end -------------------------------------------------------------------------------- function on.arrowKey(key) -------------------------------------------------------------------------------- ----allows controling of the pointer, in and out of menu if key=="right" then if not menu then if mx1 then mx=mx-1 else mx=xx end end elseif key=="up" then if menu then if menm>1 then menm=menm-1 else menm=#MenuOption end else if my>1 then my=my-1 else my=yy end end end platform.window:invalidate() end -------------------------------------------------------------------------------- function on.tabKey() -------------------------------------------------------------------------------- ----Starts new level, randomly chosen clear_grid(xx,yy) num = math.random(#puz) -- Total number of puzzles end -------------------------------------------------------------------------------- function on.enterKey() -------------------------------------------------------------------------------- if menu then ----Select Menu Items if menm==1 then on.charIn("c") elseif menm==2 then on.charIn("r") elseif menm==3 then on.tabKey() elseif menm==4 then on.charIn("h") elseif menm==5 then on.charIn("s") end menu=false else ----Fill in/Clear Cells local cell = yy*(my-1)+mx if answer[cell] == CellOption.fill then answer[cell] = CellOption.empty else answer[cell] = CellOption.fill end end platform.window:invalidate() end -------------------------------------------------------------------------------- function on.backspaceKey() -------------------------------------------------------------------------------- if not menu then ----Marks/Unmarks Cell with X local cell = yy*(my-1)+mx if answer[cell] == CellOption.cross then answer[cell] = CellOption.empty elseif answer[cell] == CellOption.empty or answer[cell] == CellOption.dot then answer[cell] = CellOption.cross end platform.window:invalidate() end end -------------------------------------------------------------------------------- function on.returnKey() -------------------------------------------------------------------------------- if not menu then --Marks/Unmarks Cell with * local cell = yy*(my-1)+mx if answer[cell] == CellOption.dot then answer[cell] = CellOption.empty elseif answer[cell] == CellOption.empty then answer[cell] = CellOption.dot end platform.window:invalidate() end end -------------------------------------------------------------------------------- function on.escapeKey() -------------------------------------------------------------------------------- ----Closes menu menu=false end -------------------------------------------------------------------------------- function on.contextMenu() -------------------------------------------------------------------------------- ----Opens menu menu=true platform.window:invalidate() menm=1 end -------------------------------------------------------------------------------- function on.timer() -------------------------------------------------------------------------------- ----When the timer ticks, the timer is stopped, the message is removed, and the screen is refreshed timer.stop() win = -1 platform.window:invalidate() end