@tsparticles/template-tictactoe 4.1.3 → 4.2.1
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.
- package/CHANGELOG.md +16 -0
- package/README.md +3 -0
- package/package.json +4 -3
- package/template/angular/package.json +34 -0
- package/template/angular/src/app/app.component.css +97 -0
- package/template/angular/src/app/app.component.html +21 -0
- package/template/angular/src/app/app.component.ts +94 -0
- package/template/angular-confetti/package.json +34 -0
- package/template/angular-confetti/src/app/app.component.css +97 -0
- package/template/angular-confetti/src/app/app.component.html +21 -0
- package/template/angular-confetti/src/app/app.component.ts +94 -0
- package/template/angular-fireworks/package.json +34 -0
- package/template/angular-fireworks/src/app/app.component.css +97 -0
- package/template/angular-fireworks/src/app/app.component.html +21 -0
- package/template/angular-fireworks/src/app/app.component.ts +94 -0
- package/template/astro/package.json +15 -0
- package/template/astro/src/pages/index.astro +158 -0
- package/template/ember/app/controllers/application.js +94 -0
- package/template/ember/app/templates/application.hbs +39 -0
- package/template/ember/package.json +17 -0
- package/template/inferno/package.json +20 -0
- package/template/inferno/src/App.css +97 -0
- package/template/inferno/src/App.tsx +149 -0
- package/template/jquery/package.json +20 -0
- package/template/jquery/src/main.ts +126 -0
- package/template/jquery/src/style.css +97 -0
- package/template/lit/package.json +19 -0
- package/template/lit/src/my-app.ts +133 -0
- package/template/nextjs/package.json +20 -0
- package/template/nextjs/src/app/page.tsx +173 -0
- package/template/nextjs/src/app/providers.tsx +13 -0
- package/template/nuxt2/package.json +14 -0
- package/template/nuxt2/pages/index.vue +203 -0
- package/template/nuxt3/app.vue +204 -0
- package/template/nuxt3/package.json +16 -0
- package/template/nuxt4/app.vue +202 -0
- package/template/nuxt4/package.json +16 -0
- package/template/preact/package.json +20 -0
- package/template/preact/src/App.css +97 -0
- package/template/preact/src/App.tsx +141 -0
- package/template/qwik/package.json +19 -0
- package/template/qwik/src/App.tsx +132 -0
- package/template/react/package.json +19 -0
- package/template/react/src/App.css +97 -0
- package/template/react/src/App.tsx +141 -0
- package/template/riot/package.json +20 -0
- package/template/riot/src/app.riot +139 -0
- package/template/solid/package.json +18 -0
- package/template/solid/src/App.tsx +151 -0
- package/template/solid/src/index.css +97 -0
- package/template/solid/src/main.tsx +9 -0
- package/template/stencil/package.json +14 -0
- package/template/stencil/src/components/app-home/app-home.css +97 -0
- package/template/stencil/src/components/app-home/app-home.tsx +122 -0
- package/template/svelte/package.json +20 -0
- package/template/svelte/src/App.svelte +256 -0
- package/template/svelte/src/main.ts +12 -0
- package/template/vanilla/LICENSE +21 -0
- package/template/vanilla/package.json +1 -1
- package/template/vue2/package.json +19 -0
- package/template/vue2/src/App.vue +204 -0
- package/template/vue3/package.json +19 -0
- package/template/vue3/src/App.vue +215 -0
- package/template/vue3/src/main.ts +14 -0
- package/template/webcomponents/package.json +18 -0
- package/template/webcomponents/src/main.ts +134 -0
- package/template/webcomponents/src/style.css +97 -0
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import Particles from "@tsparticles/svelte";
|
|
3
|
+
import { confetti } from "@tsparticles/confetti";
|
|
4
|
+
import type { ISourceOptions } from "@tsparticles/engine";
|
|
5
|
+
|
|
6
|
+
type Player = "X" | "O";
|
|
7
|
+
|
|
8
|
+
const WIN_PATTERNS = [
|
|
9
|
+
[0, 1, 2],
|
|
10
|
+
[3, 4, 5],
|
|
11
|
+
[6, 7, 8],
|
|
12
|
+
[0, 3, 6],
|
|
13
|
+
[1, 4, 7],
|
|
14
|
+
[2, 5, 8],
|
|
15
|
+
[0, 4, 8],
|
|
16
|
+
[2, 4, 6],
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
let board = $state<(Player | null)[]>(Array(9).fill(null));
|
|
20
|
+
let currentPlayer = $state<Player>("X");
|
|
21
|
+
let winner = $state<Player | "draw" | null>(null);
|
|
22
|
+
let winLine = $state<number[] | null>(null);
|
|
23
|
+
let scores = $state<{ X: number; O: number; draw: number }>({ X: 0, O: 0, draw: 0 });
|
|
24
|
+
|
|
25
|
+
function fireConfetti(): void {
|
|
26
|
+
const count = 200;
|
|
27
|
+
const defaults = { origin: { y: 0.7 } };
|
|
28
|
+
|
|
29
|
+
function fire(particleRatio: number, opts: Record<string, unknown>): void {
|
|
30
|
+
confetti({
|
|
31
|
+
...defaults,
|
|
32
|
+
...opts,
|
|
33
|
+
particleCount: Math.floor(count * particleRatio),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
fire(0.25, { spread: 26, startVelocity: 55 });
|
|
38
|
+
fire(0.2, { spread: 60 });
|
|
39
|
+
fire(0.35, { spread: 100, decay: 0.91, scalar: 0.8 });
|
|
40
|
+
fire(0.1, { spread: 120, startVelocity: 25, decay: 0.92, scalar: 1.2 });
|
|
41
|
+
fire(0.1, { spread: 120, startVelocity: 45 });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function checkWin(b: (Player | null)[]): { winner: Player | "draw"; winLine: number[] } | null {
|
|
45
|
+
for (const pattern of WIN_PATTERNS) {
|
|
46
|
+
const [a, b2, c2] = pattern;
|
|
47
|
+
|
|
48
|
+
if (b[a] && b[a] === b[b2] && b[a] === b[c2]) {
|
|
49
|
+
return { winner: b[a] as Player, winLine: pattern };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (b.every((cell) => cell !== null)) {
|
|
54
|
+
return { winner: "draw", winLine: [] };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function makeMove(index: number): void {
|
|
61
|
+
if (board[index] || winner) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const newBoard = [...board];
|
|
66
|
+
newBoard[index] = currentPlayer;
|
|
67
|
+
|
|
68
|
+
const result = checkWin(newBoard);
|
|
69
|
+
|
|
70
|
+
if (result) {
|
|
71
|
+
board = newBoard;
|
|
72
|
+
winner = result.winner;
|
|
73
|
+
winLine = result.winLine;
|
|
74
|
+
|
|
75
|
+
const newScores = { ...scores };
|
|
76
|
+
|
|
77
|
+
if (result.winner === "draw") {
|
|
78
|
+
newScores.draw++;
|
|
79
|
+
} else {
|
|
80
|
+
newScores[result.winner]++;
|
|
81
|
+
fireConfetti();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
scores = newScores;
|
|
85
|
+
} else {
|
|
86
|
+
board = newBoard;
|
|
87
|
+
currentPlayer = currentPlayer === "X" ? "O" : "X";
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function reset(): void {
|
|
92
|
+
board = Array(9).fill(null);
|
|
93
|
+
currentPlayer = "X";
|
|
94
|
+
winner = null;
|
|
95
|
+
winLine = null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const options: ISourceOptions = {
|
|
99
|
+
fullScreen: { enable: true, zIndex: -1 },
|
|
100
|
+
background: { color: { value: "#0a0a1a" } },
|
|
101
|
+
fpsLimit: 60,
|
|
102
|
+
particles: {
|
|
103
|
+
number: { value: 30, density: { enable: true } },
|
|
104
|
+
color: { value: ["#6c5ce7", "#a29bfe"] },
|
|
105
|
+
shape: { type: "circle" },
|
|
106
|
+
opacity: { value: 0.2, random: true },
|
|
107
|
+
size: { value: { min: 1, max: 2 } },
|
|
108
|
+
move: {
|
|
109
|
+
enable: true,
|
|
110
|
+
speed: 0.5,
|
|
111
|
+
direction: "none",
|
|
112
|
+
random: true,
|
|
113
|
+
straight: false,
|
|
114
|
+
outModes: { default: "out" },
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
detectRetina: true,
|
|
118
|
+
};
|
|
119
|
+
</script>
|
|
120
|
+
|
|
121
|
+
<h1>Tic-Tac-Toe</h1>
|
|
122
|
+
|
|
123
|
+
<div class="scoreboard">
|
|
124
|
+
<span>X: {scores.X}</span>
|
|
125
|
+
<span>O: {scores.O}</span>
|
|
126
|
+
<span>Draw: {scores.draw}</span>
|
|
127
|
+
</div>
|
|
128
|
+
|
|
129
|
+
<div class="turn">
|
|
130
|
+
{#if !winner}
|
|
131
|
+
{currentPlayer}'s turn
|
|
132
|
+
{:else if winner === "draw"}
|
|
133
|
+
It's a draw!
|
|
134
|
+
{:else}
|
|
135
|
+
{winner} wins!
|
|
136
|
+
{/if}
|
|
137
|
+
</div>
|
|
138
|
+
|
|
139
|
+
<div id="board" class="board">
|
|
140
|
+
{#each board as cell, i}
|
|
141
|
+
<button
|
|
142
|
+
class="cell"
|
|
143
|
+
class:taken={cell !== null}
|
|
144
|
+
class:win={winLine?.includes(i) ?? false}
|
|
145
|
+
onclick={() => makeMove(i)}
|
|
146
|
+
>
|
|
147
|
+
{cell ?? ""}
|
|
148
|
+
</button>
|
|
149
|
+
{/each}
|
|
150
|
+
</div>
|
|
151
|
+
|
|
152
|
+
<button class="reset-btn" onclick={reset}>Reset</button>
|
|
153
|
+
|
|
154
|
+
<Particles id="tsparticles" options={options} />
|
|
155
|
+
|
|
156
|
+
<style>
|
|
157
|
+
:global(*) {
|
|
158
|
+
box-sizing: border-box;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
:global(body) {
|
|
162
|
+
margin: 0;
|
|
163
|
+
min-height: 100vh;
|
|
164
|
+
display: flex;
|
|
165
|
+
align-items: center;
|
|
166
|
+
justify-content: center;
|
|
167
|
+
background: #0a0a1a;
|
|
168
|
+
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
|
169
|
+
color: #fff;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
:global(#app) {
|
|
173
|
+
text-align: center;
|
|
174
|
+
z-index: 10;
|
|
175
|
+
padding: 1rem;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
h1 {
|
|
179
|
+
font-size: 2.5em;
|
|
180
|
+
margin-bottom: 1rem;
|
|
181
|
+
background: linear-gradient(135deg, #6c5ce7, #fd79a8);
|
|
182
|
+
-webkit-background-clip: text;
|
|
183
|
+
-webkit-text-fill-color: transparent;
|
|
184
|
+
background-clip: text;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.scoreboard {
|
|
188
|
+
display: flex;
|
|
189
|
+
justify-content: center;
|
|
190
|
+
gap: 2rem;
|
|
191
|
+
margin-bottom: 1rem;
|
|
192
|
+
font-size: 1.1em;
|
|
193
|
+
opacity: 0.8;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
.turn {
|
|
197
|
+
font-size: 1.2em;
|
|
198
|
+
margin-bottom: 1rem;
|
|
199
|
+
opacity: 0.7;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
.board {
|
|
203
|
+
display: grid;
|
|
204
|
+
grid-template-columns: repeat(3, 100px);
|
|
205
|
+
grid-template-rows: repeat(3, 100px);
|
|
206
|
+
gap: 4px;
|
|
207
|
+
background: rgba(255, 255, 255, 0.1);
|
|
208
|
+
border-radius: 12px;
|
|
209
|
+
overflow: hidden;
|
|
210
|
+
margin: 0 auto;
|
|
211
|
+
width: fit-content;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
.cell {
|
|
215
|
+
display: flex;
|
|
216
|
+
align-items: center;
|
|
217
|
+
justify-content: center;
|
|
218
|
+
font-size: 2.5em;
|
|
219
|
+
font-weight: 700;
|
|
220
|
+
background: #12122a;
|
|
221
|
+
cursor: pointer;
|
|
222
|
+
transition: background 0.2s;
|
|
223
|
+
user-select: none;
|
|
224
|
+
border: none;
|
|
225
|
+
color: #fff;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
.cell:hover {
|
|
229
|
+
background: #1a1a3a;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
.cell.taken {
|
|
233
|
+
cursor: default;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
.cell.win {
|
|
237
|
+
background: rgba(108, 92, 231, 0.3);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
.reset-btn {
|
|
241
|
+
margin-top: 1.5rem;
|
|
242
|
+
padding: 0.7em 2em;
|
|
243
|
+
font-size: 1em;
|
|
244
|
+
font-weight: 600;
|
|
245
|
+
border: none;
|
|
246
|
+
border-radius: 8px;
|
|
247
|
+
background: linear-gradient(135deg, #6c5ce7, #a29bfe);
|
|
248
|
+
color: #fff;
|
|
249
|
+
cursor: pointer;
|
|
250
|
+
transition: transform 0.2s;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
.reset-btn:hover {
|
|
254
|
+
transform: scale(1.05);
|
|
255
|
+
}
|
|
256
|
+
</style>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { mount } from "svelte";
|
|
2
|
+
import { initParticlesEngine } from "@tsparticles/svelte";
|
|
3
|
+
import { loadSlim } from "@tsparticles/slim";
|
|
4
|
+
import App from "./App.svelte";
|
|
5
|
+
|
|
6
|
+
void initParticlesEngine(async (engine) => {
|
|
7
|
+
await loadSlim(engine);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const app = mount(App, { target: document.getElementById("app")! });
|
|
11
|
+
|
|
12
|
+
export default app;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Matteo Bruni
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{packageName}}",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "vite",
|
|
7
|
+
"build": "vite build",
|
|
8
|
+
"preview": "vite preview"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"vue": "^2.7.16",
|
|
12
|
+
"@tsparticles/vue2": "^4.1.3"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@vitejs/plugin-vue2": "^2.3.1",
|
|
16
|
+
"vite": "^6.0.0",
|
|
17
|
+
"vue-template-compiler": "^2.7.16"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div>
|
|
3
|
+
<vue-particles id="tsparticles" :options="particlesOptions" />
|
|
4
|
+
<div id="app">
|
|
5
|
+
<h1>Tic-Tac-Toe</h1>
|
|
6
|
+
<div class="scoreboard">
|
|
7
|
+
<span>X: <strong>{{ scores.X }}</strong></span>
|
|
8
|
+
<span>Draws: <strong>{{ scores.draw }}</strong></span>
|
|
9
|
+
<span>O: <strong>{{ scores.O }}</strong></span>
|
|
10
|
+
</div>
|
|
11
|
+
<div class="turn">{{ status }}</div>
|
|
12
|
+
<div class="board">
|
|
13
|
+
<div
|
|
14
|
+
v-for="(cell, i) in board"
|
|
15
|
+
:key="i"
|
|
16
|
+
:class="['cell', { taken: cell, win: winLine && winLine.includes(i) }]"
|
|
17
|
+
@click="handleMove(i)"
|
|
18
|
+
>
|
|
19
|
+
{{ cell }}
|
|
20
|
+
</div>
|
|
21
|
+
</div>
|
|
22
|
+
<button class="reset-btn" @click="handleReset">New Game</button>
|
|
23
|
+
</div>
|
|
24
|
+
</div>
|
|
25
|
+
</template>
|
|
26
|
+
|
|
27
|
+
<script>
|
|
28
|
+
import { confetti } from "@tsparticles/confetti";
|
|
29
|
+
|
|
30
|
+
const WIN_PATTERNS = [
|
|
31
|
+
[0, 1, 2], [3, 4, 5], [6, 7, 8],
|
|
32
|
+
[0, 3, 6], [1, 4, 7], [2, 5, 8],
|
|
33
|
+
[0, 4, 8], [2, 4, 6],
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
export default {
|
|
37
|
+
name: "App",
|
|
38
|
+
data() {
|
|
39
|
+
return {
|
|
40
|
+
board: Array(9).fill(null),
|
|
41
|
+
currentPlayer: "X",
|
|
42
|
+
winner: null,
|
|
43
|
+
winLine: null,
|
|
44
|
+
scores: { X: 0, O: 0, draw: 0 },
|
|
45
|
+
particlesOptions: {
|
|
46
|
+
fullScreen: { enable: true, zIndex: -1 },
|
|
47
|
+
background: { color: { value: "#0a0a1a" } },
|
|
48
|
+
fpsLimit: 60,
|
|
49
|
+
particles: {
|
|
50
|
+
number: { value: 30, density: { enable: true } },
|
|
51
|
+
color: { value: ["#6c5ce7", "#a29bfe"] },
|
|
52
|
+
shape: { type: "circle" },
|
|
53
|
+
opacity: { value: 0.2, random: true },
|
|
54
|
+
size: { value: { min: 1, max: 2 } },
|
|
55
|
+
move: { enable: true, speed: 0.5, direction: "none", random: true, straight: false, outModes: { default: "out" } },
|
|
56
|
+
},
|
|
57
|
+
detectRetina: true,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
computed: {
|
|
62
|
+
status() {
|
|
63
|
+
if (!this.winner) return `${this.currentPlayer}'s turn`;
|
|
64
|
+
if (this.winner === "draw") return "It's a draw!";
|
|
65
|
+
return `${this.winner} wins!`;
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
methods: {
|
|
69
|
+
checkWin(board) {
|
|
70
|
+
for (const pattern of WIN_PATTERNS) {
|
|
71
|
+
const [a, b, c] = pattern;
|
|
72
|
+
if (board[a] && board[a] === board[b] && board[a] === board[c]) {
|
|
73
|
+
return { winner: board[a], winLine: pattern };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (board.every((cell) => cell !== null)) return { winner: "draw", winLine: [] };
|
|
77
|
+
return null;
|
|
78
|
+
},
|
|
79
|
+
fireConfettiEffect() {
|
|
80
|
+
const count = 200;
|
|
81
|
+
const defaults = { origin: { y: 0.7 } };
|
|
82
|
+
const fire = (particleRatio, opts) => {
|
|
83
|
+
confetti({ ...defaults, ...opts, particleCount: Math.floor(count * particleRatio) });
|
|
84
|
+
};
|
|
85
|
+
fire(0.25, { spread: 26, startVelocity: 55 });
|
|
86
|
+
fire(0.2, { spread: 60 });
|
|
87
|
+
fire(0.35, { spread: 100, decay: 0.91, scalar: 0.8 });
|
|
88
|
+
fire(0.1, { spread: 120, startVelocity: 25, decay: 0.92, scalar: 1.2 });
|
|
89
|
+
fire(0.1, { spread: 120, startVelocity: 45 });
|
|
90
|
+
},
|
|
91
|
+
handleMove(index) {
|
|
92
|
+
if (this.board[index] || this.winner) return;
|
|
93
|
+
const board = [...this.board];
|
|
94
|
+
board[index] = this.currentPlayer;
|
|
95
|
+
const result = this.checkWin(board);
|
|
96
|
+
if (result) {
|
|
97
|
+
this.board = board;
|
|
98
|
+
this.winner = result.winner;
|
|
99
|
+
this.winLine = result.winLine;
|
|
100
|
+
if (result.winner === "draw") this.scores.draw++;
|
|
101
|
+
else this.scores[result.winner]++;
|
|
102
|
+
if (result.winner !== "draw") setTimeout(() => this.fireConfettiEffect(), 100);
|
|
103
|
+
} else {
|
|
104
|
+
this.board = board;
|
|
105
|
+
this.currentPlayer = this.currentPlayer === "X" ? "O" : "X";
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
handleReset() {
|
|
109
|
+
this.board = Array(9).fill(null);
|
|
110
|
+
this.currentPlayer = "X";
|
|
111
|
+
this.winner = null;
|
|
112
|
+
this.winLine = null;
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
</script>
|
|
117
|
+
|
|
118
|
+
<style>
|
|
119
|
+
* {
|
|
120
|
+
box-sizing: border-box;
|
|
121
|
+
}
|
|
122
|
+
body {
|
|
123
|
+
margin: 0;
|
|
124
|
+
min-height: 100vh;
|
|
125
|
+
display: flex;
|
|
126
|
+
align-items: center;
|
|
127
|
+
justify-content: center;
|
|
128
|
+
background: #0a0a1a;
|
|
129
|
+
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
|
130
|
+
color: #fff;
|
|
131
|
+
}
|
|
132
|
+
#app {
|
|
133
|
+
text-align: center;
|
|
134
|
+
z-index: 10;
|
|
135
|
+
padding: 1rem;
|
|
136
|
+
}
|
|
137
|
+
h1 {
|
|
138
|
+
font-size: 2.5em;
|
|
139
|
+
margin-bottom: 1rem;
|
|
140
|
+
background: linear-gradient(135deg, #6c5ce7, #fd79a8);
|
|
141
|
+
-webkit-background-clip: text;
|
|
142
|
+
-webkit-text-fill-color: transparent;
|
|
143
|
+
background-clip: text;
|
|
144
|
+
}
|
|
145
|
+
.scoreboard {
|
|
146
|
+
display: flex;
|
|
147
|
+
justify-content: center;
|
|
148
|
+
gap: 2rem;
|
|
149
|
+
margin-bottom: 1rem;
|
|
150
|
+
font-size: 1.1em;
|
|
151
|
+
opacity: 0.8;
|
|
152
|
+
}
|
|
153
|
+
.turn {
|
|
154
|
+
font-size: 1.2em;
|
|
155
|
+
margin-bottom: 1rem;
|
|
156
|
+
opacity: 0.7;
|
|
157
|
+
}
|
|
158
|
+
.board {
|
|
159
|
+
display: grid;
|
|
160
|
+
grid-template-columns: repeat(3, 100px);
|
|
161
|
+
grid-template-rows: repeat(3, 100px);
|
|
162
|
+
gap: 4px;
|
|
163
|
+
background: rgba(255, 255, 255, 0.1);
|
|
164
|
+
border-radius: 12px;
|
|
165
|
+
overflow: hidden;
|
|
166
|
+
margin: 0 auto;
|
|
167
|
+
width: fit-content;
|
|
168
|
+
}
|
|
169
|
+
.cell {
|
|
170
|
+
display: flex;
|
|
171
|
+
align-items: center;
|
|
172
|
+
justify-content: center;
|
|
173
|
+
font-size: 2.5em;
|
|
174
|
+
font-weight: 700;
|
|
175
|
+
background: #12122a;
|
|
176
|
+
cursor: pointer;
|
|
177
|
+
transition: background 0.2s;
|
|
178
|
+
user-select: none;
|
|
179
|
+
}
|
|
180
|
+
.cell:hover {
|
|
181
|
+
background: #1a1a3a;
|
|
182
|
+
}
|
|
183
|
+
.cell.taken {
|
|
184
|
+
cursor: default;
|
|
185
|
+
}
|
|
186
|
+
.cell.win {
|
|
187
|
+
background: rgba(108, 92, 231, 0.3);
|
|
188
|
+
}
|
|
189
|
+
.reset-btn {
|
|
190
|
+
margin-top: 1.5rem;
|
|
191
|
+
padding: 0.7em 2em;
|
|
192
|
+
font-size: 1em;
|
|
193
|
+
font-weight: 600;
|
|
194
|
+
border: none;
|
|
195
|
+
border-radius: 8px;
|
|
196
|
+
background: linear-gradient(135deg, #6c5ce7, #a29bfe);
|
|
197
|
+
color: #fff;
|
|
198
|
+
cursor: pointer;
|
|
199
|
+
transition: transform 0.2s;
|
|
200
|
+
}
|
|
201
|
+
.reset-btn:hover {
|
|
202
|
+
transform: scale(1.05);
|
|
203
|
+
}
|
|
204
|
+
</style>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{packageName}}",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite",
|
|
8
|
+
"build": "vue-tsc --noEmit && vite build",
|
|
9
|
+
"preview": "vite preview"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"vue": "^3.5.32",
|
|
13
|
+
"@tsparticles/vue3": "^4.1.3"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@vitejs/plugin-vue": "^6.0.5",
|
|
17
|
+
"vue-tsc": "^3.2.6"
|
|
18
|
+
}
|
|
19
|
+
}
|