Browse Source

Finish main game logic

main
ThePerkinrex 5 years ago
parent
commit
a6dae9bc77
No known key found for this signature in database GPG Key ID: FD81DE6D75E20917
  1. 49
      game.rhai

49
game.rhai

@ -24,7 +24,9 @@ fn setup(data) {
// 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;
@ -32,11 +34,14 @@ fn setup(data) {
fn turn_end(data, player) {
print("Turn for " + player + " ending");
let s = if data.skip {2} else {1};
if data.fw {
player.add(1);
player.add(s);
}else{
player.sub(1);
player.sub(s);
}
data.skip = false;
return [data, player];
}
@ -46,7 +51,6 @@ fn turn_start(data, player) {
}
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);
@ -78,16 +82,22 @@ fn on_click(data, card, action_author, current_player) {
}else{
if card.pile_kind == "common" {
if card.pile_name == "deck" {
if data.next_plus4 == 0 {
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{
}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];
}
}
@ -124,15 +134,26 @@ fn on_click(data, card, action_author, current_player) {
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 {
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];
}
}

Loading…
Cancel
Save