Skip to content

Commit

Permalink
Merge pull request #811 from 2222k3060/patch-9
Browse files Browse the repository at this point in the history
Create Bottle flip game.html
  • Loading branch information
Ayushparikh-code authored Oct 29, 2024
2 parents 2190c76 + 20fbbe8 commit 708fa06
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions Bottle flip game.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bottle Flip Game</title>
<style>
body {
font-family: 'Arial', sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
background-color: #f4f4f4;
}

h1 {
margin-bottom: 20px;
color: #333;
}

.bottle {
width: 100px;
height: 300px;
background: url('https://static.vecteezy.com/system/resources/previews/012/628/136/non_2x/transparent-plastic-bottle-on-transparent-background-free-png.png') no-repeat center;
background-size: cover;
transform-origin: bottom;
transition: transform 1s ease-in-out;
}

.container {
display: flex;
flex-direction: column;
align-items: center;
}

button {
padding: 10px 15px;
font-size: 18px;
margin-top: 20px;
background-color: #28a745;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
outline: none;
}

button:hover {
background-color: #218838;
}

.result {
font-size: 24px;
font-weight: bold;
margin-top: 20px;
}
</style>
</head>
<body>

<div class="container">
<h1>Bottle Flip Game</h1>
<div class="bottle" id="bottle"></div>
<button onclick="flipBottle()">Flip the Bottle</button>
<div class="result" id="result"></div>
</div>

<script>
function flipBottle() {
var bottle = document.getElementById('bottle');
var result = document.getElementById('result');

// Reset the result text
result.textContent = '';

// Randomly determine the rotation angle (between 360 and 1080 degrees)
var rotation = Math.floor(Math.random() * 720) + 360;

// Apply the rotation to the bottle
bottle.style.transform = 'rotate(' + rotation + 'deg)';

// Determine if the flip was successful (approximate upright position)
setTimeout(function() {
if (rotation % 360 >= 330 || rotation % 360 <= 30) {
result.textContent = 'Success! 🏆';
result.style.color = 'green';
} else {
result.textContent = 'Fail! 😢';
result.style.color = 'red';
}
}, 1000);
}
</script>

</body>
</html>

0 comments on commit 708fa06

Please sign in to comment.