-
Notifications
You must be signed in to change notification settings - Fork 0
/
LifeCounter.svelte
62 lines (58 loc) · 1.32 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
53
54
55
56
57
58
59
60
61
62
<script>
export let header;
let life = 20;
$: alive = (life >= 0);
function changeLife(n) {
life += n;
}
</script>
<stackLayout>
<label class="header">{header}</label>
{#if alive}
<label class="info" horizontalAlignment="center" verticalAlignment="center" textWrap="true">
<formattedString>
<span text= "{life} " />
<span class="fas alive" text="" />
</formattedString>
</label>
{:else}
<label class="info" horizontalAlignment="center" verticalAlignment="center" textWrap="true">
<formattedString>
<span text= "{life} " />
<span class="fas dead" text="" />
</formattedString>
</label>
{/if}
<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 {
margin: 1em;
}
.dead {
color: #770077;
}
.alive {
color: #FF8888;
}
.header {
text-align: center;
font-size: 30;
}
.info {
font-size: 20;
}
button {
background-color: #1188CC;
margin: 0;
}
.reset {
background-color: red;
}
</style>