Here is a basic example of a zoo roulette game using HTML, CSS, and JavaScript
HTML:
<!-- Zoo Roulette Game --> <div class="zoo-roulette"> <div class="wheel"> <div class="animal" data-animal="Lion">Lion</div> <div class="animal" data-animal="Tiger">Tiger</div> <div class="animal" data-animal="Giraffe">Giraffe</div> <div class="animal" data-animal="Monkey">Monkey</div> <div class="animal" data-animal="Elephant">Elephant</div> <div class="animal" data-animal="Zebra">Zebra</div> <div class="animal" data-animal="Kangaroo">Kangaroo</div> <div class="animal" data-animal="Penguin">Penguin</div> <div class="animal" data-animal="Crocodile">Crocodile</div> <div class="animal" data-animal="Hippo">Hippo</div> <div class="animal" data-animal="Chimpanzee">Chimpanzee</div> <div class="animal" data-animal="Koala">Koala</div> <div class="animal" data-animal="Sloth">Sloth</div> <div class="animal" data-animal="Rhino">Rhino</div> <div class="animal" data-animal="Cheetah">Cheetah</div> <div class="animal" data-animal="Hyena">Hyena</div> <div class="animal" data-animal="Wolf">Wolf</div> <div class="animal" data-animal="Bear">Bear</div> <div class="animal" data-animal="Snake">Snake</div> <div class="animal" data-animal="Turtle">Turtle</div> </div> <button id="spin-button">Spin the Wheel!</button> <div id="result"></div> </div>
Js:
// Get the wheel and spin button elements const wheel = document.querySelector('.wheel'); const spinButton = document.querySelector('#spin-button'); const resultDiv = document.querySelector('#result'); // Define the animals array const animals = [ 'Lion', 'Tiger', 'Giraffe', 'Monkey', 'Elephant', 'Zebra', 'Kangaroo', 'Penguin', 'Crocodile', 'Hippo', 'Chimpanzee', 'Koala', 'Sloth', 'Rhino', 'Cheetah', 'Hyena', 'Wolf', 'Bear', 'Snake', 'Turtle', 'Falcon', 'Shark', 'Octopus', 'Dolphin', 'Whale' ]; // Add event listener to spin button spinButton.addEventListener('click', () => { // Generate a random index for the animals array const randomIndex = Math.floor(Math.random() * animals.length); // Get the winning animal const winningAnimal = animals[randomIndex]; // Display the winning animal resultDiv.innerHTML = `You won: ${winningAnimal}!`; // Animate the wheel (optional) wheel.classList.add('animate'); setTimeout(() => { wheel.classList.remove('animate'); }, 3000); });
Css:
/* Global Styles */
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
}
/* Zoo Roulette Styles */
.zoo-roulette {
max-width: 800px;
margin: 40px auto;
text-align: center;
background-color: #fff;
padding: 20px;
border: 1px solid #ddd;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.wheel {
display: inline-block;
margin: 20px auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 50%;
background-color: #f7f7f7;
}
.animal {
display: inline-block;
margin: 10px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 50%;
background-color: #fff;
cursor: pointer;
}
.animal:hover {
background-color: #f7f7f7;
}
#spin-button {
background-color: #4CAF50;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
}
#spin-button:hover {
background-color: #3e8e41;
}
#result {
font-size: 24px;
font-weight: bold;
margin-top: 20px;
}
.animate {
transition: transform 3s ease-in-out;
transform: rotate(360deg);
}
0 Comments