Uno (Card Game)/Julia: Difference between revisions
m
Fixed syntax highlighting.
m (move logging area to side) |
m (Fixed syntax highlighting.) |
||
(4 intermediate revisions by one other user not shown) | |||
Line 2:
Gtk based graphical version.
<
#=========== Channel and flag (IPC) section ===================#
""" channel, communicates player's mouse choice of card or color to game logic """
const channel = Channel{Any}(100)
""" flush the channel from mouse choice to game logic """
Line 18:
""" The Uno card type. The first field is color, second field is number or command. """
color(c::UnoCard) = first(c)
type(c::UnoCard) = last(c)
Line 97:
hands = [deck[i:i+6] for i in 1:7:27]
game = UnoCardGameState(drawpile, discardpile, [UnoCardGamePlayer(playernames[i], 0,
startswith(playernames[i], "Bot")
for i in 1:length(playernames)], 1, "Wild", "Wild", true, true)
dealer = rand(1:length(playernames))
Line 152:
# bot will challenge half the time, player must challenge in 5 seconds.
if game.players[game.pnow].isabot && rand() < 0.5 ||
(!game.players[game.pnow].isabot && challenge[begin]
challenge[begin] = false
logline("$(game.players[game.pnow].name) challenged Draw Four!")
Line 158:
nextplayer!(game); nextplayer!(game); nextplayer!(game); # prior player
game.colornow = game.lastcolor
hand = game.players[game.pnow].hand
if any(
logline("Challenge sustained! Challenged Draw Four player draws 4.")
drawcardsfromdeck!(game, 2); drawcardsfromdeck!(game, 2)
Line 335 ⟶ 334:
"Green" => colorant"green", "Blue" => colorant"blue", "Wild" => colorant"black")
""" CSS style button for bold colored text """
function colorbutton(txt::String, clr::String)
button = GtkButton(txt)
Line 465:
hand = first(game.players).hand
isempty(hand) && return
nrow = (length(hand) + 15) ÷
for row in 1:nrow
cards = hand[(row - 1) *
startx, starty = 40 + (
for (i, card) in enumerate(cards)
idx, x0 = (row - 1) *
cardpositions[idx] = [x0, starty, x0 + 40, starty + 80]
cairocard(ctx, card, x0, starty, 40, 80)
Line 536:
end
UnoCardGameApp()</syntaxhighlight>
|