-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfieldtest.html
More file actions
96 lines (87 loc) · 2.3 KB
/
Copy pathfieldtest.html
File metadata and controls
96 lines (87 loc) · 2.3 KB
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
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8" />
<title>Простое игровое поле 15x15</title>
<style>
body {
font-family: sans-serif;
background: #222;
color: #eee;
padding: 20px;
user-select: none;
}
#game-board {
display: grid;
grid-template-columns: repeat(15, 30px);
grid-template-rows: repeat(15, 30px);
gap: 2px;
margin-bottom: 15px;
width: max-content;
border: 2px solid #444;
background: #111;
}
.cell {
width: 30px;
height: 30px;
background: #333;
border-radius: 3px;
cursor: pointer;
transition: background 0.3s;
display: flex;
align-items: center;
justify-content: center;
}
.cell:hover {
background: #555;
}
.tower {
background: crimson;
box-shadow: 0 0 5px crimson;
}
#status {
font-size: 16px;
}
</style>
</head>
<body>
<h1>Игровое поле 15x15 — ставим башни</h1>
<div id="game-board"></div>
<div id="status">Башен поставлено: 0</div>
<script>
const board = document.getElementById('game-board');
const status = document.getElementById('status');
// Массив состояния клеток: false — пустая, true — башня
const grid = new Array(15 * 15).fill(false);
// Создаем 15x15 клеток
for (let i = 0; i < 15 * 15; i++) {
const cell = document.createElement('div');
cell.classList.add('cell');
cell.dataset.index = i;
cell.addEventListener('click', () => {
// Переключаем состояние башни
grid[i] = !grid[i];
updateCell(i);
updateStatus();
});
board.appendChild(cell);
}
// Обновить визуально одну клетку
function updateCell(index) {
const cell = board.children[index];
if (grid[index]) {
cell.classList.add('tower');
cell.title = 'Башня';
} else {
cell.classList.remove('tower');
cell.title = '';
}
}
// Обновить статус с количеством башен
function updateStatus() {
const count = grid.filter(Boolean).length;
status.textContent = `Башен поставлено: ${count}`;
}
</script>
</body>
</html>