| Name | Message | Date |
|---|---|---|
| 📄 GameScreen.svelte | 1 month ago | |
| 📄 ResultsScreen.svelte | 1 month ago |
📄
GameScreen.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<script lang="ts">
import { PLAYER_COLORS } from "$lib/types";
import { onMount } from "svelte";
interface Props {
playerCount: number;
onTap: (playerId: number) => void;
}
let { playerCount, onTap }: Props = $props();
let currentPlayer: number | null = $state(null);
let timeout: NodeJS.Timeout | null = null;
onMount(() => {
nextTimeout();
return () => {
if (timeout) {
clearTimeout(timeout);
}
};
});
function nextTimeout() {
const minInterval = 800;
const maxInterval = 6000;
const interval = Math.random() * (maxInterval - minInterval) + minInterval;
timeout = setTimeout(() => {
// Choose a random player
currentPlayer = Math.floor(Math.random() * playerCount);
// Clear current player after a short delay
const minInterval = 800;
const maxInterval = 2500;
const interval = Math.random() * (maxInterval - minInterval) + minInterval;
timeout = setTimeout(() => {
currentPlayer = null;
nextTimeout();
}, interval);
}, interval);
}
function handleClick() {
if (currentPlayer != null) {
onTap(currentPlayer);
if (timeout) {
clearTimeout(timeout);
}
currentPlayer = null;
nextTimeout();
}
}
function handleKeydown(event: KeyboardEvent) {
if (event.key === "Enter" || event.key === " ") {
handleClick();
}
}
</script>
<div
class="game-screen"
style="background-color: {currentPlayer != null ? PLAYER_COLORS[currentPlayer] : '#000000'}"
onclick={handleClick}
onkeydown={handleKeydown}
role="button"
tabindex="0"
>
{#if currentPlayer != null}
<div class="tap-indicator">TAP!</div>
{/if}
</div>
<style>
.game-screen {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
user-select: none;
-webkit-tap-highlight-color: transparent;
}
.tap-indicator {
font-size: 4rem;
font-weight: bold;
color: rgba(255, 255, 255, 0.9);
text-shadow:
0 0 10px rgba(0, 0, 0, 0.5),
0 0 20px rgba(0, 0, 0, 0.3);
animation: pulse 0.5s ease-in-out infinite alternate;
}
@keyframes pulse {
from {
transform: scale(1);
opacity: 0.8;
}
to {
transform: scale(1.1);
opacity: 1;
}
}
</style>