Skip to content

Commit

Permalink
Congratulations
Browse files Browse the repository at this point in the history
It always feels good to be praised for hard work.
Let's add a popup dialog that does exactly that, only thing
we need is the number of solved cards.
  • Loading branch information
orlovol committed May 29, 2019
1 parent 0b05ec3 commit 1f62aad
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions game.flow
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,17 @@ blockerForm(content: Tropic, click: DynamicBehaviour<bool>, visible: Transform<b
}

main() {
header = TText("Memory game", [FontSize(20.0)]);
text = \t : string -> TText(t, [FontSize(20.0)]);

header = text("Memory game");

makeCard = \icon -> Card(icon, make(false), make(false));
cards = map(shuffleArray(FACES), makeCard);
cardGrid = TGrid(splitByNumber(map(cards, drawCard), COLS));

activeCardStates = fmerge(map(cards, \c -> fand(c.opened, fnot(c.solved))));
activeCount = flength(ffilter(activeCardStates, idfn));
solvedAll = feq(flength(ffilter(fmerge(map(cards, \c -> c.solved)), idfn)), length(FACES));

closeClick = make(false);
closeOpened = \close -> {
Expand All @@ -97,11 +100,18 @@ main() {
}
}

congratulate = \solved -> {
if (solved) {
dialog = text("You won!");
ShowTDialog(TFrame(20.0, 10.0, [Fill(white)], dialog), []);
}
}

game = TConstruct(
[
makeSubscribe(activeCardStates, matchOpened),
makeSubscribe(closeClick, closeOpened)
makeSubscribe(closeClick, closeOpened),
makeSubscribe(solvedAll, congratulate),
],
TLinesXCenter([
header,
Expand Down

0 comments on commit 1f62aad

Please sign in to comment.