Demos (Gruppe D): Image cb-web, Aufgaben d-10 Snake, d-11 Sonnensystem, d-12 Highscore auf eigener Lösung, Browser-Prüfung mit Screenshot und Checkliste, Aufgaben mit depends_on

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-09 13:53:14 +01:00
parent c8a24fd8b3
commit 8e5be1ed0b
34 changed files with 1125 additions and 30 deletions

View File

@ -0,0 +1,24 @@
<!doctype html><html lang="de"><head><meta charset="utf-8"><title>Snake</title>
<style>
html,body{margin:0;background:#111;color:#eee;font-family:sans-serif}
#top{padding:8px}
#board{display:grid;grid-template-columns:repeat(20,24px);grid-auto-rows:24px;gap:1px;width:max-content;margin:8px auto;background:#222}
.cell{background:#1c1c1c}.snake{background:#4c4}.head{background:#9f9}.food{background:#e44}
</style></head><body>
<div id="top"><button id="start">Start</button> Punkte: <span id="score">0</span> · <span id="status">bereit</span></div>
<div id="board"></div>
<script>
const N=20,board=document.getElementById("board"),cells=[];
for(let y=0;y<N;y++)for(let x=0;x<N;x++){const c=document.createElement("div");c.className="cell";c.dataset.x=x;c.dataset.y=y;board.appendChild(c);cells.push(c)}
let snake,dir,next,food,score,timer,alive=false;
const at=(x,y)=>cells[y*N+x];
function place(){let x,y;do{x=Math.floor(Math.random()*N);y=Math.floor(Math.random()*N)}while(snake.some(s=>s[0]==x&&s[1]==y));food=[x,y]}
function draw(){cells.forEach(c=>c.className="cell");snake.forEach((s,i)=>at(s[0],s[1]).classList.add("snake",...(i==0?["head"]:[])));at(food[0],food[1]).classList.add("food");document.getElementById("score").textContent=score}
function start(){clearInterval(timer);snake=[[10,10],[9,10],[8,10]];dir=[1,0];next=dir;score=0;alive=true;place();draw();document.getElementById("status").textContent="läuft";timer=setInterval(step,150)}
function step(){if(!alive)return;dir=next;const h=[snake[0][0]+dir[0],snake[0][1]+dir[1]];
const eat=h[0]==food[0]&&h[1]==food[1];const body=eat?snake:snake.slice(0,-1);
if(h[0]<0||h[1]<0||h[0]>=N||h[1]>=N||body.some(s=>s[0]==h[0]&&s[1]==h[1])){alive=false;clearInterval(timer);document.getElementById("status").textContent="vorbei";return}
snake.unshift(h);if(eat){score++;place()}else snake.pop();draw()}
document.addEventListener("keydown",e=>{const m={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]}[e.key];if(!m)return;e.preventDefault();if(m[0]==-dir[0]&&m[1]==-dir[1])return;next=m});
document.getElementById("start").onclick=start;
</script></body></html>

View File

@ -0,0 +1,25 @@
<!doctype html>
<html lang="de"><head><meta charset="utf-8"><title>Sonnensystem</title>
<style>
html,body{margin:0;height:100%;overflow:hidden;background:#05060f;color:#ddd;font-family:sans-serif}
#space{position:relative;width:1280px;height:760px}
#sun{position:absolute;left:655px;top:405px;width:50px;height:50px;margin:-25px 0 0 -25px;border-radius:50%;background:#fc3;box-shadow:0 0 40px #fa0}
.planet{position:absolute;border-radius:50%;cursor:pointer;margin:-8px 0 0 -8px;width:16px;height:16px}
#info{position:absolute;left:10px;top:10px;width:300px}
#pause{position:absolute;right:10px;top:10px}
</style></head><body>
<div id="space"><div id="sun"></div><div id="info">Klicke auf einen Planeten</div><button id="pause">Pause</button></div>
<script>
const data=[["merkur","Merkur",50,"#aaa",4,"4879 km"],["venus","Venus",80,"#e9c",3.2,"12104 km"],["erde","Erde",115,"#4af",2.6,"12742 km"],["mars","Mars",150,"#e64",2.1,"6779 km"],["jupiter","Jupiter",200,"#d96",1.4,"139820 km"],["saturn","Saturn",250,"#eb8",1.1,"116460 km"],["uranus","Uranus",295,"#8dd",0.8,"50724 km"],["neptun","Neptun",335,"#46f",0.6,"49244 km"]];
const space=document.getElementById("space"),info=document.getElementById("info");
let paused=false;const els=[];
for(const [id,name,r,col,sp,dia] of data){
const o=document.createElement("div");o.style.cssText=`position:absolute;left:655px;top:405px;width:${2*r}px;height:${2*r}px;margin:${-r}px 0 0 ${-r}px;border:1px solid #223;border-radius:50%`;space.appendChild(o);
const p=document.createElement("div");p.className="planet";p.dataset.planet=id;p.style.background=col;
p.onclick=()=>{info.textContent=`${name}: Durchmesser ${dia}, Abstand ${r} Einheiten`};space.appendChild(p);els.push([p,r,sp,Math.random()*6]);
}
let last=performance.now();
function tick(t){const dt=(t-last)/1000;last=t;for(const e of els){if(!paused)e[3]+=dt*e[2]*0.6;e[0].style.left=(655+e[1]*Math.cos(e[3]))+"px";e[0].style.top=(405+e[1]*Math.sin(e[3]))+"px"}requestAnimationFrame(tick)}
requestAnimationFrame(tick);
document.getElementById("pause").onclick=()=>{paused=!paused};
</script></body></html>

View File

@ -0,0 +1,24 @@
<!doctype html><html lang="de"><head><meta charset="utf-8"><title>Snake</title>
<style>
html,body{margin:0;background:#111;color:#eee;font-family:sans-serif}
#top{padding:8px}
#board{display:grid;grid-template-columns:repeat(20,24px);grid-auto-rows:24px;gap:1px;width:max-content;margin:8px auto;background:#222}
.cell{background:#1c1c1c}.snake{background:#4c4}.head{background:#9f9}.food{background:#e44}
</style></head><body>
<div id="top"><button id="start">Start</button> Punkte: <span id="score">0</span> · Highscore: <span id="highscore">0</span> · <span id="status">bereit</span></div>
<div id="board"></div>
<script>
const N=20,board=document.getElementById("board"),cells=[];
for(let y=0;y<N;y++)for(let x=0;x<N;x++){const c=document.createElement("div");c.className="cell";c.dataset.x=x;c.dataset.y=y;board.appendChild(c);cells.push(c)}
let snake,dir,next,food,score,timer,alive=false;let hi=Number(localStorage.getItem("hi")||0);const showHi=()=>{document.getElementById("highscore").textContent=hi};showHi();
const at=(x,y)=>cells[y*N+x];
function place(){let x,y;do{x=Math.floor(Math.random()*N);y=Math.floor(Math.random()*N)}while(snake.some(s=>s[0]==x&&s[1]==y));food=[x,y]}
function draw(){cells.forEach(c=>c.className="cell");snake.forEach((s,i)=>at(s[0],s[1]).classList.add("snake",...(i==0?["head"]:[])));at(food[0],food[1]).classList.add("food");document.getElementById("score").textContent=score}
function start(){clearInterval(timer);snake=[[10,10],[9,10],[8,10]];dir=[1,0];next=dir;score=0;alive=true;place();draw();document.getElementById("status").textContent="läuft";timer=setInterval(step,150)}
function step(){if(!alive)return;dir=next;const h=[snake[0][0]+dir[0],snake[0][1]+dir[1]];
const eat=h[0]==food[0]&&h[1]==food[1];const body=eat?snake:snake.slice(0,-1);
if(h[0]<0||h[1]<0||h[0]>=N||h[1]>=N||body.some(s=>s[0]==h[0]&&s[1]==h[1])){alive=false;clearInterval(timer);if(score>hi){hi=score;localStorage.setItem("hi",hi);showHi()}document.getElementById("status").textContent="vorbei";return}
snake.unshift(h);if(eat){score++;place()}else snake.pop();draw()}
document.addEventListener("keydown",e=>{const m={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]}[e.key];if(!m)return;e.preventDefault();if(m[0]==-dir[0]&&m[1]==-dir[1])return;next=m});
document.getElementById("start").onclick=start;
</script></body></html>