-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #811 from 2222k3060/patch-9
Create Bottle flip game.html
- Loading branch information
Showing
1 changed file
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |