0 Members and 2 Guests are viewing this topic.
function on.charIn(ch) if ch == "r" then board = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 } -- Randomize local swaps = 0 for i = 1, 16 do local j = math.random(i, 16) if i ~= j then board[i], board[j] = board[j], board[i] swaps = swaps + 1 end if board[i] == 16 then empty = i end end -- If the number of swaps plus the number of empty-space movements is odd, -- then the puzzle is impossible, so do an impossible move to make it possible -- (exchange the space with a tile two squares away) if (swaps + (empty - 1) + math.floor((empty - 1) / 4)) % 2 == 1 then local i = (empty + 7) % 16 + 1 board[empty] = board[i] empty = i board[empty] = 16 end moves = 0 platform.window:invalidate() endendon.charIn("r")function on.paint(gc) local won = true for i, n in ipairs(board) do if n ~= 16 then local x = (platform.window:width() - 128) / 2 + 32*((i - 1) % 4) local y = (platform.window:height() - 128) / 2 + 32*math.floor((i - 1) / 4) gc:drawRect(x, y, 30, 30) gc:drawString(n, x + (30 - gc:getStringWidth(n)) / 2, y + 15, "middle") end won = (won and n == i) end local str = moves .. " moves" gc:drawString(str, (platform.window:width() - gc:getStringWidth(str)) / 2, 0, "top") if won then str = "You win! Press R to reset" gc:drawString(str, (platform.window:width() - gc:getStringWidth(str)) / 2, platform.window:height(), "bottom") endendfunction on.arrowKey(key) local dir if key == "left" and empty % 4 ~= 0 then dir = 1 elseif key == "right" and empty % 4 ~= 1 then dir = -1 elseif key == "up" and empty <= 12 then dir = 4 elseif key == "down" and empty > 4 then dir = -4 else return end board[empty] = board[empty + dir] empty = empty + dir board[empty] = 16 moves = moves + 1 platform.window:invalidate()end
3.2 is not yet released ..I think you are mixing version numbers Here is a little list of versions:3.0.0 -- Only on CX in shop3.0.13.0.2 -- They added encryption to documents. Documents made with luna2tns and similar (for 3.0.1) don't work anymore3.1 -- Present3.2 -- Coming soon