Skip to content

Instantly share code, notes, and snippets.

@olekstomek
Last active November 10, 2024 19:21
Show Gist options
  • Save olekstomek/f9338e22e2002a48239544ad826e7701 to your computer and use it in GitHub Desktop.
Save olekstomek/f9338e22e2002a48239544ad826e7701 to your computer and use it in GitHub Desktop.
prosta implementacja do rozgrywki teleturnieju typu Awantura o Kasę
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bitwa na Pasmo</title>
<style>
body {
display: flex;
flex-direction: column;
align-items: center;
font-family: Arial, sans-serif;
height: 100vh;
margin: 0;
background: linear-gradient(to bottom, black, orange);
color: white;
overflow: hidden;
}
.teams-container {
display: flex;
justify-content: center;
margin: 20px 0;
}
.team {
width: 450px;
height: 180px;
margin: 10px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
font-size: 24px;
font-weight: bold;
border-radius: 20px;
position: relative;
}
.blue {
background-color: blue;
}
.green {
background-color: green;
}
.yellow {
background-color: gold;
}
.team-name {
font-size: 1.5em;
font-weight: bold;
margin-bottom: 1px;
}
.bid-info {
margin-top: 5px;
font-size: 1.2em;
position: absolute;
top: -40px;
background: rgba(255, 255, 255, 0.1);
padding: -15px 10px;
border-radius: 5px;
}
#pot {
font-size: 50px;
margin: 20px;
background: rgba(99, 99, 99, 0.1);
}
button {
margin: 10px;
padding: 10px 20px;
font-size: 16px;
}
.correct {
background-color: green;
color: white;
}
.wrong {
background-color: red;
color: white;
}
.horizontal-buttons {
display: flex;
}
.va-banque {
background-color: #FF4500;
color: white;
border: none;
padding: 10px;
cursor: pointer;
font-weight: bold;
border-radius: 5px;
}
.va-banque:disabled {
background-color: grey;
cursor: not-allowed;
border-radius: 5px;
}
.animated-title {
font-size: 3em;
text-align: center;
font-weight: bold;
margin: 20px 0;
color: #fff;
animation: colorChange 3s ease-in-out infinite, pulse 1.5s ease-in-out infinite;
}
@keyframes colorChange {
0% {
color: #ff3333;
}
25% {
color: #33ff33;
}
50% {
color: #3333ff;
}
75% {
color: #ffff33;
}
100% {
color: #ff3333;
}
}
@keyframes pulse {
0%, 100% {
transform: scale(1);
}
50% {
transform: scale(1.1);
}
}
#timer {
position: absolute;
top: 20px;
right: 20px;
font-size: 7em;
font-weight: bold;
}
.warning {
color: red;
animation: shake 0.5s infinite;
}
@keyframes shake {
0%, 100% {
transform: translateX(0);
}
25% {
transform: translateX(-3px);
}
75% {
transform: translateX(3px);
}
}
</style>
</head>
<body>
<h1 class="animated-title">⚔️ Bitwa 📶 na 📶 Pasmo ⚔️</h1>
<div id="timer">01:00</div>
<div id="pot"></div>
<div class="teams-container">
<div class="team blue" id="teamBlue">
<div class="team-name">Niebiescy</div>
<div class="balance">Saldo: <span id="balanceBlue"></span> GB</div>
<div class="bid-info">Kwota licytacji: <span id="bidBlue">0</span></div>
<button id="btnBlue" onclick="increaseBid('blue')">&#10133; 100 Gigsów</button>
<button class="va-banque" id="vaBanqueBlue" onclick="vaBanque('blue')" disabled>Va banque</button>
</div>
<div class="team green" id="teamGreen">
<div class="team-name">Zieloni</div>
<div class="balance">Saldo: <span id="balanceGreen"></span> GB</div>
<div class="bid-info">Kwota licytacji: <span id="bidGreen">0</span></div>
<button id="btnGreen" onclick="increaseBid('green')">&#10133; 100 Gigsów</button>
<button class="va-banque" id="vaBanqueGreen" onclick="vaBanque('green')" disabled>Va banque</button>
</div>
<div class="team yellow" id="teamYellow">
<div class="team-name">Żółci</div>
<div class="balance">Saldo: <span id="balanceYellow"></span> GB</div>
<div class="bid-info">Kwota licytacji: <span id="bidYellow">0</span></div>
<button id="btnYellow" onclick="increaseBid('yellow')">&#10133; 100 Gigsów</button>
<button class="va-banque" id="vaBanqueYellow" onclick="vaBanque('yellow')" disabled>Va banque</button>
</div>
</div>
<div class="horizontal-buttons">
<button id="startButton" onclick="startAuction()">&#9654; Start licytacji</button>
<button id="correctButton" class="correct" onclick="correctAnswer()" disabled>&#10003; Dobra odpowiedź</button>
<button id="wrongButton" class="wrong" onclick="wrongAnswer()" disabled>&#10060; Zła odpowiedź | 📦 Czarna
skrzynka
</button>
</div>
<iframe style="max-width:100%"
src="https://wordwall.net/embed/ff43169ab9ac4d6c86ed3be4ca9ea3a3?themeId=21&templateId=8&fontStackId=0"
width="680" height="800" frameborder="0" allowfullscreen></iframe>
<div class="controls">
<button onclick="playIntro()">&#9835; Intro</button>
<button onclick="playRulesOfTheGame()">&#9835; Zasady gry</button>
<button onclick="playIntroductionOfPlayers()">&#9835; Przedstawienie graczy</button>
<button onclick="playPickCategory()">&#9835; Losowanie kategorii</button>
<button onclick="playAuction()">&#9835; Licytacja</button>
<button onclick="playPenalty()">&#9835; Kara</button>
<button onclick="playPresentingTheQuestion()">&#9835; Przedstawienie pytania</button>
<button onclick="playTimeForAQuestion()">&#9835; Czas na pytanie</button>
<button onclick="playGameSummary()">&#9835; Podsumowanie gry</button>
<button onclick="playBlackBox()">&#9835; Czarna skrzynka</button>
<button onclick="stopMusic()">Stop &#9835;</button>
|
<button onclick="startTimer()">&#128337; Uruchom czas</button>
<button onclick="stopTimer()">&#128337; Zatrzymaj czas</button>
<button onclick="resetTimer()">&#128337; Restartuj czas</button>
|
<button onclick="restartGame()">&#10227; Restart bitwy</button>
||
<button onclick="addToPot(2000)">&#127873; Dorzuć 2000 GB do puli</button>
</div>
<script>
let pot = 0;
let teamBalances = {blue: 15000, green: 15000, yellow: 15000};
let bids = {blue: 0, green: 0, yellow: 0};
let auctionStarted = false;
let timerInterval;
let timeRemaining = 60;
const intro = new Audio('sounds/Demolition.mp3');
const rulesOfTheGame = new Audio('sounds/Hipnotica.mp3');
const introductionOfPlayers = new Audio('sounds/Phat Katz.mp3');
const pickCategory = new Audio('sounds/Boom.mp3');
const auction = new Audio('sounds/Smokin.mp3');
const penalty = new Audio('sounds/Extra Grip.mp3');
const presentingTheQuestion = new Audio('sounds/Electric Dimensions.mp3');
const timeForAQuestion = new Audio('sounds/Raw Drums.mp3');
const gameSummary = new Audio('sounds/Extreme.mp3');
const blackBox = new Audio('sounds/Dark Pulse.mp3');
const teamNames = {
blue: 'Niebiescy',
green: 'Zieloni',
yellow: 'Żółci'
};
function updateDisplay() {
const teamElements = {
blue: document.getElementById('teamBlue'),
green: document.getElementById('teamGreen'),
yellow: document.getElementById('teamYellow')
};
const maxBid = Math.max(...Object.values(bids));
const leadingTeams = Object.keys(bids).filter(team => bids[team] === maxBid);
if (leadingTeams.length === 1) {
const leadingTeam = leadingTeams[0];
teamElements[leadingTeam].querySelector('.team-name').innerHTML = `${teamNames[leadingTeam]} &#127942;`;
}
Object.keys(teamElements).forEach(team => {
if (!leadingTeams.includes(team)) {
teamElements[team].querySelector('.team-name').innerHTML = teamNames[team];
}
});
document.getElementById('balanceBlue').innerText = teamBalances.blue;
document.getElementById('balanceGreen').innerText = teamBalances.green;
document.getElementById('balanceYellow').innerText = teamBalances.yellow;
document.getElementById('pot').innerText = `Pula: ${pot} GB (Gigabajty)`;
document.getElementById('bidBlue').innerText = `${bids.blue} GB`;
document.getElementById('bidGreen').innerText = `${bids.green} GB`;
document.getElementById('bidYellow').innerText = `${bids.yellow} GB`;
checkAnswerButtons();
}
function startAuction() {
if (!auctionStarted) {
resetTrophies();
resetTimer();
for (let team in teamBalances) {
const deduction = Math.min(teamBalances[team], 200);
teamBalances[team] -= deduction;
bids[team] = deduction;
pot += deduction;
document.getElementById(`vaBanque${capitalize(team)}`).disabled = teamBalances[team] === 0;
}
auctionStarted = true;
document.getElementById('startButton').disabled = true;
updateDisplay();
updateBidButtons();
}
}
function resetTrophies() {
document.getElementById('teamBlue').querySelector('.team-name').innerHTML = teamNames.blue;
document.getElementById('teamGreen').querySelector('.team-name').innerHTML = teamNames.green;
document.getElementById('teamYellow').querySelector('.team-name').innerHTML = teamNames.yellow;
}
function increaseBid(team) {
if (auctionStarted) {
const maxBid = Math.max(...Object.values(bids));
const difference = maxBid > bids[team] ? (maxBid - bids[team]) + 100 : 100;
if (teamBalances[team] >= difference) {
teamBalances[team] -= difference;
bids[team] += difference;
pot += difference;
updateDisplay();
updateBidButtons();
}
}
}
function updateBidButtons() {
const maxBid = Math.max(...Object.values(bids));
const teams = ['blue', 'green', 'yellow'];
teams.forEach(team => {
const difference = maxBid > bids[team] ? (maxBid - bids[team]) + 100 : 100;
const button = document.getElementById(`btn${capitalize(team)}`);
button.disabled = teamBalances[team] < difference;
});
}
function vaBanque(team) {
const confirmVaBanque = confirm("Czy na pewno chcesz grać va banque? Całe saldo zostanie przeniesione do puli.");
if (!confirmVaBanque) return;
if (teamBalances[team] > 0 && auctionStarted) {
pot += teamBalances[team];
bids[team] = teamBalances[team];
teamBalances[team] = 0;
disableOtherTeamsActions(team);
updateDisplay();
}
}
function correctAnswer() {
if (auctionStarted) {
const winningTeam = Object.keys(bids).reduce((a, b) => bids[a] > bids[b] ? a : b);
teamBalances[winningTeam] += pot;
resetAuction();
updateDisplay();
}
}
function wrongAnswer() {
if (auctionStarted) {
resetAuction(false);
updateDisplay();
}
}
function resetAuction(resetPot = true) {
for (let team in bids) bids[team] = 0;
if (resetPot) pot = 0;
auctionStarted = false;
document.getElementById('startButton').disabled = false;
disableVaBanqueButtons();
enableAllTeamsActions();
updateDisplay();
updateBidButtons();
}
function disableOtherTeamsActions(activeTeam) {
const teams = ['blue', 'green', 'yellow'];
teams.forEach(team => {
if (team !== activeTeam) {
document.getElementById(`vaBanque${capitalize(team)}`).disabled = true;
document.getElementById(`btn${capitalize(team)}`).disabled = true;
}
});
}
function disableVaBanqueButtons() {
document.getElementById('vaBanqueBlue').disabled = true;
document.getElementById('vaBanqueGreen').disabled = true;
document.getElementById('vaBanqueYellow').disabled = true;
}
function enableAllTeamsActions() {
const teams = ['blue', 'green', 'yellow'];
teams.forEach(team => {
document.getElementById(`btn${capitalize(team)}`).disabled = false;
});
}
function checkAnswerButtons() {
const uniqueBids = new Set(Object.values(bids).filter(bid => bid > 0));
const maxBid = Math.max(...Object.values(bids));
const maxBidTeams = Object.values(bids).filter(bid => bid === maxBid).length;
document.getElementById('correctButton').disabled = uniqueBids.size < 2 || maxBidTeams > 1;
document.getElementById('wrongButton').disabled = uniqueBids.size < 2 || maxBidTeams > 1;
}
function capitalize(word) {
return word.charAt(0).toUpperCase() + word.slice(1);
}
function playIntro() {
intro.play();
}
function playRulesOfTheGame() {
rulesOfTheGame.play();
}
function playIntroductionOfPlayers() {
introductionOfPlayers.play();
}
function playPickCategory() {
pickCategory.play();
}
function playAuction() {
auction.play();
}
function playPenalty() {
penalty.play();
}
function playPresentingTheQuestion() {
presentingTheQuestion.play();
}
function playTimeForAQuestion() {
timeForAQuestion.play();
}
function playGameSummary() {
gameSummary.play();
}
function playBlackBox() {
blackBox.play();
}
function stopMusic() {
intro.pause();
intro.currentTime = 0;
rulesOfTheGame.pause();
rulesOfTheGame.currentTime = 0;
introductionOfPlayers.pause();
introductionOfPlayers.currentTime = 0;
pickCategory.pause();
pickCategory.currentTime = 0;
auction.pause();
auction.currentTime = 0;
penalty.pause();
penalty.currentTime = 0;
presentingTheQuestion.pause();
presentingTheQuestion.currentTime = 0;
timeForAQuestion.pause();
timeForAQuestion.currentTime = 0;
gameSummary.pause();
gameSummary.currentTime = 0;
blackBox.pause();
blackBox.currentTime = 0;
}
function startTimer() {
if (timerInterval) return;
timerInterval = setInterval(() => {
timeRemaining--;
document.getElementById("timer").innerText = formatTime(timeRemaining);
if (timeRemaining <= 10) {
document.getElementById("timer").classList.add("warning");
}
if (timeRemaining <= 0) {
clearInterval(timerInterval);
timerInterval = null;
alert("Czas upłynął!");
}
}, 1000);
}
function stopTimer() {
clearInterval(timerInterval);
timerInterval = null;
}
function resetTimer() {
stopTimer();
timeRemaining = 60;
document.getElementById("timer").innerText = formatTime(timeRemaining);
document.getElementById("timer").classList.remove("warning");
}
function formatTime(seconds) {
const mins = Math.floor(seconds / 60);
const secs = seconds % 60;
return `${String(mins).padStart(2, '0')}:${String(secs).padStart(2, '0')}`;
}
function restartGame() {
const confirmRestart = confirm("Czy na pewno chcesz zacząć grę od nowa?");
if (confirmRestart) {
location.reload();
}
}
function addToPot(amount) {
pot += amount;
updateDisplay();
}
updateDisplay();
</script>
</body>
</html>
@olekstomek
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment