Hello,
I am trying to make snake in Wolfram Mathematica.
I got part of code:
EventHandler[
Dynamic[Dynamic@
ArrayPlot@plansza], {{"KeyDown",
"j"} :> (SessionSubmit[
ScheduledTask[{GLOWASNAKE = Snake[[1]],
GLOWASNAKE1 = {GLOWASNAKE[[1]] + 1, GLOWASNAKE[[2]]},
Snake = Insert[Snake, GLOWASNAKE1, 1], zerujpkt[Last[Snake]],
Snake = Delete[Snake, Length[Snake]],
dodajdoplanszy[#, 1] & /@ Snake}, {1, 3}]]), {"KeyDown",
"u"} :> (SessionSubmit[
ScheduledTask[{GLOWASNAKE = Snake[[1]],
GLOWASNAKE1 = {GLOWASNAKE[[1]] - 1, GLOWASNAKE[[2]]},
Snake = Insert[Snake, GLOWASNAKE1, 1], zerujpkt[Last[Snake]],
Snake = Delete[Snake, Length[Snake]],
dodajdoplanszy[#, 1] & /@ Snake}, {1, 3}]]), {"KeyDown",
"h"} :> (SessionSubmit[
ScheduledTask[{GLOWASNAKE = Snake[[1]],
GLOWASNAKE1 = {GLOWASNAKE[[1]], GLOWASNAKE[[2]] - 1},
Snake = Insert[Snake, GLOWASNAKE1, 1], zerujpkt[Last[Snake]],
Snake = Delete[Snake, Length[Snake]],
dodajdoplanszy[#, 1] & /@ Snake}, {1, 3}]]), {"KeyDown",
"k"} :> (SessionSubmit[
ScheduledTask[{GLOWASNAKE = Snake[[1]],
GLOWASNAKE1 = {GLOWASNAKE[[1]], GLOWASNAKE[[2]] + 1},
Snake = Insert[Snake, GLOWASNAKE1, 1], zerujpkt[Last[Snake]],
Snake = Delete[Snake, Length[Snake]],
dodajdoplanszy[#, 1] & /@ Snake}, {1, 3}]])}]
And I'm trying to change "3" in a {1,3} part to something, that would stop the current task, when the other key is pressed on keyboard.
How to do this?