Uno (Card Game)/Julia: Difference between revisions

Content added Content deleted
m (const globals)
Line 18: Line 18:


""" The Uno card type. The first field is color, second field is number or command. """
""" The Uno card type. The first field is color, second field is number or command. """
const UnoCard = Pair{String, String}
UnoCard = Pair{String, String}
color(c::UnoCard) = first(c)
color(c::UnoCard) = first(c)
type(c::UnoCard) = last(c)
type(c::UnoCard) = last(c)
Line 335: Line 335:
"Green" => colorant"green", "Blue" => colorant"blue", "Wild" => colorant"black")
"Green" => colorant"green", "Blue" => colorant"blue", "Wild" => colorant"black")


""" CSS style button for bold colored text """
function colorbutton(txt::String, clr::String)
function colorbutton(txt::String, clr::String)
button = GtkButton(txt)
button = GtkButton(txt)
Line 465: Line 466:
hand = first(game.players).hand
hand = first(game.players).hand
isempty(hand) && return
isempty(hand) && return
nrow = (length(hand) + 15) ÷ 16
nrow = (length(hand) + 15) ÷ 15
for row in 1:nrow
for row in 1:nrow
cards = hand[(row - 1) * 16 + 1 : min(length(hand), row * 16 - 1)]
cards = hand[(row - 1) * 15 + 1 : min(length(hand), row * 15 - 1)]
startx, starty = 40 + (16 - length(cards)) * 20, 500 + 85 * (row - 1)
startx, starty = 40 + (15 - length(cards)) * 20, 500 + 85 * (row - 1)
for (i, card) in enumerate(cards)
for (i, card) in enumerate(cards)
idx, x0 = (row - 1) * 16 + i, startx + 50 * (i - 1)
idx, x0 = (row - 1) * 15 + i, startx + 50 * (i - 1)
cardpositions[idx] = [x0, starty, x0 + 40, starty + 80]
cardpositions[idx] = [x0, starty, x0 + 40, starty + 80]
cairocard(ctx, card, x0, starty, 40, 80)
cairocard(ctx, card, x0, starty, 40, 80)