forked from frero/hanabi
kinda working client
This commit is contained in:
+15
-3
@@ -39,6 +39,10 @@ Bit_Card :: bit_field u8 {
|
||||
color: COLORS | 3,
|
||||
}
|
||||
|
||||
pack_card :: proc(c: Card) -> Bit_Card {
|
||||
return {value = c.value, color = c.color}
|
||||
}
|
||||
|
||||
Payload :: struct #packed {
|
||||
num_hints: u8,
|
||||
num_lives: u8,
|
||||
@@ -52,7 +56,7 @@ create_payload :: proc(g: Game, player: int, allocator := context.allocator) ->
|
||||
if i == player do continue
|
||||
hand := g.players[i].hand[:]
|
||||
for c in hand {
|
||||
append(&cards, Bit_Card{value = c.value, color = c.color})
|
||||
append(&cards, pack_card(c))
|
||||
}
|
||||
}
|
||||
return {u8(g.hint_tokens), u8(g.lives_left), u8(len(cards)), cards[:]}
|
||||
@@ -88,19 +92,27 @@ run_server :: proc(
|
||||
defer delete_game(&g)
|
||||
|
||||
current_player := rand.int_max(num_players)
|
||||
game_loop: for {
|
||||
GAME_LOOP: for {
|
||||
for i in 0 ..< num_players {
|
||||
pl := create_payload(g, i, context.temp_allocator)
|
||||
send_err := send_payload(w.sockets[i], pl)
|
||||
if send_err != nil do panic("failed to send payload")
|
||||
}
|
||||
|
||||
fmt.printfln("player %s's turn!", current_player)
|
||||
fmt.printfln("player %d's turn!", current_player)
|
||||
|
||||
for p in g.players {
|
||||
fmt.println()
|
||||
for c in p.hand {
|
||||
fmt.println(c.value, c.color)
|
||||
}
|
||||
}
|
||||
|
||||
// body
|
||||
|
||||
current_player = (current_player + 1) % num_players
|
||||
free_all(context.temp_allocator)
|
||||
break GAME_LOOP
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user