2048: Difference between revisions
m
update for newer Gtk versions
(2048 en QBasic) |
m (update for newer Gtk versions) |
||
Line 8,191:
=={{header|Julia}}==
Uses the Gtk toolkit. Includes scoring, a choice of board size and toolbar buttons for Undo and New Game.
<lang julia>using Gtk.ShortNames
@enum Direction2048 Right Left Up Down
Line 8,272 ⟶ 8,271:
toolbar = Toolbar()
newgame = ToolButton("New Game")
undomove = ToolButton("Undo Move")
map(w->push!(toolbar,w),[newgame,undomove])
grid = Grid()
map(w -> push!(box, w),[toolbar, grid])
buttons = Array{Gtk.GtkButtonLeaf,2}(undef, bsize, bsize)
for i in 1:bsize, j in 1:bsize
grid[i,j] = buttons[i,j] = Button()
end
board = zeros(Int, (bsize,bsize))
Line 8,294 ⟶ 8,293:
function update!()
for i in 1:bsize, j in 1:bsize
label = (board[i,j] > 0) ? board[i,j] : " "
end
end
function newrandomtile!()
Line 8,318 ⟶ 8,317:
for i in 1:bsize, j in 1:bsize
board[i,j] = 0
end
newrandomtile!()
Line 8,355 ⟶ 8,354:
signal_connect(undo!,undomove, :clicked)
signal_connect(endit, win, :destroy)
signal_connect(keypress, win, "key-press-event")
Gtk.showall(win)
wait(condition)
end
Line 8,363 ⟶ 8,362:
const boardsize = 4
app2048(boardsize)
=={{header|Kotlin}}==
|