2048: Difference between revisions

39 bytes added ,  2 years ago
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
using Gtk.ShortNames
 
@enum Direction2048 Right Left Up Down
Line 8,272 ⟶ 8,271:
toolbar = Toolbar()
newgame = ToolButton("New Game")
setpropertyset_gtk_property!(newgame, :label, "New Game")
setpropertyset_gtk_property!(newgame, :is_important, true)
undomove = ToolButton("Undo Move")
setpropertyset_gtk_property!(undomove, :label, "Undo Move")
setpropertyset_gtk_property!(undomove, :is_important, true)
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()
setpropertyset_gtk_property!(buttons[i,j], :expand, true)
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] : " "
setpropertyset_gtk_property!(buttons[i,j], :label, label)
end
setpropertyset_gtk_property!(win, :title, "$won 2048 Game (Score: $score)")
end
function newrandomtile!()
Line 8,318 ⟶ 8,317:
for i in 1:bsize, j in 1:bsize
board[i,j] = 0
setpropertyset_gtk_property!(buttons[i,j], :label, " ")
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)
</lang>
 
=={{header|Kotlin}}==
4,102

edits