Puzzle Online

Witaj w świecie puzzli!
Sprawdź swoją spostrzegawczość, koncentrację i cierpliwość, układając losowo wybrane obrazy z rozsypanych fragmentów. Każda nowa gra to inne wyzwanie – obraz jest losowany po kliknięciu przycisku Wylosuj, aby rozpocząć układanie nowego wzoru.
Przed rozpoczęciem zabawy wybierz poziom trudności:
- Łatwy – mniejsza liczba elementów, idealna na szybkie rozgrywki oraz dla początkujących.
- Trudny – większa liczba fragmentów i znacznie większe wyzwanie dla miłośników łamigłówek.
Twoim zadaniem jest odtworzenie pełnego obrazu poprzez przeciąganie i zamienianie miejscami poszczególnych elementów układanki. Im wyższy poziom trudności, tym więcej puzzli do ułożenia i większa satysfakcja z ukończenia obrazka.
Czy uda Ci się ułożyć wszystkie elementy we właściwej kolejności i odkryć wylosowany obraz? Powodzenia!
Uwaga
Aplikacja nie jest przystosowana do pracy na urządzeniach mobilnych o szerokości ekranu mniejszej niż 440 px. Ograniczenie to dotyczy przede wszystkim smartfonów używanych w orientacji pionowej. Dla najlepszych wrażeń zalecane jest korzystanie z aplikacji na komputerze, tablecie lub telefonie w orientacji poziomej.
Kod po stronie przeglądarki
<style>
.preview{
width:300px;
height:300px;
margin:auto;
border:2px solid var(--bs-secondary);
background-size:cover;
background-position:center;
}
#board{
width:404px;
margin:auto;
display:grid;
grid-template-columns:repeat(4, 100px);
grid-template-rows:repeat(4, 100px);
gap:1px;
}
.slot{
width:100px;
height:100px;
background:transparent;
border:1px solid var(--bs-secondary);
}
.piece{
width:100%;
height:100%;
cursor:grab;
user-select:none;
}
.piece:hover{
opacity:0.9;
}
#message{
margin-top:20px;
text-align:center;
font-size:1.4rem;
font-weight:bold;
}
</style>
<div id="app">
<div class="row g-3 align-items-end mb-5">
<div class="col-12 col-md">
<label for="level" class="form-label">
Poziom trudności
</label>
<select class="form-select" id="level">
<option value="easy">Łatwy</option>
<option value="hard">Trudny</option>
</select>
</div>
<div class="col-12 col-md-auto">
<button id="btnShuffle" class="btn btn-primary w-100">
<i class="bi bi-shuffle me-1"></i>
Wylosuj obraz
</button>
</div>
</div>
<div id="loader" class="d-flex justify-content-center d-none">
<div class="spinner-border" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
<div id="puzzle" class="row g-4 d-none">
<div class="col-lg-4">
<h2 id="title" class="h5 mb-3 text-center"></h2>
<div id="preview" class="preview"></div>
</div>
<div class="col-lg-8">
<div id="board"></div>
</div>
</div>
<div id="message"></div>
</div>
<script>
const level = document.getElementById("level");
const loader = document.getElementById("loader");
const puzzle = document.getElementById("puzzle");
const board = document.getElementById("board");
const title = document.getElementById("title");
const message = document.getElementById("message");
const preview = document.getElementById("preview");
const btnShuffle = document.getElementById("btnShuffle");
let draggedPiece = null;
let shuffled = null;
let dialogShown = false;
const puzzleData = {
rows: 4,
cols: 4,
imageBase64: null,
pieces: []
};
const BOARD_SIZE = 400;
let TILE_SIZE = 100;
function setupPiecesData()
{
const lvl = level.value;
const mul = lvl === 'easy' ? 1 : 2;
puzzleData.rows = 4 * mul;
puzzleData.cols = 4 * mul;
puzzleData.pieces = [];
TILE_SIZE = BOARD_SIZE / puzzleData.cols
let id = 0;
for (let i = 0; i < 4 * mul; i++)
{
for (let j = 0; j < 4 * mul; j++)
{
const obj = {
id: id,
row: i,
col: j
}
puzzleData.pieces.push(obj);
id++;
}
}
}
function loadPuzzleData()
{
const params = {
level: level.value,
token: 'e54d8900d189faece52c956a6b9c8b1c0865ea70'
};
if (loader.classList.contains('d-none'))
{
loader.classList.remove('d-none');
}
if (!puzzle.classList.contains('d-none'))
{
puzzle.classList.add('d-none');
}
message.innerHTML = "";
dialogShown = false;
axios.post(urlSite('public/ajax/app/exec/52'), params,
{
headers:
{
'Content-Type': 'application/x-www-form-urlencoded'
}
})
.then(function(response)
{
const svg = response.data.svg;
title.textContent = response.data.title;
puzzleData.imageBase64 = "data:image/svg+xml;base64," + btoa(unescape(encodeURIComponent(svg))),
preview.style.backgroundImage = `url('${puzzleData.imageBase64}')`;
setupPiecesData();
shuffled = [...puzzleData.pieces].sort(() => Math.random() - 0.5);
createBoard();
if (!loader.classList.contains('d-none'))
{
loader.classList.add('d-none');
}
if (puzzle.classList.contains('d-none'))
{
puzzle.classList.remove('d-none');
}
}).catch(function(error)
{
BootstrapToast.error(error.response.data.message);
});
}
btnShuffle.addEventListener('click', function()
{
loadPuzzleData();
});
/* tworzenie planszy */
function createBoard()
{
const lvl = level.value;
board.innerHTML = '';
if (lvl === 'easy')
{
board.style.setProperty('grid-template-columns', 'repeat(4, 100px)');
board.style.setProperty('grid-template-rows', 'repeat(4, 100px)');
}
else
{
board.style.setProperty('grid-template-columns', 'repeat(8, 50px)');
board.style.setProperty('grid-template-rows', 'repeat(8, 50px)');
}
for (let position = 0; position < shuffled.length; position++)
{
const slot = document.createElement("div");
slot.className = "slot";
slot.style.width = lvl === 'easy' ? '100px' : '50px';
slot.style.height = lvl === 'easy' ? '100px' : '50px';
slot.dataset.position = position;
const piece =
createPiece(shuffled[position]);
slot.appendChild(piece);
slot.addEventListener("dragover", e =>
{
e.preventDefault();
});
slot.addEventListener("drop", e =>
{
e.preventDefault();
if (!draggedPiece) return;
const sourceSlot = draggedPiece.parentElement;
const targetSlot = slot;
if (sourceSlot === targetSlot)
{
return;
}
const targetPiece = targetSlot.firstElementChild;
sourceSlot.appendChild(targetPiece);
targetSlot.appendChild(draggedPiece);
draggedPiece = null;
checkWin();
});
board.appendChild(slot);
}
checkWin();
}
/* tworzenie kafelka */
function createPiece(pieceData)
{
const piece = document.createElement("div");
piece.className = "piece";
piece.draggable = true;
piece.dataset.id = pieceData.id;
piece.style.backgroundImage =
`url('${puzzleData.imageBase64}')`;
piece.style.backgroundSize =
`${BOARD_SIZE}px ${BOARD_SIZE}px`;
piece.style.backgroundPosition =
`-${pieceData.col * TILE_SIZE}px -${pieceData.row * TILE_SIZE}px`;
piece.addEventListener("dragstart", () =>
{
draggedPiece = piece;
});
return piece;
}
/* sprawdzenie zwycięstwa */
function checkWin()
{
const slots =
document.querySelectorAll(".slot");
let win = true;
slots.forEach((slot, index) =>
{
const piece = slot.firstElementChild;
if (!piece)
{
win = false;
return;
}
if (Number(piece.dataset.id) !== index)
{
win = false;
}
});
if (win)
{
if (!dialogShown)
{
BootstrapDialog.dialog(
{
title: '<i class="bi bi-trophy me-1"></i> Gratulacje!',
message: 'Puzzle zostały ułożone. Czy chcesz zagrać znowu?',
type: 'success',
onhide: function()
{
message.innerHTML = '<i class="bi bi-trophy me-1"></i> Gratulacje! Puzzle zostały ułożone.';
message.className = 'text-center text-success fw-bold mt-3';
},
buttons: [
{
type: 'btn-primary',
label: 'Tak, gramy dalej!',
action: function(dialogRef)
{
dialogRef.hide();
loadPuzzleData();
}
},
{
type: 'btn-secondary',
label: 'Nie, dziękuję.',
action: function(dialogRef)
{
dialogRef.hide();
}
}]
});
dialogShown = true;
}
}
else
{
message.innerHTML = "";
}
}
</script>
Kod po stronie serwera
Kod serwera niedostępny
Kod po stronie serwera tej aplikacji jest zamknięty i nie jest publicznie dostępny.
Licencja
## BSD-3-Clause License Agreement
BSD-3-Clause
Сopyright (c) 2026 Dariusz Rorat
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Kategorie
Technologie
Masz pomysł na podobną aplikację?
Chętnie pomogę zaplanować MVP, funkcjonalności oraz dalszy rozwój produktu.
Omówmy Twój pomysłNawet wstępny pomysł wystarczy, by rozpocząć rozmowę.