Here's a simple pasta maker game in a single HTML file using HTML5, CSS, and JavaScript. Players can drag and drop ingredients to make pasta:
html
<!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 {
margin: 0;
padding: 20px;
font-family: Arial, sans-serif;
background-color: #f0f0f0;
touch-action: none;
}
#game-container {
max-width: 600px;
margin: 0 auto;
}
#ingredients-container {
display: flex;
justify-content: space-around;
flex-wrap: wrap;
margin-bottom: 20px;
}
.ingredient {
width: 80px;
height: 80px;
background-color: #fff;
border: 2px solid #333;
border-radius: 10px;
display: flex;
align-items: center;
justify-content: center;
margin: 5px;
cursor: pointer;
user-select: none;
touch-action: none;
}
#bowl {
width: 200px;
height: 200px;
background-color: #ddd;
border: 3px solid #666;
border-radius: 50%;
margin: 0 auto;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
#controls {
text-align: center;
margin-top: 20px;
}
button {
padding: 10px 20px;
font-size: 16px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
margin: 5px;
}
button:disabled {
background-color: #cccccc;
cursor: not-allowed;
}
#score {
text-align: center;
font-size: 24px;
margin-top: 20px;
}
</style>
</head>
<body>
<div id="game-container">
<div id="score">Score: <span id="score-value">0</span></div>
<div id="ingredients-container">
<div class="ingredient" draggable="true" data-type="flour">Flour</div>
<div class="ingredient" draggable="true" data-type="egg">Egg</div>
<div class="ingredient" draggable="true" data-type="water">Water</div>
<div class="ingredient" draggable="true" data-type="salt">Salt</div>
</div>
<div id="bowl">
<div id="bowl-contents">Empty</div>
</div>
<div id="controls">
<button id="mix-button" disabled>Mix Ingredients</button>
<button id="cook-button" disabled>Cook Pasta</button>
<button id="reset-button">Reset</button>
</div>
</div>
<script>
const bowl = document.getElementById('bowl');
const bowlContents = document.getElementById('bowl-contents');
const mixButton = document.getElementById('mix-button');
const cookButton = document.getElementById('cook-button');
const resetButton = document.getElementById('reset-button');
const scoreValue = document.getElementById('score-value');
let ingredients = [];
let score = 0;
let isMixed = false;
// Initialize drag and drop for ingredients
document.querySelectorAll('.ingredient').forEach(ingredient => {
ingredient.addEventListener('touchstart', handleDragStart);
ingredient.addEventListener('touchmove', handleDragMove);
ingredient.addEventListener('touchend', handleDragEnd);
});
function handleDragStart(e) {
if (e.type === 'touchstart') {
e.preventDefault();
this.classList.add('dragging');
}
}
function handleDragMove(e) {
if (e.type === 'touchmove') {
e.preventDefault();
const touch = e.touches[0];
this.style.position = 'fixed';
this.style.left = touch.pageX - this.offsetWidth / 2 + 'px';
this.style.top = touch.pageY - this.offsetHeight / 2 + 'px';
}
}
function handleDragEnd(e) {
if (e.type === 'touchend') {
e.preventDefault();
this.classList.remove('dragging');
this.style.position = '';
const touch = e.changedTouches[0];
const bowlRect = bowl.getBoundingClientRect();
if (touch.pageX >= bowlRect.left &&
touch.pageX <= bowlRect.right &&
touch.pageY >= bowlRect.top &&
touch.pageY <= bowlRect.bottom) {
addIngredient(this.dataset.type);
}
}
}
function addIngredient(type) {
if (!ingredients.includes(type)) {
ingredients.push(type);
updateBowlContents();
checkMixability();
}
}
function updateBowlContents() {
if (ingredients.length === 0) {
bowlContents.textContent = 'Empty';
} else {
bowlContents.textContent = ingredients.join(', ');
}
}
function checkMixability() {
mixButton.disabled = ingredients.length < 2;
}
mixButton.addEventListener('click', () => {
isMixed = true;
bowlContents.textContent = 'Mixed Pasta Dough';
mixButton.disabled = true;
cookButton.disabled = false;
});
cookButton.addEventListener('click', () => {
if (isMixed) {
const hasRequiredIngredients =
ingredients.includes('flour') &&
ingredients.includes('egg') &&
ingredients.includes('water');
if (hasRequiredIngredients) {
score += 10;
scoreValue.textContent = score;
bowlContents.textContent = 'Delicious Pasta!';
} else {
bowlContents.textContent = 'Failed Recipe!';
}
cookButton.disabled = true;
}
});
resetButton.addEventListener('click', () => {
ingredients = [];
isMixed = false;
updateBowlContents();
mixButton.disabled = true;
cookButton.disabled = true;
});
</script>
</body>
</html>
This code creates a simple pasta maker game where players can:
- Drag and drop ingredients into the bowl
- Mix the ingredients
- Cook the pasta
- Score points for successful recipes
Features:
- Touch-enabled for mobile devices
- Simple drag and drop interface
- Basic scoring system
- Recipe validation
- Reset functionality
To make pasta successfully, players need to:
- Add flour, egg, and water (salt is optional)
- Click the Mix button
- Click the Cook button
The game will award 10 points for each successful pasta creation.
To use this game:
- Save the code as an HTML file
- Open it in a mobile browser
- Start playing by dragging ingredients into the bowl
Note that this is a basic version of the game. You can enhance it by:
- Adding more ingredients
- Creating different pasta recipes
- Adding animations
- Implementing time limits
- Adding sound effects
- Creating levels with increasing difficulty
- Adding more visual feedback