diff --git a/src/main/java/stirling/software/SPDF/controller/api/other/OCRController.java b/src/main/java/stirling/software/SPDF/controller/api/other/OCRController.java index e7534b12..28b84f8c 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/other/OCRController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/other/OCRController.java @@ -54,7 +54,7 @@ public class OCRController { throws IOException, InterruptedException { // --output-type pdfa - if (selectedLanguages == null || selectedLanguages.size() < 1) { + if (selectedLanguages == null || selectedLanguages.isEmpty()) { throw new IOException("Please select at least one language."); } @@ -62,7 +62,7 @@ public class OCRController { List availableLanguages = getAvailableTesseractLanguages(); // Validate selected languages - selectedLanguages = selectedLanguages.stream().filter(availableLanguages::contains).collect(Collectors.toList()); + selectedLanguages = selectedLanguages.stream().filter(availableLanguages::contains).toList(); if (selectedLanguages.isEmpty()) { throw new IOException("None of the selected languages are valid."); diff --git a/src/main/resources/static/js/game.js b/src/main/resources/static/js/game.js index a38f860d..36cb5a5b 100644 --- a/src/main/resources/static/js/game.js +++ b/src/main/resources/static/js/game.js @@ -1,15 +1,22 @@ -document.addEventListener('DOMContentLoaded', function() { - +function initializeGame() { const gameContainer = document.getElementById('game-container'); const player = document.getElementById('player'); + + let playerSize = gameContainer.clientWidth * 0.0625; // 5% of container width + player.style.width = playerSize + 'px'; + player.style.height = playerSize + 'px'; + + let playerX = gameContainer.clientWidth / 2 - playerSize / 2; + let playerY = gameContainer.clientHeight * 0.1; const scoreElement = document.getElementById('score'); const levelElement = document.getElementById('level'); const livesElement = document.getElementById('lives'); const highScoreElement = document.getElementById('high-score'); + let pdfSize = gameContainer.clientWidth * 0.0625; // 5% of container width + let projectileWidth = gameContainer.clientWidth * 0.00625; // 0.5% of container width + let projectileHeight = gameContainer.clientHeight * 0.01667; // 1% of container height - let playerX = gameContainer.clientWidth / 2; - let playerY = 50; let paused = false; const fireRate = 200; // Time between shots in milliseconds let lastProjectileTime = 0; @@ -48,6 +55,9 @@ document.addEventListener('DOMContentLoaded', function() { document.addEventListener('keydown', (event) => { + if (event.key === ' ') { + event.preventDefault(); + } keysPressed[event.key] = true; handleKeys(); }); @@ -75,25 +85,29 @@ document.addEventListener('DOMContentLoaded', function() { const projectile = document.createElement('div'); projectile.classList.add('projectile'); projectile.style.backgroundColor = 'black'; - projectile.style.width = '5px'; - projectile.style.height = '10px'; - projectile.style.left = playerX + 20 + 'px'; - projectile.style.top = (gameContainer.clientHeight - playerY - 20) + 'px'; + projectile.style.width = projectileWidth + 'px'; + projectile.style.height = projectileHeight + 'px'; + projectile.style.left = (playerX + playerSize / 2 - projectileWidth / 2) + 'px'; + projectile.style.top = (gameContainer.clientHeight - playerY - playerSize) + 'px'; gameContainer.appendChild(projectile); projectiles.push(projectile); } + function spawnPdf() { const pdf = document.createElement('img'); pdf.src = 'images/file-earmark-pdf.svg'; pdf.classList.add('pdf'); - pdf.style.left = Math.floor(Math.random() * (gameContainer.clientWidth - 50)) + 'px'; + pdf.style.width = pdfSize + 'px'; + pdf.style.height = pdfSize + 'px'; + pdf.style.left = Math.floor(Math.random() * (gameContainer.clientWidth - pdfSize)) + 'px'; pdf.style.top = '0px'; gameContainer.appendChild(pdf); pdfs.push(pdf); } + function resetEnemies() { pdfs.forEach((pdf) => gameContainer.removeChild(pdf)); pdfs.length = 0; @@ -137,30 +151,7 @@ function resetEnemies() { } }); - function resetGame() { - playerX = gameContainer.clientWidth / 2; - playerY = 50; - updatePlayerPosition(); - - pdfs.forEach((pdf) => gameContainer.removeChild(pdf)); - projectiles.forEach((projectile) => gameContainer.removeChild(projectile)); - - pdfs.length = 0; - projectiles.length = 0; - - score = 0; - level = 1; - lives = 3; - pdfSpeed = 2; - gameOver = false; - - updateScore(); - updateLevel(); - updateLives(); - - setTimeout(updateGame, 1000 / 60); - spawnPdfInterval(); - } + @@ -189,7 +180,31 @@ function resetEnemies() { setTimeout(updateGame, 1000 / 60); } +function resetGame() { + playerX = gameContainer.clientWidth / 2; + playerY = 50; + updatePlayerPosition(); + pdfs.forEach((pdf) => gameContainer.removeChild(pdf)); + projectiles.forEach((projectile) => gameContainer.removeChild(projectile)); + + pdfs.length = 0; + projectiles.length = 0; + + score = 0; + level = 1; + lives = 3; + pdfSpeed = 1; + gameOver = false; + + updateScore(); + updateLives(); + levelElement.textContent = 'Level: ' + level; + + clearTimeout(spawnPdfTimeout); // Clear the existing spawnPdfTimeout + setTimeout(updateGame, 1000 / 60); + spawnPdfInterval(); +} @@ -228,7 +243,9 @@ function resetEnemies() { updateHighScore(); } alert('Game Over! Your final score is: ' + score); - resetGame(); + setTimeout(() => { // Wrap the resetGame() call in a setTimeout + resetGame(); + }, 0); } @@ -237,10 +254,13 @@ function resetEnemies() { let spawnPdfTimeout; function spawnPdfInterval() { + console.log("spawnPdfInterval"); if (gameOver || paused) { + console.log("spawnPdfInterval 2"); clearTimeout(spawnPdfTimeout); return; } + console.log("spawnPdfInterval 3"); spawnPdf(); spawnPdfTimeout = setTimeout(spawnPdfInterval, 1000 - level * 50); } @@ -261,4 +281,6 @@ function resetEnemies() { }); -}); \ No newline at end of file +} + +window.initializeGame = initializeGame; diff --git a/src/main/resources/templates/about.html b/src/main/resources/templates/about.html index 41cdcf0a..3f53c928 100644 --- a/src/main/resources/templates/about.html +++ b/src/main/resources/templates/about.html @@ -11,67 +11,7 @@
-
-
-
Lives: 3
-
Score: 0
-
High Score: 0
-
Level: 1
- -
- - -
-
+
diff --git a/src/main/resources/templates/fragments/common.html b/src/main/resources/templates/fragments/common.html index 6a8048a6..0e5118e5 100644 --- a/src/main/resources/templates/fragments/common.html +++ b/src/main/resources/templates/fragments/common.html @@ -102,144 +102,161 @@ document.addEventListener("DOMContentLoaded", function () { -
-
- - -
-
-
-
- - + + +
+
+ + +
+
+
+
+ + + + + + + + + +