Snake: Difference between revisions
m
→{{header|Julia}}: update for Makie changes to Observables
m (→{{header|Julia}}: update for Makie changes to Observables) |
|||
Line 3,261:
=={{header|Julia}}==
▲<syntaxhighlight lang="julia">using Makie
mutable struct SnakeGame
height::Int
width::Int
snake::Vector{CartesianIndex{2}}
food::CartesianIndex{2}
end
Line 3,307 ⟶ 3,306:
function play(;n=10,t=0.5)
game =
scene = Scene(resolution = (1000, 1000), raw = true, camera = campixel!)
display(scene)
Line 3,328 ⟶ 3,327:
score_text = @lift("Score: $(length($game.snake)-1)")
text!(scene, score_text, color=:gray, position = @lift((widths($area)[1]/2, widths($area)[2])),
direction = Ref{Any}(nothing)
on(events(scene).
if
direction[] = CartesianIndex(-1,0)
direction[] = CartesianIndex(0,1)
direction[] = CartesianIndex(0,-1)
direction[] = CartesianIndex(1,0)
end
end
end
|