Fun 15 Game
About this app
Play the exciting 15 puzzle game! Slide tiles around to arrange them in numerical order. Challenge yourself with this fun and interactive game!
Fun 15 Game 15 Puzzle Game!
Related apps
Put this on your site
Source
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Fun 15 Game</title>
<meta name="description" content="Play the exciting 15 puzzle game! Slide tiles around to arrange them in numerical order. Challenge yourself with this fun and interactive game!">
<meta name="keywords" content="15 puzzle game, slide tiles, fun game, interactive, numbers, brain teaser">
<!-- Libraries -->
<!-- jQuery (3.6.0) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js" crossorigin="anonymous"></script>
<!-- Bootstrap CSS (5.3.3) -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" crossorigin="anonymous">
<!-- Bootstrap JS (5.3.3) -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.min.js" crossorigin="anonymous">
</script>
<!-- Font Awesome (6.6.0) -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.6.0/css/fontawesome.min.css" crossorigin="anonymous">
<script type="text/javascript">
try {
// App Javascript Goes Here. Place your entire script content inside the try block for error handling.
const gridSize = 4;
let tiles = [];
let emptyTileIndex = gridSize * gridSize - 1;
function initGame() {
tiles = Array.from({length: gridSize * gridSize}, (_, i) => i);
shuffleTiles();
renderBoard();
}
function shuffleTiles() {
for (let i = tiles.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[tiles[i], tiles[j]] = [tiles[j], tiles[i]];
}
}
function renderBoard() {
const board = document.getElementById('game-board');
board.innerHTML = '';
tiles.forEach((tile, index) => {
const tileDiv = document.createElement('div');
tileDiv.className = 'tile';
if (tile !== 0) {
tileDiv.textContent = tile;
tileDiv.onclick = () => moveTile(index);
} else {
tileDiv.className += ' empty';
}
board.appendChild(tileDiv);
});
}
function moveTile(index) {
const emptyIndex = findAdjacent(index);
if (emptyIndex !== -1) {
[tiles[index], tiles[emptyIndex]] = [tiles[emptyIndex], tiles[index]];
renderBoard();
}
}
function findAdjacent(index) {
const adjacent = [
index - 1, // left
index + 1, // right
index - gridSize, // up
index + gridSize, // down
];
return adjacent.find(i => i === emptyTileIndex && isValidMove(index)) || -1;
}
function isValidMove(index) {
const col = index % gridSize;
const emptyCol = emptyTileIndex % gridSize;
return Math.abs(col - emptyCol) <= 1 && Math.floor(index / gridSize) === Math.floor(emptyTileIndex / gridSize) ||
Math.abs(Math.floor(index / gridSize) - Math.floor(emptyTileIndex / gridSize)) <= 1 && col === emptyCol;
}
document.addEventListener("DOMContentLoaded", function() {
initGame();
});
} catch (error) {
// This will throw the error to the parent window.
throw error;
}
</script>
<style>
/* App CSS Goes Here */
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background: linear-gradient(120deg, #ff9a9e 0%, #fad0c4 100%);
}
#main-container {
text-align: center;
}
#game-board {
display: grid;
grid-template-columns: repeat(4, 100px);
grid-template-rows: repeat(4, 100px);
gap: 5px;
margin: auto;
}
.tile {
display: flex;
justify-content: center;
align-items: center;
background: #4CAF50;
color: white;
font-size: 24px;
border-radius: 10px;
transition: transform 0.2s;
cursor: pointer;
}
.tile.empty {
background: transparent;
border: 2px dashed #ccc;
}
.tile:hover {
transform: scale(1.1);
}
h1 {
color: #333;
margin-bottom: 20px;
}
</style>
</head>
<body>
<div id="main-container" class="container">
<h1>15 Puzzle Game!</h1>
<div id="game-board"></div>
</div>
</body>
</html>
NEW APPS
These are apps made by the community!