-
Notifications
You must be signed in to change notification settings - Fork 0
/
LifeCounter.svelte
52 lines (48 loc) · 1.1 KB
/
LifeCounter.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<script>
export let header;
let life = 20;
$: alive = (life >= 0);
function changeLife(n) {
life += n;
}
</script>
<stackLayout>
<label class="header">{header}</label>
<label class="info" horizontalAlignment="center" verticalAlignment="center" textWrap="true">
<formattedString class="alive">
<span text= "{life} " />
{#if alive}
<span class="fas alive" text="" />
{:else}
<span class="fas dead" text="" />
{/if}
</formattedString>
</label>
<flexboxLayout>
<button on:tap={() => changeLife(-5)}>-5</button>
<button on:tap={() => changeLife(-1)}>-1</button>
<button on:tap={() => changeLife(+1)}>+1</button>
<button on:tap={() => changeLife(+5)}>+5</button>
<button on:tap={() => life=20} class="reset">RESET</button>
</flexboxLayout>
</stackLayout>
<style>
.info .fas {
color: #FF8888;
margin: 1em;
}
.header {
text-align: center;
font-size: 30;
}
.info {
font-size: 20;
}
button {
background-color: blue;
margin: 0;
}
.reset {
background-color: red;
}
</style>