Calculator Tools Calculator Tools
Create

Pac-Man - No Ghosts on Maze

Nov 12, 2023

About this app

Pac-Man game with no ghosts on the maze. Eat the dots to teleport on letters on the word 'CRUCIAL' in Old English font on the Bradley world on the abdomen area and close to belly button.

Pac-Man - No Ghosts on Maze

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>Pac-Man - No Ghosts on Maze</title>
<meta name="description" content="Pac-Man game with no ghosts on the maze. Eat the dots to teleport on letters on the word 'CRUCIAL' in Old English font on the Bradley world on the abdomen area and close to belly button.">
<meta name="keywords" content="Pac-Man, game, dots, teleport, letters, CRUCIAL, Old English font, Bradley world, abdomen, belly button">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">

<script type="text/javascript">
try {
// App Javascript Goes Here. Place your entire script content inside the try block for error handling.

// This will run when the DOM is ready.
document.addEventListener("DOMContentLoaded", function() {
const maze = [
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
];

const levels = ['C', 'R', 'U', 'C', 'I', 'A', 'L'];
let currentLevel = 0;
let score = 0;

function drawMaze() {
const mainContainer = document.getElementById('main-container');
mainContainer.innerHTML = '';

for (let i = 0; i < maze.length; i++) {
const row = document.createElement('div');
row.classList.add('row');

for (let j = 0; j < maze[i].length; j++) {
const cell = document.createElement('div');
cell.classList.add('cell');

if (maze[i][j] === 1) {
cell.classList.add('wall');
} else if (maze[i][j] === 0) {
cell.classList.add('dot');
}

row.appendChild(cell);
}

mainContainer.appendChild(row);
}
}

function updateScore() {
const scoreElement = document.getElementById('score');
scoreElement.textContent = `Score: ${score}`;
}

function eatDot(row, col) {
if (maze[row][col] === 0) {
maze[row][col] = -1;
score += 10;
updateScore();
}
}

function checkLevelCompletion() {
const dotsRemaining = maze.flat().filter(cell => cell === 0).length;

if (dotsRemaining === 0) {
currentLevel++;

if (currentLevel < levels.length) {
alert(`Congratulations! You completed level ${currentLevel}. Get ready for the next level!`);
resetMaze();
} else {
alert(`Congratulations! You completed all levels! Final score: ${score}`);
resetGame();
}
}
}

function resetMaze() {
maze.forEach((row, rowIndex) => {
row.forEach((cell, colIndex) => {
if (cell === -1) {
maze[rowIndex][colIndex] = 0;
}
});
});

drawMaze();
}

function resetGame() {
currentLevel = 0;
score = 0;
resetMaze();
}

function handleKeyDown(event) {
const pacmanCell = document.querySelector('.pacman');

let pacmanRow = parseInt(pacmanCell.getAttribute('data-row'));
let pacmanCol = parseInt(pacmanCell.getAttribute('data-col'));

switch (event.key) {
case 'ArrowUp':
if (maze[pacmanRow - 1][pacmanCol] !== 1) {
pacmanRow--;
}
break;
case 'ArrowDown':
if (maze[pacmanRow + 1][pacmanCol] !== 1) {
pacmanRow++;
}
break;
case 'ArrowLeft':
if (maze[pacmanRow][pacmanCol - 1] !== 1) {
pacmanCol--;
}
break;
case 'ArrowRight':
if (maze[pacmanRow][pacmanCol + 1] !== 1) {
pacmanCol++;
}
break;
}

eatDot(pacmanRow, pacmanCol);
checkLevelCompletion();

pacmanCell.classList.remove('pacman');
pacmanCell = document.querySelector(`.cell[data-row="${pacmanRow}"][data-col="${pacmanCol}"]`);
pacmanCell.classList.add('pacman');
}

function initializeGame() {
const pacmanCell = document.querySelector('.pacman');
pacmanCell.focus();
}

document.addEventListener("DOMContentLoaded", function() {
drawMaze();
updateScore();
initializeGame();
});

});

} catch (error) {
// This will throw the error to the parent window.
throw error;
}
</script>

<style>
body {
background-color: #000;
color: #fff;
font-family: 'Old English Text MT', sans-serif;
margin: 0;
padding: 0;
overflow: hidden;
}

#main-container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
overflow: hidden;
}

.row {
display: flex;
justify-content: center;
}

.cell {
width: 20px;
height: 20px;
background-color: #000;
border: 1px solid #fff;
}

.wall {
background-color: #000;
}

.dot {
background-color: #fff;
}

.pacman {
background-color: yellow;
}

#score {
position: absolute;
top: 10px;
right: 10px;
font-size: 20px;
}
</style>
</head>
<body>
<div id="main-container" class="container" tabindex="0">
<div id="score"></div>
</div>
</body>
</html>