wh = 220 ww = 330 function wi() platform.window:invalidate() end xc = ww/2 yc = wh/2 dx = 0 dy = 0 x = {} y = {} x[1] = {} y[1] = {} x[1][1] = ww/2 y[1][1] = wh/2 idxy = 1 last = {} last[1] = 1 reset = false isDrawLine = true mode = "menu" function on.paint(gc) if mode == "menu" then gc:drawString("Appuyer sur Entree pour jouer !", ww/2-gc:getStringWidth("Appuyer sur Entree pour jouer !")/2, wh/2+30) gc:setFont("serif", "r", 20) gc:drawString("TI-Cran", ww/2-gc:getStringWidth("TI-Cran")/2, wh/2-40) elseif mode == "jeu" then gc:setColorRGB(0, 0, 0) if reset == true then resetW() reset = false end i = 1 j = 1 while i < idxy or i == idxy do temp = last[i] while j < temp do gc:drawLine(x[i][j], y[i][j], x[i][j+1], y[i][j+1]) j = j + 1 end i = i + 1 end if isDrawLine == true then temp = last[idxy] gc:drawLine(x[idxy][temp], y[idxy][temp], xc, yc) else gc:drawLine(xc, yc, xc, yc) end xc = xc + dx yc = yc + dy if xc > ww then xc = ww dx = 0 dy = 0 end if yc > wh then yc = wh dx = 0 dy = 0 end if xc < 0 then xc = 0 dx = 0 dy = 0 end if yc < 0 then yc = 0 dx = 0 dy = 0 end end timer.start(0.05) end function on.timer() timer.stop() wi() end function resetW() i = idxy while i > 0 do j = last[i] while j > 0 do x[i][j] = nil y[i][j] = nil j = j - 1 end i = i - 1 end xc = ww/2 yc = wh/2 dx = 0 dy = 0 x[1][1] = ww/2 y[1][1] = wh/2 idxy = 1 last[1] = 1 end function on.enterKey() if mode == "menu" then mode = "jeu" elseif mode == "jeu" then mode = "menu" resetW() end end function on.charIn(char) if mode == "jeu" then if char == "9" then isnb = true dx = 1 dy = -1 elseif char == "8" then isnb = true dx = 0 dy = -1 elseif char == "7" then isnb = true dx = -1 dy = -1 elseif char == "6" then isnb = true dx = 1 dy = 0 elseif char == "5" then isnb = true dx = 0 dy = 0 elseif char == "4" then isnb = true dx = -1 dy = 0 elseif char == "3" then isnb = true dx = 1 dy = 1 elseif char == "2" then isnb = true dx = 0 dy = 1 elseif char == "1" then isnb = true dx = -1 dy = 1 end if isnb == true and isDrawLine == true then last[idxy] = last[idxy] + 1 x[idxy][last[idxy]] = xc y[idxy][last[idxy]] = yc isnb = false end if char == "0" then reset = true end if char == "." then if isDrawLine == true then isDrawLine = false last[idxy] = last[idxy] + 1 x[idxy][last[idxy]] = xc y[idxy][last[idxy]] = yc else isDrawLine = true idxy = idxy + 1 last[idxy] = 1 x[idxy] = {} y[idxy] = {} x[idxy][1] = xc y[idxy][1] = yc end end end wi() end