Creating a full-fledged mobile game like a "Pasta Maker" in a single HTML file is a challenging task, as it involves multiple components such as graphics, animations, and user interactions. However, I can provide you with a simplified version of a "Pasta Maker" game using HTML, CSS, and JavaScript. This version will be basic and can be expanded upon for more complexity.
Here’s the single HTML file code for a basic Pasta Maker game:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pasta Maker Game</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f8efd4;
}
#game-container {
text-align: center;
background: #fff;
border: 2px solid #ccc;
border-radius: 10px;
padding: 20px;
width: 90%;
max-width: 400px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
h1 {
color: #d35400;
}
.ingredient {
display: inline-block;
margin: 10px;
padding: 10px 20px;
background-color: #f39c12;
color: white;
border-radius: 5px;
cursor: pointer;
transition: transform 0.2s;
}
.ingredient:hover {
transform: scale(1.1);
}
#pasta-bowl {
margin: 20px auto;
width: 100%;
max-width: 300px;
height: 150px;
background-color: #f5cba7;
border-radius: 10px;
border: 2px solid #d35400;
position: relative;
overflow: hidden;
}
.added-ingredient {
position: absolute;
left: 50%;
transform: translateX(-50%);
font-size: 14px;
color: #fff;
background-color: #e74c3c;
padding: 5px 10px;
border-radius: 5px;
animation: drop 1s ease-out forwards;
}
@keyframes drop {
0% {
top: -50px;
opacity: 0;
}
50% {
opacity: 1;
}
100% {
top: 80%;
opacity: 1;
}
}
#reset-btn {
margin-top: 20px;
padding: 10px 20px;
background-color: #27ae60;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}
#reset-btn:hover {
background-color: #2ecc71;
}
</style>
</head>
<body>
<div id="game-container">
<h1>Pasta Maker Game</h1>
<p>Click on the ingredients to add them to your pasta bowl!</p>
<div id="ingredients">
<div class="ingredient" data-ingredient="Tomato Sauce">Tomato Sauce</div>
<div class="ingredient" data-ingredient="Cheese">Cheese</div>
<div class="ingredient" data-ingredient="Mushrooms">Mushrooms</div>
<div class="ingredient" data-ingredient="Basil">Basil</div>
</div>
<div id="pasta-bowl"></div>
<button id="reset-btn">Reset Bowl</button>
</div>
<script>
const ingredients = document.querySelectorAll('.ingredient');
const pastaBowl = document.getElementById('pasta-bowl');
const resetButton = document.getElementById('reset-btn');
// Add event listeners to ingredients
ingredients.forEach(ingredient => {
ingredient.addEventListener('click', () => {
const ingredientName = ingredient.getAttribute('data-ingredient');
addIngredientToBowl(ingredientName);
});
});
// Function to add ingredient to the bowl
function addIngredientToBowl(ingredientName) {
const ingredientElement = document.createElement('div');
ingredientElement.classList.add('added-ingredient');
ingredientElement.textContent = ingredientName;
pastaBowl.appendChild(ingredientElement);
// Remove ingredient after animation
setTimeout(() => {
ingredientElement.remove();
}, 2000);
}
// Reset button functionality
resetButton.addEventListener('click', () => {
pastaBowl.innerHTML = '';
});
</script>
</body>
</html>
How It Works:
- Ingredients: The game has a list of clickable ingredients (e.g., Tomato Sauce, Cheese, Mushrooms, Basil).
- Pasta Bowl: When you click on an ingredient, it gets added to the pasta bowl with a simple animation.
- Reset Button: The reset button clears the pasta bowl.
Features:
- Basic animations for adding ingredients.
- A reset button to clear the bowl.
- Mobile-friendly design with responsive layout.
How to Expand:
- Add more ingredients.
- Include a scoring system or timer.
- Add sound effects for interactions.
- Use images for ingredients instead of text.
- Add levels or challenges (e.g., make a specific pasta recipe).
You can copy and paste this code into an .html file and open it in a browser to play the game.