github verknüpfung und neuses snake
This commit is contained in:
parent
7013e330ac
commit
75aca82533
1
icons/envelope-solid.svg
Normal file
1
icons/envelope-solid.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M48 64C21.5 64 0 85.5 0 112c0 15.1 7.1 29.3 19.2 38.4L236.8 313.6c11.4 8.5 27 8.5 38.4 0L492.8 150.4c12.1-9.1 19.2-23.3 19.2-38.4c0-26.5-21.5-48-48-48L48 64zM0 176L0 384c0 35.3 28.7 64 64 64l384 0c35.3 0 64-28.7 64-64l0-208L294.4 339.2c-22.8 17.1-54 17.1-76.8 0L0 176z"/></svg>
|
After Width: | Height: | Size: 499 B |
1
icons/github-alt-brands.svg
Normal file
1
icons/github-alt-brands.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 480 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path fill="#000000" d="M186.1 328.7c0 20.9-10.9 55.1-36.7 55.1s-36.7-34.2-36.7-55.1 10.9-55.1 36.7-55.1 36.7 34.2 36.7 55.1zM480 278.2c0 31.9-3.2 65.7-17.5 95-37.9 76.6-142.1 74.8-216.7 74.8-75.8 0-186.2 2.7-225.6-74.8-14.6-29-20.2-63.1-20.2-95 0-41.9 13.9-81.5 41.5-113.6-5.2-15.8-7.7-32.4-7.7-48.8 0-21.5 4.9-32.3 14.6-51.8 45.3 0 74.3 9 108.8 36 29-6.9 58.8-10 88.7-10 27 0 54.2 2.9 80.4 9.2 34-26.7 63-35.2 107.8-35.2 9.8 19.5 14.6 30.3 14.6 51.8 0 16.4-2.6 32.7-7.7 48.2 27.5 32.4 39 72.3 39 114.2zm-64.3 50.5c0-43.9-26.7-82.6-73.5-82.6-18.9 0-37 3.4-56 6-14.9 2.3-29.8 3.2-45.1 3.2-15.2 0-30.1-.9-45.1-3.2-18.7-2.6-37-6-56-6-46.8 0-73.5 38.7-73.5 82.6 0 87.8 80.4 101.3 150.4 101.3h48.2c70.3 0 150.6-13.4 150.6-101.3zm-82.6-55.1c-25.8 0-36.7 34.2-36.7 55.1s10.9 55.1 36.7 55.1 36.7-34.2 36.7-55.1-10.9-55.1-36.7-55.1z"/></svg>
|
After Width: | Height: | Size: 1.0 KiB |
17
index.html
17
index.html
@ -85,6 +85,8 @@
|
|||||||
color="black"
|
color="black"
|
||||||
></l-quantum>
|
></l-quantum>
|
||||||
</div>
|
</div>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
|
||||||
<!-- Deine anderen Inhalte hier -->
|
<!-- Deine anderen Inhalte hier -->
|
||||||
<h1><img src="/icons/Controller.png" height="150svh">
|
<h1><img src="/icons/Controller.png" height="150svh">
|
||||||
@ -92,6 +94,19 @@
|
|||||||
Creative Crafter</h1>
|
Creative Crafter</h1>
|
||||||
<h3>Hey there! I'm Creative Crafter, your go-to gamer. On this website, I showcase my latest and greatest games.<br/>
|
<h3>Hey there! I'm Creative Crafter, your go-to gamer. On this website, I showcase my latest and greatest games.<br/>
|
||||||
Note: All games are available in German <span>🇩🇪</span> only. Enjoy the adventure!</h3>
|
Note: All games are available in German <span>🇩🇪</span> only. Enjoy the adventure!</h3>
|
||||||
|
<br>
|
||||||
|
<header>
|
||||||
|
<div style="display: flex; gap: 10px; align-items: center;">
|
||||||
|
<a href="https://github.com/Creative-Crafter" target="_blank">
|
||||||
|
<img src="/icons/github-alt-brands.svg" height="25" alt="GitHub" style="cursor: pointer;" />
|
||||||
|
</a>
|
||||||
|
<a href="mailto:info@creative-crafter.de">
|
||||||
|
<img src="/icons/email.svg" height="25" alt="E-Mail" style="cursor: pointer;" />
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<br>
|
||||||
<h2><img src="/icons/spiele.png" height="25vh">Categories</h2>
|
<h2><img src="/icons/spiele.png" height="25vh">Categories</h2>
|
||||||
|
|
||||||
<!-- Button hinzufügen -->
|
<!-- Button hinzufügen -->
|
||||||
@ -107,7 +122,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<footer><a href="mailto:info@creative-crafter.de">info@creative-crafter.de</a> | <i id="footer-text"></i></footer>
|
<footer><i id="footer-text"></i></footer>
|
||||||
<script>
|
<script>
|
||||||
// Ladeanimation beim Laden der Seite anzeigen
|
// Ladeanimation beim Laden der Seite anzeigen
|
||||||
document.body.classList.add('loading');
|
document.body.classList.add('loading');
|
||||||
|
@ -1,51 +1,222 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<!-- saved from url=(0060)https://test.creative-crafter.de/programmieren/spiele/Snake/ -->
|
<html lang="en">
|
||||||
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
<title>Snake Game</title>
|
<title>Snake Game</title>
|
||||||
<style>
|
<style>
|
||||||
body { display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background-color: #000; }
|
* { box-sizing: border-box; }
|
||||||
canvas { border: 1px solid #fff; }
|
body {
|
||||||
#startScreen { display: none; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: white; text-align: center; }
|
margin: 0;
|
||||||
|
background: linear-gradient(135deg, #3498db, #9b59b6);
|
||||||
|
color: white;
|
||||||
|
font-family: "Coda", system-ui;
|
||||||
|
font-weight: 800;
|
||||||
|
font-style: normal;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 100vh;
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
canvas {
|
||||||
|
border: 4px solid #ffffff81;
|
||||||
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
|
||||||
|
background-color: #2c3e5085;
|
||||||
|
}
|
||||||
|
#overlay {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
text-align: center;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
#overlay h1 {
|
||||||
|
font-size: 3em;
|
||||||
|
margin-bottom: 0.5em;
|
||||||
|
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.7);
|
||||||
|
}
|
||||||
|
#scoreboard {
|
||||||
|
position: absolute;
|
||||||
|
top: 20px;
|
||||||
|
left: 20px;
|
||||||
|
font-size: 18px;
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
.score-text {
|
||||||
|
font-size: 1.5em;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.highscore-text {
|
||||||
|
font-size: 1.5em;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<canvas id="gameCanvas" width="400" height="400"></canvas>
|
<canvas id="gameCanvas" width="400" height="400"></canvas>
|
||||||
<div id="startScreen" style="display: block;"><h1>Snake Game</h1><p>Press Space to Start</p></div>
|
<div id="scoreboard">
|
||||||
<script>
|
<div class="score-text">Score: <span id="score">0</span></div>
|
||||||
const canvas = document.getElementById('gameCanvas'), ctx = canvas.getContext('2d'), startScreen = document.getElementById('startScreen');
|
<div class="highscore-text">Highscore: <span id="highscore">0</span></div>
|
||||||
const gridSize = 20; let snake = [{ x: 200, y: 200 }], direction = { x: 0, y: 0 }, food = { x: 0, y: 0 }, gameOver = false, gameStarted = false;
|
</div>
|
||||||
|
<div id="overlay">
|
||||||
|
<h1>Snake Game</h1>
|
||||||
|
<p>Press Space to Start</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
const getRandomFoodPosition = () => ({ x: Math.floor(Math.random() * (canvas.width / gridSize)) * gridSize, y: Math.floor(Math.random() * (canvas.height / gridSize)) * gridSize });
|
<script>
|
||||||
const drawRect = (x, y, color) => { ctx.fillStyle = color; ctx.fillRect(x, y, gridSize, gridSize); };
|
const canvas = document.getElementById('gameCanvas');
|
||||||
const update = () => {
|
const ctx = canvas.getContext('2d');
|
||||||
if (gameOver) return;
|
const overlay = document.getElementById('overlay');
|
||||||
const head = { x: snake[0].x + direction.x, y: snake[0].y + direction.y };
|
const scoreDisplay = document.getElementById('score');
|
||||||
if (head.x < 0 || head.x >= canvas.width || head.y < 0 || head.y >= canvas.height || snake.some(segment => segment.x === head.x && segment.y === head.y)) {
|
const highscoreDisplay = document.getElementById('highscore');
|
||||||
gameOver = true;
|
|
||||||
location.reload(); // Reload the page when the game is over
|
const gridSize = 20;
|
||||||
|
let snake = [{ x: 200, y: 200 }];
|
||||||
|
let direction = { x: 0, y: 0 };
|
||||||
|
let nextDirection = { x: 0, y: -gridSize };
|
||||||
|
let food = {};
|
||||||
|
let score = 0;
|
||||||
|
let highscore = parseInt(localStorage.getItem('snakeHighscore')) || 0;
|
||||||
|
let gameRunning = false;
|
||||||
|
let gameOver = false;
|
||||||
|
let speed = 100;
|
||||||
|
let timeoutId;
|
||||||
|
|
||||||
|
highscoreDisplay.textContent = highscore;
|
||||||
|
|
||||||
|
function getRandomPosition() {
|
||||||
|
return {
|
||||||
|
x: Math.floor(Math.random() * (canvas.width / gridSize)) * gridSize,
|
||||||
|
y: Math.floor(Math.random() * (canvas.height / gridSize)) * gridSize
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function placeFood() {
|
||||||
|
food = getRandomPosition();
|
||||||
|
while (snake.some(s => s.x === food.x && s.y === food.y)) {
|
||||||
|
food = getRandomPosition();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Funktion zum Zeichnen eines abgerundeten Rechtecks (für die Snake)
|
||||||
|
function drawRoundedRect(x, y, width, height, radius, color) {
|
||||||
|
ctx.fillStyle = color;
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(x + radius, y);
|
||||||
|
ctx.lineTo(x + width - radius, y);
|
||||||
|
ctx.arcTo(x + width, y, x + width, y + height, radius);
|
||||||
|
ctx.lineTo(x + width, y + height - radius);
|
||||||
|
ctx.arcTo(x + width, y + height, x + width - radius, y + height, radius);
|
||||||
|
ctx.lineTo(x + radius, y + height);
|
||||||
|
ctx.arcTo(x, y + height, x, y + height - radius, radius);
|
||||||
|
ctx.lineTo(x, y + radius);
|
||||||
|
ctx.arcTo(x, y, x + radius, y, radius);
|
||||||
|
ctx.closePath();
|
||||||
|
ctx.fill();
|
||||||
|
}
|
||||||
|
|
||||||
|
function update() {
|
||||||
|
direction = nextDirection;
|
||||||
|
|
||||||
|
const head = {
|
||||||
|
x: snake[0].x + direction.x,
|
||||||
|
y: snake[0].y + direction.y
|
||||||
|
};
|
||||||
|
|
||||||
|
if (
|
||||||
|
head.x < 0 || head.x >= canvas.width ||
|
||||||
|
head.y < 0 || head.y >= canvas.height ||
|
||||||
|
snake.some(segment => segment.x === head.x && segment.y === head.y)
|
||||||
|
) {
|
||||||
|
endGame();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
snake.unshift(head);
|
snake.unshift(head);
|
||||||
if (head.x === food.x && head.y === food.y) food = getRandomFoodPosition(); else snake.pop();
|
|
||||||
};
|
if (head.x === food.x && head.y === food.y) {
|
||||||
const draw = () => { ctx.clearRect(0, 0, canvas.width, canvas.height); snake.forEach(segment => drawRect(segment.x, segment.y, 'lime')); drawRect(food.x, food.y, 'red'); };
|
score++;
|
||||||
const gameLoop = () => { update(); draw(); if (!gameOver) setTimeout(gameLoop, 100); };
|
scoreDisplay.textContent = score;
|
||||||
const resetGame = () => { snake = [{ x: 200, y: 200 }]; direction = { x: 0, y: 0 }; food = getRandomFoodPosition(); gameOver = false; gameLoop(); };
|
placeFood();
|
||||||
|
} else {
|
||||||
|
snake.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function draw() {
|
||||||
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
|
// Snake als abgerundetes Rechteck zeichnen
|
||||||
|
snake.forEach((segment, index) => {
|
||||||
|
const color = index === 0 ? 'limegreen' : 'darkgreen'; // Kopf grün, Rest dunkelgrün
|
||||||
|
drawRoundedRect(segment.x, segment.y, gridSize, gridSize, 5, color);
|
||||||
|
});
|
||||||
|
// Essen zeichnen
|
||||||
|
drawRoundedRect(food.x, food.y, gridSize, gridSize, 5, 'tomato');
|
||||||
|
}
|
||||||
|
|
||||||
|
function gameLoop() {
|
||||||
|
if (!gameRunning) return;
|
||||||
|
update();
|
||||||
|
draw();
|
||||||
|
timeoutId = setTimeout(gameLoop, speed);
|
||||||
|
}
|
||||||
|
|
||||||
|
function startGame() {
|
||||||
|
snake = [{ x: 200, y: 200 }];
|
||||||
|
direction = { x: 0, y: -gridSize };
|
||||||
|
nextDirection = { x: 0, y: -gridSize };
|
||||||
|
score = 0;
|
||||||
|
speed = 100; // Standard-Geschwindigkeit ohne Erhöhung
|
||||||
|
scoreDisplay.textContent = score;
|
||||||
|
gameOver = false;
|
||||||
|
gameRunning = true;
|
||||||
|
overlay.style.display = 'none';
|
||||||
|
placeFood();
|
||||||
|
gameLoop();
|
||||||
|
}
|
||||||
|
|
||||||
|
function endGame() {
|
||||||
|
gameRunning = false;
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
|
||||||
|
if (score > highscore) {
|
||||||
|
highscore = score;
|
||||||
|
localStorage.setItem('snakeHighscore', highscore);
|
||||||
|
highscoreDisplay.textContent = highscore;
|
||||||
|
}
|
||||||
|
|
||||||
|
overlay.innerHTML = '<h1>Game Over</h1><p>Press Space to Restart</p>';
|
||||||
|
overlay.style.display = 'block';
|
||||||
|
}
|
||||||
|
|
||||||
window.addEventListener('keydown', e => {
|
window.addEventListener('keydown', e => {
|
||||||
switch (e.key) {
|
switch (e.key) {
|
||||||
case 'ArrowUp': case 'w': if (direction.y === 0) direction = { x: 0, y: -gridSize }; break;
|
case 'ArrowUp':
|
||||||
case 'ArrowDown': case 's': if (direction.y === 0) direction = { x: 0, y: gridSize }; break;
|
case 'w':
|
||||||
case 'ArrowLeft': case 'a': if (direction.x === 0) direction = { x: -gridSize, y: 0 }; break;
|
if (direction.y === 0) nextDirection = { x: 0, y: -gridSize };
|
||||||
case 'ArrowRight': case 'd': if (direction.x === 0) direction = { x: gridSize, y: 0 }; break;
|
break;
|
||||||
case ' ': if (gameOver) resetGame(); else if (!gameStarted) { startScreen.style.display = 'none'; gameStarted = true; gameLoop(); } break;
|
case 'ArrowDown':
|
||||||
|
case 's':
|
||||||
|
if (direction.y === 0) nextDirection = { x: 0, y: gridSize };
|
||||||
|
break;
|
||||||
|
case 'ArrowLeft':
|
||||||
|
case 'a':
|
||||||
|
if (direction.x === 0) nextDirection = { x: -gridSize, y: 0 };
|
||||||
|
break;
|
||||||
|
case 'ArrowRight':
|
||||||
|
case 'd':
|
||||||
|
if (direction.x === 0) nextDirection = { x: gridSize, y: 0 };
|
||||||
|
break;
|
||||||
|
case ' ':
|
||||||
|
if (!gameRunning) startGame();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
food = getRandomFoodPosition();
|
overlay.style.display = 'block';
|
||||||
startScreen.style.display = 'block';
|
|
||||||
</script>
|
</script>
|
||||||
|
</body>
|
||||||
</body></html>
|
</html>
|
Loading…
x
Reference in New Issue
Block a user