Make me a restraunt simulator in html css and javascipt polished design and animations…
- User
Make me a restraunt simulator in html css and javascipt polished design and animations in one file.
- Assistant
Make me a restraunt simulator in html css and javascipt polished design and animations in one file.
Sure! Below is a complete, self-contained HTML file that implements a simple Restaurant Simulator using HTML, CSS, and JavaScript. The simulator includes a polished design with animations. You can copy the entire code into a .html file and open it in your browser to see it in action.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Restaurant Simulator</title>
<style>
/* Reset Styles */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* Body Styling */
body {
background-color: #f5f5f5;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
overflow: hidden;
}
/* Header */
header {
background-color: #ff6347;
color: white;
padding: 20px;
text-align: center;
font-size: 2em;
position: relative;
z-index: 2;
}
/* Game Container */
.game-container {
position: relative;
width: 100%;
height: calc(100vh - 80px);
background: url('https://i.imgur.com/8IuLkBm.jpg') no-repeat center center/cover;
overflow: hidden;
}
/* Kitchen Area */
.kitchen {
position: absolute;
width: 150px;
height: 150px;
background-color: #8B4513;
bottom: 20px;
left: 20px;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0,0,0,0.3);
display: flex;
align-items: center;
justify-content: center;
color: white;
font-weight: bold;
}
/* Customer Styles */
.customer {
position: absolute;
width: 50px;
height: 50px;
background-color: #FFD700;
border-radius: 50%;
animation: walkIn 3s linear forwards;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}
/* Order Popup */
.order {
position: absolute;
width: 100px;
height: 40px;
background-color: rgba(0,0,0,0.8);
color: white;
top: -50px;
left: 50%;
transform: translateX(-50%);
border-radius: 5px;
display: flex;
align-items: center;
justify-content: center;
opacity: 0;
animation: fadeIn 1s forwards;
pointer-events: none;
}
/* Animation for Customers Walking In */
@keyframes walkIn {
from { left: -100px; bottom: 20px; }
to { left: 60%; bottom: 20px; }
}
/* Fade In Animation */
@keyframes fadeIn {
to { opacity: 1; }
}
/* Serve Animation */
.serve {
animation: serveAnim 1s forwards;
}
@keyframes serveAnim {
0% { transform: translateY(0); opacity: 1; }
100% { transform: translateY(-100px); opacity: 0; }
}
/* Scoreboard */
.scoreboard {
position: absolute;
top: 20px;
right: 20px;
background-color: rgba(255,99,71,0.8);
color: white;
padding: 10px 20px;
border-radius: 10px;
font-size: 1.2em;
box-shadow: 0 4px 8px rgba(0,0,0,0.3);
z-index: 1;
}
/* Game Over Overlay */
.game-over {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: rgba(0,0,0,0.8);
color: white;
padding: 30px;
border-radius: 10px;
text-align: center;
display: none;
z-index: 3;
}
.game-over h1 {
margin-bottom: 20px;
font-size: 2em;
}
.game-over button {
padding: 10px 20px;
background-color: #ff6347;
border: none;
border-radius: 5px;
color: white;
font-size: 1em;
cursor: pointer;
transition: background-color 0.3s;
}
.game-over button:hover {
background-color: #e5533d;
}
</style>
</head>
<body>
<header>🍽️ Restaurant Simulator 🍽️</header>
<div class="game-container">
<div class="kitchen">Kitchen</div>
<div class="scoreboard">Score: <span id="score">0</span></div>
<div class="game-over" id="gameOver">
<h1>Game Over!</h1>
<p>Your Score: <span id="finalScore">0</span></p>
<button onclick="restartGame()">Restart</button>
</div>
</div>
<script>
// Game Variables
const gameContainer = document.querySelector('.game-container');
const scoreElement = document.getElementById('score');
const gameOverOverlay = document.getElementById('gameOver');
const finalScoreElement = document.getElementById('finalScore');
let score = 0;
let gameInterval;
let customerCount = 0;
let maxCustomers = 20; // Game ends after serving 20 customers
// Function to Generate Random Orders
const menu = ['Burger', 'Pizza', 'Salad', 'Sushi', 'Pasta', 'Steak'];
function getRandomOrder() {
return menu[Math.floor(Math.random() * menu.length)];
}
// Function to Create a Customer
function createCustomer() {
if (customerCount >= maxCustomers) {
endGame();
return;
}
customerCount++;
const customer = document.createElement('div');
customer.classList.add('customer');
// Position the customer at a random height
const height = Math.random() * 200 + 100; // Between 100px and 300px from bottom
customer.style.bottom = `${20}px`;
customer.style.left = `-100px`;
customer.style.transition = 'left 3s linear';
gameContainer.appendChild(customer);
// After a short delay, move the customer into the screen
setTimeout(() => {
customer.style.left = `60%`;
}, 100);
// Create Order
const order = document.createElement('div');
order.classList.add('order');
order.textContent = getRandomOrder();
customer.appendChild(order);
// Click Event to Serve
customer.addEventListener('click', () => serveCustomer(customer, order.textContent));
// Remove customer if not served within 10 seconds
setTimeout(() => {
if (gameContainer.contains(customer)) {
customer.remove();
subtractScore();
}
}, 10000); // 10 seconds
}
// Function to Serve Customer
function serveCustomer(customer, order) {
// Simulate serving with animation
const serveEffect = document.createElement('div');
serveEffect.classList.add('serve');
serveEffect.textContent = 'Served!';
customer.appendChild(serveEffect);
// Update Score
score++;
scoreElement.textContent = score;
// Remove customer after animation
setTimeout(() => {
customer.remove();
}, 1000);
}
// Function to Subtract Score for Unserved Customer
function subtractScore() {
score = Math.max(0, score - 1);
scoreElement.textContent = score;
}
// Function to Start the Game
function startGame() {
gameInterval = setInterval(createCustomer, 3000); // Every 3 seconds
}
// Function to End the Game
function endGame() {
clearInterval(gameInterval);
finalScoreElement.textContent = score;
gameOverOverlay.style.display = 'block';
}
// Function to Restart the Game
function restartGame() {
// Reset Variables
score = 0;
customerCount = 0;
scoreElement.textContent = score;
gameOverOverlay.style.display = 'none';
// Remove existing customers
const customers = document.querySelectorAll('.customer');
customers.forEach(c => c.remove());
// Restart Game
startGame();
}
// Start the Game on Load
window.onload = startGame;
</script>
</body>
</html>
Header: Displays the title of the simulator with an emoji for a friendly look.
Game Container: The main area where customers appear and interact.
Kitchen Area: Represents the kitchen where orders are prepared.
Customers:
Scoreboard: Keeps track of your current score.
Game Over Overlay: Appears when you've served a set number of customers (20 in this case), displaying your final score and an option to restart.
Animations:
Serve Customers: Click on the customers before they leave to serve them and earn points.
Score Management: Successfully serving a customer increases your score, while failing to serve decreases it.
Game Progression: The game continues until you've interacted with 20 customers. Once the game ends, you can choose to restart.
Menu Items: You can add or modify the items in the menu array within the JavaScript section to change the possible orders.
Maximum Customers: Adjust the maxCustomers variable to change when the game ends.
Customer Appearance Rate: Modify the interval in the startGame function to control how frequently new customers appear.
Feel free to enhance the simulator further by adding more features such as different customer types, more detailed animations, a money system, upgrades, and more!
Not yet included in a published release.