Skip to content

Commit

Permalink
Add interactivity
Browse files Browse the repository at this point in the history
Rectangles are good, but we need to handle card clicks.
To separate model from view, we add Card structure with
basic fields - color and some boolean flag behaviours.
At any point we can check behaviour value and draw either
face or back of the card.
Clicking the card would toggle the opened value.
  • Loading branch information
orlovol committed May 29, 2019
1 parent 0e8e466 commit 87a47dc
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions game.flow
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
import lib/tropic/tropic_ui;

Card(
face: TColor,
opened: DynamicBehaviour<bool>,
solved: DynamicBehaviour<bool>,
);

drawCard() -> Tropic {
TRectangle([Fill(darkGray)], TFixed(150.0, 150.0));
drawCard(color: TColor) -> Tropic {
size = TFixed(150.0, 150.0);

card = Card(color, make(false), make(false));
toggleCard = \ -> reverseBehaviour(card.opened);

TSelect(card.opened, \opened -> {
faceColor = if (opened) card.face else TDarkGrey();
TTextButton("", "", [faceColor, TForeground(size)], [TOnClicked(toggleCard)]);
});
}

main() {
header = TText("Memory game", [FontSize(20.0)]);

cards = TCols([
drawCard(),
drawCard(),
drawCard(),
drawCard(),
drawCard(TGreen()),
drawCard(TRed()),
drawCard(TGreen()),
drawCard(TRed()),
]);

view = TLines([
header |> TCenterX,
cards |> TCenterX,
]);
view = TLinesXCenter([
header,
cards,
]) |> TCenterX;

trender(view, []);
}

0 comments on commit 87a47dc

Please sign in to comment.