Skip to main content

Game Development

Recipies about game development.

Setup

Sort Pieces

const hand = game.create(Space, "hand", { player });
hand.onEnter(Card, (c) => {
hand.sortBy("name");
});

Make Pieces Visible Only To Owner

const hand = game.create(Space, "hand", { player });
hand.onEnter(Card, (c) => {
c.showOnlyTo(player.position);
});

Actions

Draw Multiple Cards At Once

game.defineActions({
drawCards: (player) =>
action({ prompt: "Draw 2 cards" })
.chooseOnBoard("cards", $.drawPile.all(Card), {
number: 2,
confirm: "Take these 2 cards?",
})
.move("cards", player.my("hand")!),
});

Flow

Draw an Initial Hand For Each Player

for (const player of game.players) {
$.draw.firstN(3, Card).putInto(player.my("hand")!);
}

Shuffle a Deck

$.drawPile.shuffle();

Simultaneous Actions

If you need players to perform actions at the same time:

everyPlayer({
do: playerActions({ actions: ['discardCard'] })
}),