@tsparticles/template-tictactoe 4.1.3 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +3 -0
  3. package/package.json +4 -3
  4. package/template/angular/package.json +34 -0
  5. package/template/angular/src/app/app.component.css +97 -0
  6. package/template/angular/src/app/app.component.html +21 -0
  7. package/template/angular/src/app/app.component.ts +94 -0
  8. package/template/angular-confetti/package.json +34 -0
  9. package/template/angular-confetti/src/app/app.component.css +97 -0
  10. package/template/angular-confetti/src/app/app.component.html +21 -0
  11. package/template/angular-confetti/src/app/app.component.ts +94 -0
  12. package/template/angular-fireworks/package.json +34 -0
  13. package/template/angular-fireworks/src/app/app.component.css +97 -0
  14. package/template/angular-fireworks/src/app/app.component.html +21 -0
  15. package/template/angular-fireworks/src/app/app.component.ts +94 -0
  16. package/template/astro/package.json +15 -0
  17. package/template/astro/src/pages/index.astro +158 -0
  18. package/template/ember/app/controllers/application.js +94 -0
  19. package/template/ember/app/templates/application.hbs +39 -0
  20. package/template/ember/package.json +17 -0
  21. package/template/inferno/package.json +20 -0
  22. package/template/inferno/src/App.css +97 -0
  23. package/template/inferno/src/App.tsx +149 -0
  24. package/template/jquery/package.json +20 -0
  25. package/template/jquery/src/main.ts +126 -0
  26. package/template/jquery/src/style.css +97 -0
  27. package/template/lit/package.json +19 -0
  28. package/template/lit/src/my-app.ts +133 -0
  29. package/template/nextjs/package.json +20 -0
  30. package/template/nextjs/src/app/page.tsx +173 -0
  31. package/template/nextjs/src/app/providers.tsx +13 -0
  32. package/template/nuxt2/package.json +14 -0
  33. package/template/nuxt2/pages/index.vue +203 -0
  34. package/template/nuxt3/app.vue +204 -0
  35. package/template/nuxt3/package.json +16 -0
  36. package/template/nuxt4/app.vue +202 -0
  37. package/template/nuxt4/package.json +16 -0
  38. package/template/preact/package.json +20 -0
  39. package/template/preact/src/App.css +97 -0
  40. package/template/preact/src/App.tsx +141 -0
  41. package/template/qwik/package.json +19 -0
  42. package/template/qwik/src/App.tsx +132 -0
  43. package/template/react/package.json +19 -0
  44. package/template/react/src/App.css +97 -0
  45. package/template/react/src/App.tsx +141 -0
  46. package/template/riot/package.json +20 -0
  47. package/template/riot/src/app.riot +139 -0
  48. package/template/solid/package.json +18 -0
  49. package/template/solid/src/App.tsx +151 -0
  50. package/template/solid/src/index.css +97 -0
  51. package/template/solid/src/main.tsx +9 -0
  52. package/template/stencil/package.json +14 -0
  53. package/template/stencil/src/components/app-home/app-home.css +97 -0
  54. package/template/stencil/src/components/app-home/app-home.tsx +122 -0
  55. package/template/svelte/package.json +20 -0
  56. package/template/svelte/src/App.svelte +256 -0
  57. package/template/svelte/src/main.ts +12 -0
  58. package/template/vanilla/LICENSE +21 -0
  59. package/template/vue2/package.json +19 -0
  60. package/template/vue2/src/App.vue +204 -0
  61. package/template/vue3/package.json +19 -0
  62. package/template/vue3/src/App.vue +215 -0
  63. package/template/vue3/src/main.ts +14 -0
  64. package/template/webcomponents/package.json +18 -0
  65. package/template/webcomponents/src/main.ts +134 -0
  66. package/template/webcomponents/src/style.css +97 -0
@@ -0,0 +1,97 @@
1
+ * {
2
+ box-sizing: border-box;
3
+ }
4
+
5
+ body {
6
+ margin: 0;
7
+ min-height: 100vh;
8
+ display: flex;
9
+ align-items: center;
10
+ justify-content: center;
11
+ background: #0a0a1a;
12
+ font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
13
+ color: #fff;
14
+ }
15
+
16
+ #app {
17
+ text-align: center;
18
+ z-index: 10;
19
+ padding: 1rem;
20
+ }
21
+
22
+ h1 {
23
+ font-size: 2.5em;
24
+ margin-bottom: 1rem;
25
+ background: linear-gradient(135deg, #6c5ce7, #fd79a8);
26
+ -webkit-background-clip: text;
27
+ -webkit-text-fill-color: transparent;
28
+ background-clip: text;
29
+ }
30
+
31
+ .scoreboard {
32
+ display: flex;
33
+ justify-content: center;
34
+ gap: 2rem;
35
+ margin-bottom: 1rem;
36
+ font-size: 1.1em;
37
+ opacity: 0.8;
38
+ }
39
+
40
+ .turn {
41
+ font-size: 1.2em;
42
+ margin-bottom: 1rem;
43
+ opacity: 0.7;
44
+ }
45
+
46
+ .board {
47
+ display: grid;
48
+ grid-template-columns: repeat(3, 100px);
49
+ grid-template-rows: repeat(3, 100px);
50
+ gap: 4px;
51
+ background: rgba(255, 255, 255, 0.1);
52
+ border-radius: 12px;
53
+ overflow: hidden;
54
+ margin: 0 auto;
55
+ width: fit-content;
56
+ }
57
+
58
+ .cell {
59
+ display: flex;
60
+ align-items: center;
61
+ justify-content: center;
62
+ font-size: 2.5em;
63
+ font-weight: 700;
64
+ background: #12122a;
65
+ cursor: pointer;
66
+ transition: background 0.2s;
67
+ user-select: none;
68
+ }
69
+
70
+ .cell:hover {
71
+ background: #1a1a3a;
72
+ }
73
+
74
+ .cell.taken {
75
+ cursor: default;
76
+ }
77
+
78
+ .cell.win {
79
+ background: rgba(108, 92, 231, 0.3);
80
+ }
81
+
82
+ .reset-btn {
83
+ margin-top: 1.5rem;
84
+ padding: 0.7em 2em;
85
+ font-size: 1em;
86
+ font-weight: 600;
87
+ border: none;
88
+ border-radius: 8px;
89
+ background: linear-gradient(135deg, #6c5ce7, #a29bfe);
90
+ color: #fff;
91
+ cursor: pointer;
92
+ transition: transform 0.2s;
93
+ }
94
+
95
+ .reset-btn:hover {
96
+ transform: scale(1.05);
97
+ }
@@ -0,0 +1,141 @@
1
+ import { useState, useCallback } from "preact/hooks";
2
+ import Particles, { ParticlesProvider } from "@tsparticles/preact";
3
+ import { loadSlim } from "@tsparticles/slim";
4
+ import { confetti } from "@tsparticles/confetti";
5
+ import type { Engine, ISourceOptions } from "@tsparticles/engine";
6
+ import "./App.css";
7
+
8
+ type Player = "X" | "O";
9
+
10
+ interface GameState {
11
+ board: (Player | null)[];
12
+ currentPlayer: Player;
13
+ winner: Player | "draw" | null;
14
+ winLine: number[] | null;
15
+ scores: { X: number; O: number; draw: number };
16
+ }
17
+
18
+ const WIN_PATTERNS = [
19
+ [0, 1, 2], [3, 4, 5], [6, 7, 8],
20
+ [0, 3, 6], [1, 4, 7], [2, 5, 8],
21
+ [0, 4, 8], [2, 4, 6],
22
+ ];
23
+
24
+ function createInitialState(): GameState {
25
+ return {
26
+ board: Array(9).fill(null),
27
+ currentPlayer: "X",
28
+ winner: null,
29
+ winLine: null,
30
+ scores: { X: 0, O: 0, draw: 0 },
31
+ };
32
+ }
33
+
34
+ function checkWin(board: (Player | null)[]): { winner: Player | "draw"; winLine: number[] } | null {
35
+ for (const pattern of WIN_PATTERNS) {
36
+ const [a, b, c] = pattern;
37
+ if (board[a] && board[a] === board[b] && board[a] === board[c]) {
38
+ return { winner: board[a] as Player, winLine: pattern };
39
+ }
40
+ }
41
+ if (board.every((cell) => cell !== null)) {
42
+ return { winner: "draw" as const, winLine: [] };
43
+ }
44
+ return null;
45
+ }
46
+
47
+ function fireConfettiEffect() {
48
+ const count = 200;
49
+ const defaults = { origin: { y: 0.7 } };
50
+ const fire = (particleRatio: number, opts: Record<string, unknown>) => {
51
+ confetti({ ...defaults, ...opts, particleCount: Math.floor(count * particleRatio) });
52
+ };
53
+ fire(0.25, { spread: 26, startVelocity: 55 });
54
+ fire(0.2, { spread: 60 });
55
+ fire(0.35, { spread: 100, decay: 0.91, scalar: 0.8 });
56
+ fire(0.1, { spread: 120, startVelocity: 25, decay: 0.92, scalar: 1.2 });
57
+ fire(0.1, { spread: 120, startVelocity: 45 });
58
+ }
59
+
60
+ async function init(engine: Engine): Promise<void> {
61
+ await loadSlim(engine);
62
+ }
63
+
64
+ const particlesOptions: ISourceOptions = {
65
+ fullScreen: { enable: true, zIndex: -1 },
66
+ background: { color: { value: "#0a0a1a" } },
67
+ fpsLimit: 60,
68
+ particles: {
69
+ number: { value: 30, density: { enable: true } },
70
+ color: { value: ["#6c5ce7", "#a29bfe"] },
71
+ shape: { type: "circle" },
72
+ opacity: { value: 0.2, random: true },
73
+ size: { value: { min: 1, max: 2 } },
74
+ move: { enable: true, speed: 0.5, direction: "none", random: true, straight: false, outModes: { default: "out" } },
75
+ },
76
+ detectRetina: true,
77
+ };
78
+
79
+ export default function App() {
80
+ const [state, setState] = useState<GameState>(createInitialState);
81
+
82
+ const handleMove = useCallback((index: number) => {
83
+ setState((prev) => {
84
+ if (prev.board[index] || prev.winner) return prev;
85
+ const board = [...prev.board];
86
+ board[index] = prev.currentPlayer;
87
+ const result = checkWin(board);
88
+ if (result) {
89
+ const scores = { ...prev.scores };
90
+ if (result.winner === "draw") scores.draw++;
91
+ else scores[result.winner]++;
92
+ if (result.winner !== "draw") {
93
+ setTimeout(fireConfettiEffect, 100);
94
+ }
95
+ return { ...prev, board, winner: result.winner, winLine: result.winLine, scores };
96
+ }
97
+ return { ...prev, board, currentPlayer: prev.currentPlayer === "X" ? "O" : "X" };
98
+ });
99
+ }, []);
100
+
101
+ function handleReset() {
102
+ setState((prev) => ({
103
+ ...prev,
104
+ board: Array(9).fill(null),
105
+ currentPlayer: "X",
106
+ winner: null,
107
+ winLine: null,
108
+ }));
109
+ }
110
+
111
+ const status = state.winner
112
+ ? state.winner === "draw" ? "It's a draw!" : `${state.winner} wins!`
113
+ : `${state.currentPlayer}'s turn`;
114
+
115
+ return (
116
+ <ParticlesProvider init={init}>
117
+ <Particles id="tsparticles" options={particlesOptions} />
118
+ <div id="app">
119
+ <h1>Tic-Tac-Toe</h1>
120
+ <div class="scoreboard">
121
+ <span>X: <strong>{state.scores.X}</strong></span>
122
+ <span>Draws: <strong>{state.scores.draw}</strong></span>
123
+ <span>O: <strong>{state.scores.O}</strong></span>
124
+ </div>
125
+ <div class="turn">{status}</div>
126
+ <div class="board">
127
+ {state.board.map((cell, i) => (
128
+ <div
129
+ key={i}
130
+ class={`cell${cell ? " taken" : ""}${state.winLine?.includes(i) ? " win" : ""}`}
131
+ onClick={() => handleMove(i)}
132
+ >
133
+ {cell}
134
+ </div>
135
+ ))}
136
+ </div>
137
+ <button class="reset-btn" onClick={handleReset}>New Game</button>
138
+ </div>
139
+ </ParticlesProvider>
140
+ );
141
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "{{projectName}}",
3
+ "private": true,
4
+ "version": "1.0.0",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "tsc && vite build",
9
+ "preview": "vite preview"
10
+ },
11
+ "dependencies": {
12
+ "@builder.io/qwik": "^1.12.0",
13
+ "@tsparticles/qwik": "^4.1.3"
14
+ },
15
+ "devDependencies": {
16
+ "typescript": "~5.7.0",
17
+ "vite": "^6.0.0"
18
+ }
19
+ }
@@ -0,0 +1,132 @@
1
+ import { component$, useSignal, $ } from "@builder.io/qwik";
2
+ import Particles from "@tsparticles/qwik";
3
+ import { loadSlim } from "@tsparticles/slim";
4
+ import { confetti } from "@tsparticles/confetti";
5
+ import type { Engine, ISourceOptions } from "@tsparticles/engine";
6
+
7
+ type Player = "X" | "O";
8
+
9
+ const WIN_PATTERNS = [
10
+ [0, 1, 2], [3, 4, 5], [6, 7, 8],
11
+ [0, 3, 6], [1, 4, 7], [2, 5, 8],
12
+ [0, 4, 8], [2, 4, 6],
13
+ ];
14
+
15
+ function checkWin(board: (Player | null)[]): { winner: Player | "draw"; winLine: number[] } | null {
16
+ for (const pattern of WIN_PATTERNS) {
17
+ const [a, b, c] = pattern;
18
+ if (board[a] && board[a] === board[b] && board[a] === board[c]) {
19
+ return { winner: board[a] as Player, winLine: pattern };
20
+ }
21
+ }
22
+ if (board.every((cell) => cell !== null)) return { winner: "draw" as const, winLine: [] };
23
+ return null;
24
+ }
25
+
26
+ function fireConfettiEffect() {
27
+ const count = 200;
28
+ const defaults = { origin: { y: 0.7 } };
29
+ const fire = (particleRatio: number, opts: Record<string, unknown>) => {
30
+ confetti({ ...defaults, ...opts, particleCount: Math.floor(count * particleRatio) });
31
+ };
32
+ fire(0.25, { spread: 26, startVelocity: 55 });
33
+ fire(0.2, { spread: 60 });
34
+ fire(0.35, { spread: 100, decay: 0.91, scalar: 0.8 });
35
+ fire(0.1, { spread: 120, startVelocity: 25, decay: 0.92, scalar: 1.2 });
36
+ fire(0.1, { spread: 120, startVelocity: 45 });
37
+ }
38
+
39
+ async function init(engine: Engine): Promise<void> {
40
+ await loadSlim(engine);
41
+ }
42
+
43
+ const particlesOptions: ISourceOptions = {
44
+ fullScreen: { enable: true, zIndex: -1 },
45
+ background: { color: { value: "#0a0a1a" } },
46
+ fpsLimit: 60,
47
+ particles: {
48
+ number: { value: 30, density: { enable: true } },
49
+ color: { value: ["#6c5ce7", "#a29bfe"] },
50
+ shape: { type: "circle" },
51
+ opacity: { value: 0.2, random: true },
52
+ size: { value: { min: 1, max: 2 } },
53
+ move: { enable: true, speed: 0.5, direction: "none", random: true, straight: false, outModes: { default: "out" } },
54
+ },
55
+ detectRetina: true,
56
+ };
57
+
58
+ interface GameState {
59
+ board: (Player | null)[];
60
+ currentPlayer: Player;
61
+ winner: Player | "draw" | null;
62
+ winLine: number[] | null;
63
+ scores: { X: number; O: number; draw: number };
64
+ }
65
+
66
+ export default component$(() => {
67
+ const state = useSignal<GameState>({
68
+ board: Array(9).fill(null),
69
+ currentPlayer: "X",
70
+ winner: null,
71
+ winLine: null,
72
+ scores: { X: 0, O: 0, draw: 0 },
73
+ });
74
+
75
+ const handleMove = $((index: number) => {
76
+ const prev = state.value;
77
+ if (prev.board[index] || prev.winner) return;
78
+ const board = [...prev.board];
79
+ board[index] = prev.currentPlayer;
80
+ const result = checkWin(board);
81
+ if (result) {
82
+ const scores = { ...prev.scores };
83
+ if (result.winner === "draw") scores.draw++;
84
+ else scores[result.winner]++;
85
+ if (result.winner !== "draw") setTimeout(fireConfettiEffect, 100);
86
+ state.value = { ...prev, board, winner: result.winner, winLine: result.winLine, scores };
87
+ } else {
88
+ state.value = { ...prev, board, currentPlayer: prev.currentPlayer === "X" ? "O" : "X" };
89
+ }
90
+ });
91
+
92
+ const handleReset = $(() => {
93
+ state.value = {
94
+ ...state.value,
95
+ board: Array(9).fill(null),
96
+ currentPlayer: "X",
97
+ winner: null,
98
+ winLine: null,
99
+ };
100
+ });
101
+
102
+ const status = state.value.winner
103
+ ? state.value.winner === "draw" ? "It's a draw!" : `${state.value.winner} wins!`
104
+ : `${state.value.currentPlayer}'s turn`;
105
+
106
+ return (
107
+ <>
108
+ <Particles init={init} id="tsparticles" options={particlesOptions} />
109
+ <div id="app">
110
+ <h1>Tic-Tac-Toe</h1>
111
+ <div class="scoreboard">
112
+ <span>X: <strong>{state.value.scores.X}</strong></span>
113
+ <span>Draws: <strong>{state.value.scores.draw}</strong></span>
114
+ <span>O: <strong>{state.value.scores.O}</strong></span>
115
+ </div>
116
+ <div class="turn">{status}</div>
117
+ <div class="board">
118
+ {state.value.board.map((cell, i) => (
119
+ <div
120
+ key={i}
121
+ class={`cell${cell ? " taken" : ""}${state.value.winLine?.includes(i) ? " win" : ""}`}
122
+ onClick$={() => handleMove(i)}
123
+ >
124
+ {cell}
125
+ </div>
126
+ ))}
127
+ </div>
128
+ <button class="reset-btn" onClick$={handleReset}>New Game</button>
129
+ </div>
130
+ </>
131
+ );
132
+ });
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "{{projectName}}",
3
+ "private": true,
4
+ "version": "1.0.0",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "tsc && vite build",
9
+ "preview": "vite preview"
10
+ },
11
+ "dependencies": {
12
+ "react": "^19.2.5",
13
+ "react-dom": "^19.2.5",
14
+ "@tsparticles/react": "^4.1.3"
15
+ },
16
+ "devDependencies": {
17
+ "@vitejs/plugin-react": "^6.0.1"
18
+ }
19
+ }
@@ -0,0 +1,97 @@
1
+ * {
2
+ box-sizing: border-box;
3
+ }
4
+
5
+ body {
6
+ margin: 0;
7
+ min-height: 100vh;
8
+ display: flex;
9
+ align-items: center;
10
+ justify-content: center;
11
+ background: #0a0a1a;
12
+ font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
13
+ color: #fff;
14
+ }
15
+
16
+ #app {
17
+ text-align: center;
18
+ z-index: 10;
19
+ padding: 1rem;
20
+ }
21
+
22
+ h1 {
23
+ font-size: 2.5em;
24
+ margin-bottom: 1rem;
25
+ background: linear-gradient(135deg, #6c5ce7, #fd79a8);
26
+ -webkit-background-clip: text;
27
+ -webkit-text-fill-color: transparent;
28
+ background-clip: text;
29
+ }
30
+
31
+ .scoreboard {
32
+ display: flex;
33
+ justify-content: center;
34
+ gap: 2rem;
35
+ margin-bottom: 1rem;
36
+ font-size: 1.1em;
37
+ opacity: 0.8;
38
+ }
39
+
40
+ .turn {
41
+ font-size: 1.2em;
42
+ margin-bottom: 1rem;
43
+ opacity: 0.7;
44
+ }
45
+
46
+ .board {
47
+ display: grid;
48
+ grid-template-columns: repeat(3, 100px);
49
+ grid-template-rows: repeat(3, 100px);
50
+ gap: 4px;
51
+ background: rgba(255, 255, 255, 0.1);
52
+ border-radius: 12px;
53
+ overflow: hidden;
54
+ margin: 0 auto;
55
+ width: fit-content;
56
+ }
57
+
58
+ .cell {
59
+ display: flex;
60
+ align-items: center;
61
+ justify-content: center;
62
+ font-size: 2.5em;
63
+ font-weight: 700;
64
+ background: #12122a;
65
+ cursor: pointer;
66
+ transition: background 0.2s;
67
+ user-select: none;
68
+ }
69
+
70
+ .cell:hover {
71
+ background: #1a1a3a;
72
+ }
73
+
74
+ .cell.taken {
75
+ cursor: default;
76
+ }
77
+
78
+ .cell.win {
79
+ background: rgba(108, 92, 231, 0.3);
80
+ }
81
+
82
+ .reset-btn {
83
+ margin-top: 1.5rem;
84
+ padding: 0.7em 2em;
85
+ font-size: 1em;
86
+ font-weight: 600;
87
+ border: none;
88
+ border-radius: 8px;
89
+ background: linear-gradient(135deg, #6c5ce7, #a29bfe);
90
+ color: #fff;
91
+ cursor: pointer;
92
+ transition: transform 0.2s;
93
+ }
94
+
95
+ .reset-btn:hover {
96
+ transform: scale(1.05);
97
+ }
@@ -0,0 +1,141 @@
1
+ import { useState, useCallback } from "react";
2
+ import Particles, { ParticlesProvider } from "@tsparticles/react";
3
+ import { loadSlim } from "@tsparticles/slim";
4
+ import { confetti } from "@tsparticles/confetti";
5
+ import type { Engine, ISourceOptions } from "@tsparticles/engine";
6
+ import "./App.css";
7
+
8
+ type Player = "X" | "O";
9
+
10
+ interface GameState {
11
+ board: (Player | null)[];
12
+ currentPlayer: Player;
13
+ winner: Player | "draw" | null;
14
+ winLine: number[] | null;
15
+ scores: { X: number; O: number; draw: number };
16
+ }
17
+
18
+ const WIN_PATTERNS = [
19
+ [0, 1, 2], [3, 4, 5], [6, 7, 8],
20
+ [0, 3, 6], [1, 4, 7], [2, 5, 8],
21
+ [0, 4, 8], [2, 4, 6],
22
+ ];
23
+
24
+ function createInitialState(): GameState {
25
+ return {
26
+ board: Array(9).fill(null),
27
+ currentPlayer: "X",
28
+ winner: null,
29
+ winLine: null,
30
+ scores: { X: 0, O: 0, draw: 0 },
31
+ };
32
+ }
33
+
34
+ function checkWin(board: (Player | null)[]): { winner: Player | "draw"; winLine: number[] } | null {
35
+ for (const pattern of WIN_PATTERNS) {
36
+ const [a, b, c] = pattern;
37
+ if (board[a] && board[a] === board[b] && board[a] === board[c]) {
38
+ return { winner: board[a] as Player, winLine: pattern };
39
+ }
40
+ }
41
+ if (board.every((cell) => cell !== null)) {
42
+ return { winner: "draw" as const, winLine: [] };
43
+ }
44
+ return null;
45
+ }
46
+
47
+ function fireConfettiEffect() {
48
+ const count = 200;
49
+ const defaults = { origin: { y: 0.7 } };
50
+ const fire = (particleRatio: number, opts: Record<string, unknown>) => {
51
+ confetti({ ...defaults, ...opts, particleCount: Math.floor(count * particleRatio) });
52
+ };
53
+ fire(0.25, { spread: 26, startVelocity: 55 });
54
+ fire(0.2, { spread: 60 });
55
+ fire(0.35, { spread: 100, decay: 0.91, scalar: 0.8 });
56
+ fire(0.1, { spread: 120, startVelocity: 25, decay: 0.92, scalar: 1.2 });
57
+ fire(0.1, { spread: 120, startVelocity: 45 });
58
+ }
59
+
60
+ async function init(engine: Engine): Promise<void> {
61
+ await loadSlim(engine);
62
+ }
63
+
64
+ const particlesOptions: ISourceOptions = {
65
+ fullScreen: { enable: true, zIndex: -1 },
66
+ background: { color: { value: "#0a0a1a" } },
67
+ fpsLimit: 60,
68
+ particles: {
69
+ number: { value: 30, density: { enable: true } },
70
+ color: { value: ["#6c5ce7", "#a29bfe"] },
71
+ shape: { type: "circle" },
72
+ opacity: { value: 0.2, random: true },
73
+ size: { value: { min: 1, max: 2 } },
74
+ move: { enable: true, speed: 0.5, direction: "none", random: true, straight: false, outModes: { default: "out" } },
75
+ },
76
+ detectRetina: true,
77
+ };
78
+
79
+ export default function App() {
80
+ const [state, setState] = useState<GameState>(createInitialState);
81
+
82
+ const handleMove = useCallback((index: number) => {
83
+ setState((prev) => {
84
+ if (prev.board[index] || prev.winner) return prev;
85
+ const board = [...prev.board];
86
+ board[index] = prev.currentPlayer;
87
+ const result = checkWin(board);
88
+ if (result) {
89
+ const scores = { ...prev.scores };
90
+ if (result.winner === "draw") scores.draw++;
91
+ else scores[result.winner]++;
92
+ if (result.winner !== "draw") {
93
+ setTimeout(fireConfettiEffect, 100);
94
+ }
95
+ return { ...prev, board, winner: result.winner, winLine: result.winLine, scores };
96
+ }
97
+ return { ...prev, board, currentPlayer: prev.currentPlayer === "X" ? "O" : "X" };
98
+ });
99
+ }, []);
100
+
101
+ function handleReset() {
102
+ setState((prev) => ({
103
+ ...prev,
104
+ board: Array(9).fill(null),
105
+ currentPlayer: "X",
106
+ winner: null,
107
+ winLine: null,
108
+ }));
109
+ }
110
+
111
+ const status = state.winner
112
+ ? state.winner === "draw" ? "It's a draw!" : `${state.winner} wins!`
113
+ : `${state.currentPlayer}'s turn`;
114
+
115
+ return (
116
+ <ParticlesProvider init={init}>
117
+ <Particles id="tsparticles" options={particlesOptions} />
118
+ <div id="app">
119
+ <h1>Tic-Tac-Toe</h1>
120
+ <div className="scoreboard">
121
+ <span>X: <strong>{state.scores.X}</strong></span>
122
+ <span>Draws: <strong>{state.scores.draw}</strong></span>
123
+ <span>O: <strong>{state.scores.O}</strong></span>
124
+ </div>
125
+ <div className="turn">{status}</div>
126
+ <div className="board">
127
+ {state.board.map((cell, i) => (
128
+ <div
129
+ key={i}
130
+ className={`cell${cell ? " taken" : ""}${state.winLine?.includes(i) ? " win" : ""}`}
131
+ onClick={() => handleMove(i)}
132
+ >
133
+ {cell}
134
+ </div>
135
+ ))}
136
+ </div>
137
+ <button className="reset-btn" onClick={handleReset}>New Game</button>
138
+ </div>
139
+ </ParticlesProvider>
140
+ );
141
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "{{projectName}}",
3
+ "private": true,
4
+ "version": "1.0.0",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "vite build",
9
+ "preview": "vite preview"
10
+ },
11
+ "dependencies": {
12
+ "riot": "^10.0.0",
13
+ "@tsparticles/riot": "^4.1.3"
14
+ },
15
+ "devDependencies": {
16
+ "@riotjs/vite": "^1.0.0",
17
+ "vite": "^6.0.0",
18
+ "typescript": "~5.7.0"
19
+ }
20
+ }