<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Tic-Tac-Toe Neon</title>
<style>
*{box-sizing:border-box}
body{
margin:0;min-height:100vh;padding:20px 14px;
background:radial-gradient(ellipse at top,#172642,#080c16 70%);
color:#fff;font-family:Arial,sans-serif;
display:flex;justify-content:center;align-items:center
}
.app{width:100%;max-width:400px;text-align:center}
h1{font-size:30px;margin:0 0 7px}
h1 span{color:#42eaff;text-shadow:0 0 15px #42eaff}
.sub{color:#8d9ab4;font-size:14px;margin-bottom:23px}
.modes{display:flex;gap:9px;margin-bottom:18px}
button{font:inherit;cursor:pointer;touch-action:manipulation}
.mode{
flex:1;padding:12px 5px;border:1px solid #283750;
border-radius:12px;background:#111a2a;color:#aebbd2
}
.mode.active{border-color:#42eaff;color:#42eaff;background:#132637}
.status{
padding:14px;border-radius:12px;background:#111a2a;
border:1px solid #283750;margin-bottom:15px;color:#fff
}
#turn{font-weight:bold;color:#42eaff}
.board{
display:grid;grid-template-columns:repeat(3,1fr);gap:10px;
width:100%;aspect-ratio:1;margin-bottom:20px
}
.cell{
border:1px solid #283750;border-radius:16px;
background:linear-gradient(145deg,#151f32,#0d1422);
font-size:clamp(42px,15vw,64px);font-weight:bold;
display:flex;align-items:center;justify-content:center;
min-width:0;min-height:0;transition:background .15s
}
.cell:disabled{cursor:default}
.cell:not(:disabled):active{background:#1c3045}
.x{color:#42eaff;text-shadow:0 0 18px #42eaff}
.o{color:#ff5db1;text-shadow:0 0 18px #ff5db1}
.cell.win{background:#193a3b;border-color:#42eaff}
.scores{display:grid;grid-template-columns:repeat(3,1fr);gap:9px}
.score{
background:#111a2a;border:1px solid #283750;
border-radius:12px;padding:12px 4px
}
.num{font-size:25px;font-weight:bold;margin-bottom:5px}
.label{font-size:12px;color:#93a0b8}
.actions{display:flex;gap:9px;margin-top:17px}
.action{
flex:1;border:0;border-radius:12px;padding:14px 6px;
font-weight:bold
}
.primary{background:#42eaff;color:#07111d}
.secondary{background:#202b40;color:#fff;border:1px solid #34425c}
.note{font-size:12px;color:#75839c;margin-top:18px}
</style>
</head>
<body>
<main class="app">
<h1>❌ TIC <span>TAC</span> ⭕</h1>
<div class="sub">NEON EDITION · 3 × 3</div>
<div class="modes">
<button class="mode active" data-mode="bot">🤖 Против бота</button>
<button class="mode" data-mode="two">👥 Вдвоём</button>
</div>
<div class="status" aria-live="polite">
<span id="turn">Твой ход: ❌</span>
</div>
<div class="board" id="board">
<button class="cell" aria-label="Клетка 1"></button>
<button class="cell" aria-label="Клетка 2"></button>
<button class="cell" aria-label="Клетка 3"></button>
<button class="cell" aria-label="Клетка 4"></button>
<button class="cell" aria-label="Клетка 5"></button>
<button class="cell" aria-label="Клетка 6"></button>
<button class="cell" aria-label="Клетка 7"></button>
<button class="cell" aria-label="Клетка 8"></button>
<button class="cell" aria-label="Клетка 9"></button>
</div>
<div class="scores">
<div class="score"><div class="num x" id="sx">0</div><div class="label">❌ Крестики</div></div>
<div class="score"><div class="num" id="sd">0</div><div class="label">🤝 Ничьи</div></div>
<div class="score"><div class="num o" id="so">0</div><div class="label">⭕ Нолики</div></div>
</div>
<div class="actions">
<button class="action primary" id="restart">↻ Новая партия</button>
<button class="action secondary" id="reset">Сбросить счёт</button>
</div>
<div class="note">Сделай линию из трёх символов! ✨</div>
</main>
<script>
const cells=[...document.querySelectorAll('.cell')];
const turn=document.getElementById('turn');
const modes=[...document.querySelectorAll('.mode')];
const sx=document.getElementById('sx');
const so=document.getElementById('so');
const sd=document.getElementById('sd');
const lines=[
[0,1,2],[3,4,5],[6,7,8],
[0,3,6],[1,4,7],[2,5,8],
[0,4,8],[2,4,6]
];
let board=Array(9).fill('');
let mode='bot',current='X',over=false;
let scores={X:0,O:0,D:0};
function message(text){turn.textContent=text}
function winningLine(){
return lines.find(line=>
board[line[0]] &&
board[line[0]]===board[line[1]] &&
board[line[1]]===board[line[2]]
);
}
function render(win=[]){
cells.forEach((cell,i)=>{
cell.textContent=board[i]==='X'?'×':board[i]==='O'?'○':'';
cell.className='cell'+(board[i]?' '+board[i].toLowerCase():'')+
(win.includes(i)?' win':'');
cell.disabled=over||!!board[i]||(mode==='bot'&¤t==='O');
cell.setAttribute('aria-label',
'Клетка '+(i+1)+(board[i]?': '+board[i]:''));
});
sx.textContent=scores.X;
so.textContent=scores.O;
sd.textContent=scores.D;
}
function finish(){
const line=winningLine();
if(line){
over=true;
scores[board[line[0]]]++;
message(board[line[0]]==='X'?'🎉 Победили ❌ крестики!':'🎉 Победили ⭕ нолики!');
render(line);
return true;
}
if(board.every(Boolean)){
over=true;scores.D++;
message('🤝 Ничья! Отличная игра!');
render();
return true;
}
return false;
}
function play(i){
if(over||board[i]||(mode==='bot'&¤t==='O'))return;
board[i]=current;
if(finish())return;
current=current==='X'?'O':'X';
message(mode==='bot'?(current==='X'?'Твой ход: ❌':'Бот думает…'):
'Ход: '+(current==='X'?'❌ крестики':'⭕ нолики'));
render();
if(mode==='bot'&¤t==='O'){
cells.forEach(c=>c.disabled=true);
setTimeout(botMove,350);
}
}
function botMove(){
if(over||mode!=='bot'||current!=='O')return;
// Сначала ищет победу, затем блокирует игрока
function findMove(mark){
for(const line of lines){
const empty=line.filter(i=>!board[i]);
const used=line.filter(i=>board[i]===mark);
if(empty.length===1&&used.length===2)return empty[0];
}
return -1;
}
let move=findMove('O');
if(move<0)move=findMove('X');
if(move<0&& !board[4])move=4;
if(move<0){
const corners=[0,2,6,8].filter(i=>!board[i]);
if(corners.length)move=corners[Math.floor(Math.random()*corners.length)];
}
if(move<0){
const empty=board.map((v,i)=>v? -1:i).filter(i=>i>=0);
if(empty.length)move=empty[Math.floor(Math.random()*empty.length)];
}
if(move>=0){
board[move]='O';
if(finish())return;
current='X';
message('Твой ход: ❌');
render();
}
}
function newGame(){
board=Array(9).fill('');
current='X';over=false;
message(mode==='bot'?'Твой ход: ❌':'Ход: ❌ крестики');
render();
}
cells.forEach((cell,i)=>cell.addEventListener('click',()=>play(i)));
modes.forEach(btn=>btn.addEventListener('click',()=>{
mode=btn.dataset.mode;
modes.forEach(b=>b.classList.toggle('active',b===btn));
newGame();
}));
document.getElementById('restart').addEventListener('click',newGame);
document.getElementById('reset').addEventListener('click',()=>{
scores={X:0,O:0,D:0};
newGame();
});
render();
</script>
</body>
</html>