Darts added
This commit is contained in:
46
darts/index.html
Normal file
46
darts/index.html
Normal file
@@ -0,0 +1,46 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Helios Darts 🎯</title>
|
||||
<style>
|
||||
body { font-family: sans-serif; background-color: #222; color: white; text-align: center; }
|
||||
|
||||
.scoreboard { display: flex; justify-content: center; gap: 50px; margin-top: 20px; }
|
||||
.player { background: #333; padding: 20px; border-radius: 10px; width: 150px; }
|
||||
.score { font-size: 60px; font-weight: bold; color: #1793d1; } /* Arch Blue ;) */
|
||||
|
||||
.input-area { margin-top: 40px; }
|
||||
input { font-size: 20px; padding: 10px; width: 200px; text-align: center; }
|
||||
button { font-size: 20px; padding: 10px 20px; cursor: pointer; background: #1793d1; border: none; color: white; }
|
||||
|
||||
.history { margin-top: 20px; color: #888; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>🎯 Helios Darts</h1>
|
||||
|
||||
<div class="scoreboard">
|
||||
<div class="player">
|
||||
<h2>Spieler 1</h2>
|
||||
<div id="score1" class="score">501</div>
|
||||
</div>
|
||||
<div class="player">
|
||||
<h2>Spieler 2</h2>
|
||||
<div id="score2" class="score">501</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="input-area">
|
||||
<h3>Wurf eingeben (z.B. 60 oder T20)</h3>
|
||||
<input type="text" id="inputScore" placeholder="Wurf..." autofocus>
|
||||
<button onclick="submitThrow()">Enter</button>
|
||||
</div>
|
||||
|
||||
<div class="history" id="status">Spieler 1 ist dran</div>
|
||||
|
||||
<script src="script.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
76
darts/script.js
Normal file
76
darts/script.js
Normal file
@@ -0,0 +1,76 @@
|
||||
let scores = [501, 501]; // Punktestände für Spieler 0 und 1
|
||||
let currentPlayer = 0; // 0 = Spieler 1, 1 = Spieler 2
|
||||
|
||||
function submitThrow() {
|
||||
const inputField = document.getElementById("inputScore");
|
||||
const rawInput = inputField.value.toUpperCase().trim(); // Mach "t20 " zu "T20"
|
||||
|
||||
let points = 0;
|
||||
|
||||
// 1. Checken: Ist es eine spezielle Eingabe (T18, D20, BULL)?
|
||||
if (rawInput.startsWith("T")) {
|
||||
// Beispiel: T20 -> Wir schneiden das "T" weg, nehmen die 20, mal 3
|
||||
let number = parseInt(rawInput.substring(1));
|
||||
points = number * 3;
|
||||
}
|
||||
else if (rawInput.startsWith("D")) {
|
||||
// Beispiel: D20 -> 20 * 2
|
||||
let number = parseInt(rawInput.substring(1));
|
||||
points = number * 2;
|
||||
}
|
||||
else if (rawInput === "BULL") {
|
||||
points = 50;
|
||||
}
|
||||
else if (rawInput === "25") {
|
||||
points = 25;
|
||||
}
|
||||
else {
|
||||
// 2. Normaler Zahleneingabe (z.B. "60" oder "45")
|
||||
points = parseInt(rawInput);
|
||||
}
|
||||
|
||||
// Sicherheitscheck: Ist die Eingabe Gültig?
|
||||
if (isNaN(points)) {
|
||||
alert("Ungültige Eingabe! Versuch es mit Zahlen, T20 oder D20.");
|
||||
inputField.value = "";
|
||||
return;
|
||||
}
|
||||
|
||||
// Punkte abziehen
|
||||
let newScore = scores[currentPlayer] - points;
|
||||
|
||||
// Logik: Nicht unter 0 fallen (Bust)
|
||||
if (newScore < 0) {
|
||||
document.getElementById("status").innerText = `Überworfen! Nächster Spieler.`;
|
||||
} else if (newScore === 0) {
|
||||
alert(`Spieler ${currentPlayer + 1} hat gewonnen! 🎯`);
|
||||
location.reload(); // Seite neu laden für neues Spiel
|
||||
} else {
|
||||
scores[currentPlayer] = newScore;
|
||||
}
|
||||
|
||||
// Anzeige aktualisieren
|
||||
updateDisplay();
|
||||
|
||||
// Spieler wechseln
|
||||
currentPlayer = (currentPlayer === 0) ? 1 : 0;
|
||||
|
||||
// Status Text
|
||||
document.getElementById("status").innerText = `Spieler ${currentPlayer + 1} ist dran`;
|
||||
|
||||
// Feld leeren
|
||||
inputField.value = "";
|
||||
inputField.focus();
|
||||
}
|
||||
|
||||
function updateDisplay() {
|
||||
document.getElementById("score1").innerText = scores[0];
|
||||
document.getElementById("score2").innerText = scores[1];
|
||||
}
|
||||
|
||||
// Damit man auch "Enter" auf der Tastatur drücken kann
|
||||
document.getElementById("inputScore").addEventListener("keypress", function(event) {
|
||||
if (event.key === "Enter") {
|
||||
submitThrow();
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user