fn setup(data) { print("Setting up UNO for " + data.players + " players"); // print(data.piles.deck); data.piles.deck = shuffle(data.piles.deck); // print(data.piles.deck); // print(data.player_piles); for i in range(0, 7) { // print(i); for player_idx in range(0, data.player_piles.len) { // print("Deck" + player); let drawed_card = data.piles.deck.cards.pop(); // print(player.deck.cards); data.player_piles[player_idx].deck.cards.push(drawed_card); // print(player.deck.cards); } } let drawed_card = data.piles.deck.cards.pop(); data.piles.placed.cards.push(drawed_card); // print(data.player_piles); // print(data.piles.deck); data.fw = true; data.skip = false; data.next_plus4 = 0; data.next_plus2 = 0; data.selecting_color_plus4 = false; data.selecting_color = false; return data; } fn turn_end(data, player) { print("Turn for " + player + " ending"); let s = if data.skip {2} else {1}; if data.fw { player.add(s); }else{ player.sub(s); } data.skip = false; // TODO Add has_finished condition return [data, player, false]; } fn turn_start(data, player) { print("Turn for " + player + " starting"); return data; } fn on_click(data, card, action_author, current_player) { if action_author == current_player { if data.selecting_color_plus4 { print(card); if card.pile_kind != "common" && card.pile_name == "color_select" { data.selecting_color_plus4 = false; let c = data.pop_card(card); data.piles.placed.cards.push(c); data.player_piles[current_player.val].color_select.cards = []; data.next_plus4 += 1; data.player_piles[current_player.val].color_select.visible = false; data.player_piles[current_player.val].deck.visible = true; return [data, true]; }else{ return [data, false]; } }else if data.selecting_color { print(card); if card.pile_kind != "common" && card.pile_name == "color_select" { data.selecting_color = false; let c = data.pop_card(card); data.piles.placed.cards.push(c); data.player_piles[current_player.val].color_select.cards = []; data.player_piles[current_player.val].color_select.visible = false; data.player_piles[current_player.val].deck.visible = true; return [data, true]; }else{ return [data, false]; } }else{ if card.pile_kind == "common" { if card.pile_name == "deck" { if data.next_plus4 == 0 && data.next_plus2 == 0 { // Get a card from the deck data = draw(data, current_player); return [data, true]; // TODO: Turn shouldn't end on draw, if placeable, the card should be placed or kept }else if data.next_plus2 == 0 { for i in range(0, data.next_plus4*4) { data = draw(data, current_player); } data.next_plus4 = 0; return [data, true]; }else{ for i in range(0, data.next_plus2*2) { data = draw(data, current_player); } data.next_plus2 = 0; return [data, true]; } } }else{ if card.pile_name == "deck" { let c = data.get_card(card); switch c.kind { "+4" => { data.selecting_color_plus4 = true; data.pop_card(card); data.player_piles[current_player.val].color_select.cards.push(new_card("G+4")); data.player_piles[current_player.val].color_select.cards.push(new_card("R+4")); data.player_piles[current_player.val].color_select.cards.push(new_card("B+4")); data.player_piles[current_player.val].color_select.cards.push(new_card("Y+4")); data.player_piles[current_player.val].color_select.visible = true; data.player_piles[current_player.val].deck.visible = false; return [data, false]; } "COLORCHANGE" => if data.next_plus4 == 0 { data.selecting_color = true; data.pop_card(card); data.player_piles[current_player.val].color_select.cards.push(new_card("GCOLORCHANGE")); data.player_piles[current_player.val].color_select.cards.push(new_card("RCOLORCHANGE")); data.player_piles[current_player.val].color_select.cards.push(new_card("BCOLORCHANGE")); data.player_piles[current_player.val].color_select.cards.push(new_card("YCOLORCHANGE")); data.player_piles[current_player.val].color_select.visible = true; data.player_piles[current_player.val].deck.visible = false; return [data, false]; } _ => if data.next_plus4 == 0 { let last_card = data.piles.placed.cards[data.piles.placed.cards.len-1]; print(last_card); print(c); if last_card.other.color == c.other.color || last_card.other.number == c.other.number { if data.next_plus2 == 0 { data.pop_card(card); data.piles.placed.cards.push(c); switch c.other.number { "REVERSE" => {data.fw = !data.fw} "SKIP" => {data.skip = true} "+2" => {data.next_plus2 += 1} } return [data, true]; } else if c.other.number == "+2" { data.pop_card(card); data.piles.placed.cards.push(c); data.next_plus2 += 1; return [data, true]; }else{ return [data, false]; } } else { return [data, false]; } } } } } } return [data, true]; } return [data, false]; } fn draw(data, current_player) { if data.piles.deck.len == 0 { let s = data.piles.placed.cards.split(1); data.piles.placed.cards = s[0]; data.piles.deck = shuffle(s[1]); } let c = data.piles.deck.cards.pop(); data.player_piles[current_player.val].deck.cards.push(c); return data; }