You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
2.7 KiB
106 lines
2.7 KiB
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);
|
|
}
|
|
}
|
|
// print(data.player_piles);
|
|
// print(data.piles.deck);
|
|
data.fw = true;
|
|
data.next_plus4 = 0;
|
|
data.selecting_color_plus4 = false;
|
|
return data;
|
|
}
|
|
|
|
fn turn_end(data, player) {
|
|
print("Turn for " + player + " ending");
|
|
if data.fw {
|
|
player.add(1);
|
|
}else{
|
|
player.sub(1);
|
|
}
|
|
return [data, player];
|
|
}
|
|
|
|
fn turn_start(data, player) {
|
|
print("Turn for " + player + " starting");
|
|
return data;
|
|
}
|
|
|
|
fn on_click(data, card, action_author, current_player) {
|
|
// TODO handle next_plus4
|
|
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;
|
|
return [data, true];
|
|
}else{
|
|
return [data, false];
|
|
}
|
|
}else{
|
|
if card.pile_kind == "common" {
|
|
if card.pile_name == "deck" {
|
|
// Get a card from the deck
|
|
let c = data.pop_card(card);
|
|
data.player_piles[current_player.val].deck.cards.push(c);
|
|
|
|
}
|
|
}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"));
|
|
|
|
return [data, false];
|
|
}
|
|
_ => {
|
|
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 {
|
|
data.pop_card(card);
|
|
data.piles.placed.cards.push(c);
|
|
return [data, true];
|
|
}else if last_card.other.number == c.other.number {
|
|
data.pop_card(card);
|
|
data.piles.placed.cards.push(c);
|
|
return [data, true];
|
|
}else {
|
|
return [data, false];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return [data, true];
|
|
|
|
}
|
|
return [data, false];
|
|
}
|