<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>Игра с буквами и призами</title>
<style>
body {
background-color: #f0f8ff;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
text-align: center;
margin: 0;
padding: 20px;
}
h1 {
color: #333;
}
#game-container {
display: inline-block;
margin-top: 20px;
}
.grid {
display: grid;
grid-template-columns: repeat(5, 80px);
grid-template-rows: repeat(5, 80px);
gap: 5px;
}
.cell {
width: 80px;
height: 80px;
border: 1px solid #ccc;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
font-size: 24px;
color: #fff;
position: relative;
transition: transform 0.2s;
}
.cell:active {
transform: scale(0.95);
}
.cell.opened {
cursor: default;
color: #000;
}
.cell.opened .letter {
font-size: 16px;
position: absolute;
top: 5px;
left: 5px;
}
.cell.opened .prize {
font-size: 14px;
position: absolute;
bottom: 5px;
}
/* Column colors */
.column-0 {
background-color: #fff;
color: #000;
}
.column-1 {
background-color: #ffd700;
}
.column-2 {
background-color: #90ee90;
}
.column-3 {
background-color: #ff6347;
}
.column-4 {
background-color: #1e90ff;
}
/* After game ends */
.cell.not-chosen {
opacity: 0.7;
}
#status {
margin-top: 20px;
font-size: 18px;
}
#reset-button {
margin-top: 20px;
padding: 10px 20px;
font-size: 16px;
background-color: #1e90ff;
color: #fff;
border: none;
cursor: pointer;
border-radius: 5px;
}
#reset-button:hover {
background-color: #1c86ee;
}
</style>
</head>
<body>
<h1>Игра с буквами и призами</h1>
<div id="game-container">
<div class="grid" id="grid">
<!-- Cells will be generated here -->
</div>
</div>
<div id="status">
Вы открыли <span id="opened-count">0</span> из 10 ячеек. Общий выигрыш: <span id="total-win">0</span> грн.
</div>
<button id="reset-button" onclick="resetGame()">Начать новую игру</button>
<script>
const letters = [
['А', 'Б', 'В', 'Г', 'Д'],
['Е', 'Ж', 'З', 'И', 'К'],
['Л', 'М', 'Н', 'О', 'П'],
['Р', 'С', 'Т', 'У', 'Ф'],
['Х', 'Ц', 'Ч', 'Ш', 'Я']
];
const columnColors = ['column-0', 'column-1', 'column-2', 'column-3', 'column-4'];
const maxOpens = 10;
let openedCells = 0;
let totalWin = 0;
let prizes = [];
let gridCells = [];
let thousandLineOpened = false;
let thousandLineCells = [];
let gameEnded = false;
function shuffleArray(array) {
for (let i = array.length -1; i >0; i--) {
const j = Math.floor(Math.random() * (i+1));
[array[i], array[j]] = [array[j], array[i]];
}
}
function generatePrizes() {
prizes = Array(25).fill(null);
// Prizes distribution
const prizeCounts = {
1000: 9,
2000: 5,
5000: 5,
10000: 2,
15000: 1,
25000: 1,
50000: 1,
200000:1
};
let prizeList = [];
for (const [prize, count] of Object.entries(prizeCounts)) {
for (let i = 0; i < count; i++) {
prizeList.push(parseInt(prize));
}
}
shuffleArray(prizeList);
// Place 1000 грн prizes in one horizontal and one diagonal line
let thousandCells = [];
// Random horizontal line
const randomRow = Math.floor(Math.random() * 5);
for (let col = 0; col < 5; col++) {
const index = randomRow * 5 + col;
prizes[index] = 1000;
thousandCells.push(index);
}
// Random diagonal line
const diagonals = [
[0,6,12,18,24], // top-left to bottom-right
[4,8,12,16,20] // top-right to bottom-left
];
const randomDiagonal = diagonals[Math.floor(Math.random() * 2)];
for (const index of randomDiagonal) {
if (prizes[index] !== 1000) {
prizes[index] = 1000;
thousandCells.push(index);
}
}
thousandLineCells = thousandCells;
// Assign remaining prizes to the remaining cells
let remainingIndices = [];
for (let i = 0; i < 25; i++) {
if (prizes[i] === null) {
remainingIndices.push(i);
}
}
let remainingPrizes = prizeList.slice(thousandCells.length);
for (let i = 0; i < remainingIndices.length; i++) {
prizes[remainingIndices[i]] = remainingPrizes[i];
}
}
function createGrid() {
const grid = document.getElementById('grid');
grid.innerHTML = '';
gridCells = [];
for (let row = 0; row < 5; row++) {
for (let col = 0; col < 5; col++) {
const cellIndex = row * 5 + col;
const cell = document.createElement('div');
cell.classList.add('cell', columnColors[col]);
cell.dataset.row = row;
cell.dataset.col = col;
cell.dataset.index = cellIndex;
cell.addEventListener('click', onCellClick);
grid.appendChild(cell);
gridCells.push(cell);
}
}
}
function onCellClick(event) {
if (gameEnded) return;
const cell = event.currentTarget;
if (cell.classList.contains('opened')) return;
if (openedCells >= maxOpens) return;
const index = parseInt(cell.dataset.index);
const row = parseInt(cell.dataset.row);
const col = parseInt(cell.dataset.col);
const letter = letters[row][col];
const prize = prizes[index];
cell.classList.add('opened');
cell.innerHTML = `<div class="letter">${letter}</div><div class="prize">${prize} грн</div>`;
openedCells++;
totalWin += prize;
updateStatus();
// Check if all thousand line cells are opened
if (!thousandLineOpened && thousandLineCells.every(i => gridCells[i].classList.contains('opened'))) {
thousandLineOpened = true;
// Double the prizes in thousand line cells
for (const idx of thousandLineCells) {
const cell = gridCells[idx];
const prizeElem = cell.querySelector('.prize');
const prizeValue = parseInt(prizeElem.textContent);
prizeElem.textContent = (prizeValue * 2) + ' грн';
totalWin += prizeValue; // Add the doubled amount
}
alert('Вы открыли всю линию с 1000 грн! Все призы в линии удваиваются!');
updateStatus();
}
if (openedCells >= maxOpens) {
endGame();
}
}
function updateStatus() {
document.getElementById('opened-count').textContent = openedCells;
document.getElementById('total-win').textContent = totalWin;
}
function endGame() {
gameEnded = true;
// Reveal all unopened cells
for (const cell of gridCells) {
if (!cell.classList.contains('opened')) {
const index = parseInt(cell.dataset.index);
const row = parseInt(cell.dataset.row);
const col = parseInt(cell.dataset.col);
const letter = letters[row][col];
const prize = prizes[index];
cell.classList.add('opened', 'not-chosen');
cell.innerHTML = `<div class="letter">${letter}</div><div class="prize">${prize} грн</div>`;
}
}
}
function resetGame() {
openedCells = 0;
totalWin = 0;
thousandLineOpened = false;
gameEnded = false;
generatePrizes();
createGrid();
updateStatus();
}
// Initialize the game
resetGame();
</script>
</body>
</html>