Creating a baby adoption simulation game involves several components: managing data (babies and adults), user interactions (adopting, caring, viewing adults), and a modern, animated interface. Below is a simplified version of such a game using HTML, CSS, and JavaScript. This prototype includes basic functionalities and can be expanded upon for more features.
Project Structure
adoption-game/
│
├── index.html
├── styles.css
└── script.js
1. HTML (index.html)
This file sets up the structure of the game, including sections for adopting babies, caring for them, and viewing adults.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Baby Adoption Game</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<h1>Baby Adoption Simulator</h1>
<nav>
<button id="adoptBtn">Adopt Baby</button>
<button id="homeBtn">Home</button>
<button id="adultsBtn">Adults</button>
</nav>
</header>
<main>
<!-- Adopt Baby Section -->
<section id="adoptSection" class="active">
<h2>Available Babies</h2>
<div id="babiesList" class="card-container">
<!-- Babies will be dynamically added here -->
</div>
</section>
<!-- Home Section -->
<section id="homeSection">
<h2>Your Babies</h2>
<div id="homeList" class="card-container">
<!-- Cared babies will be listed here -->
</div>
</section>
<!-- Adults Section -->
<section id="adultsSection">
<h2>Your Adults</h2>
<div id="adultsList" class="card-container">
<!-- Adults will be listed here -->
</div>
</section>
</main>
<footer>
<p>© 2023 Baby Adoption Game</p>
</footer>
<script src="script.js"></script>
</body>
</html>
2. CSS (styles.css)
This stylesheet provides a modern look with simple animations using CSS transitions.
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f0f4f8;
color: #333;
}
header {
background-color: #4a90e2;
color: white;
padding: 20px;
text-align: center;
position: sticky;
top: 0;
z-index: 1000;
}
nav {
margin-top: 10px;
}
nav button {
background-color: #fff;
color: #4a90e2;
border: none;
padding: 10px 20px;
margin: 0 5px;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}
nav button:hover {
background-color: #e6e6e6;
}
main {
padding: 20px;
}
section {
display: none;
animation: fadeIn 0.5s ease-in-out;
}
section.active {
display: block;
}
.card-container {
display: flex;
flex-wrap: wrap;
gap: 20px;
}
.card {
background-color: white;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
width: 200px;
padding: 15px;
text-align: center;
position: relative;
transition: transform 0.3s;
}
.card:hover {
transform: translateY(-10px);
}
.card img {
width: 100%;
border-radius: 10px;
}
.card button {
background-color: #4a90e2;
color: white;
border: none;
padding: 8px 12px;
border-radius: 5px;
cursor: pointer;
margin-top: 10px;
}
.card button:hover {
background-color: #357ab8;
}
footer {
background-color: #4a90e2;
color: white;
text-align: center;
padding: 10px;
position: fixed;
width: 100%;
bottom: 0;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
3. JavaScript (script.js)
This script manages the game logic, including adopting babies, caring for them over time, and promoting them to adults upon reaching 18.
// Data Structures
let availableBabies = [
{ id: 1, name: "Emma", image: "https://via.placeholder.com/200?text=Emma" },
{ id: 2, name: "Liam", image: "https://via.placeholder.com/200?text=Liam" },
{ id: 3, name: "Olivia", image: "https://via.placeholder.com/200?text=Olivia" }
];
let homeBabies = [];
let adults = [];
// DOM Elements
const adoptBtn = document.getElementById('adoptBtn');
const homeBtn = document.getElementById('homeBtn');
const adultsBtn = document.getElementById('adultsBtn');
const adoptSection = document.getElementById('adoptSection');
const homeSection = document.getElementById('homeSection');
const adultsSection = document.getElementById('adultsSection');
const babiesList = document.getElementById('babiesList');
const homeList = document.getElementById('homeList');
const adultsList = document.getElementById('adultsList');
// Event Listeners for Navigation
adoptBtn.addEventListener('click', () => showSection('adopt'));
homeBtn.addEventListener('click', () => showSection('home'));
adultsBtn.addEventListener('click', () => showSection('adults'));
// Function to show sections
function showSection(section) {
adoptSection.classList.remove('active');
homeSection.classList.remove('active');
adultsSection.classList.remove('active');
if (section === 'adopt') adoptSection.classList.add('active');
if (section === 'home') homeSection.classList.add('active');
if (section === 'adults') adultsSection.classList.add('active');
}
// Function to render available babies
function renderAvailableBabies() {
babiesList.innerHTML = '';
availableBabies.forEach(baby => {
const card = document.createElement('div');
card.className = 'card';
card.innerHTML = `
<img src="${baby.image}" alt="${baby.name}">
<h3>${baby.name}</h3>
<button onclick="adoptBaby(${baby.id})">Adopt</button>
`;
babiesList.appendChild(card);
});
}
// Function to adopt a baby
function adoptBaby(id) {
const babyIndex = availableBabies.findIndex(b => b.id === id);
if (babyIndex !== -1) {
const baby = availableBabies.splice(babyIndex, 1)[0];
baby.age = 0; // Start age at 0
baby.health = 100;
baby.happiness = 100;
baby.interval = setInterval(() => updateBabyStatus(baby.id), 1000);
homeBabies.push(baby);
renderAvailableBabies();
renderHomeBabies();
}
}
// Function to render home babies
function renderHomeBabies() {
homeList.innerHTML = '';
homeBabies.forEach(baby => {
const card = document.createElement('div');
card.className = 'card';
card.innerHTML = `
<img src="${baby.image}" alt="${baby.name}">
<h3>${baby.name}</h3>
<p>Age: ${baby.age}</p>
<p>Health: ${baby.health}</p>
<p>Happiness: ${baby.happiness}</p>
<button onclick="careForBaby(${baby.id})">Care</button>
`;
homeList.appendChild(card);
});
}
// Function to care for a baby
function careForBaby(id) {
const baby = homeBabies.find(b => b.id === id);
if (baby) {
baby.health = Math.min(baby.health + 10, 100);
baby.happiness = Math.min(baby.happiness + 10, 100);
renderHomeBabies();
}
}
// Function to update baby's status over time
function updateBabyStatus(id) {
const baby = homeBabies.find(b => b.id === id);
if (baby) {
baby.age += 1; // Age increases by 1 every second (for demo)
baby.health = Math.max(baby.health - 1, 0);
baby.happiness = Math.max(baby.happiness - 1, 0);
if (baby.health <= 0 || baby.happiness <= 0) {
alert(`${baby.name} has left your care unfortunately.`);
clearInterval(baby.interval);
homeBabies = homeBabies.filter(b => b.id !== id);
renderHomeBabies();
return;
}
if (baby.age >= 18) { // For demo, age 18 is reached quickly
promoteToAdult(baby);
clearInterval(baby.interval);
homeBabies = homeBabies.filter(b => b.id !== id);
renderHomeBabies();
} else {
renderHomeBabies();
}
}
}
// Function to promote a baby to adult
function promoteToAdult(baby) {
const occupations = ['Engineer', 'Doctor', 'Artist', 'Teacher', 'Developer'];
const adult = {
id: baby.id,
name: baby.name,
age: baby.age,
occupation: occupations[Math.floor(Math.random() * occupations.length)],
family: null // Can be expanded
};
adults.push(adult);
renderAdults();
}
// Function to render adults
function renderAdults() {
adultsList.innerHTML = '';
adults.forEach(adult => {
const card = document.createElement('div');
card.className = 'card';
card.innerHTML = `
<h3>${adult.name}</h3>
<p>Age: ${adult.age}</p>
<p>Occupation: ${adult.occupation}</p>
`;
adultsList.appendChild(card);
});
}
// Initialize the game
renderAvailableBabies();
renderHomeBabies();
renderAdults();
Explanation and Features
-
HTML Structure:
- Header: Contains the game title and navigation buttons.
- Main Sections:
- Adopt Section: Lists available babies to adopt.
- Home Section: Displays babies currently in your care.
- Adults Section: Shows adults who have left your home after turning 18.
- Footer: Simple footer for the game.
-
CSS Styling:
- Modern Look: Clean layout with soft colors and simple card designs.
- Animations:
- Fade-In: Sections appear smoothly when navigating.
- Hover Effects: Cards lift slightly on hover for interactivity.
- Responsive Design: Flexbox is used for responsive card layouts.
-
JavaScript Functionality:
- Data Management: Arrays to manage available babies, home babies, and adults.
- Adopting Babies: Users can adopt babies from the available list. Each adopted baby starts with age 0, health, and happiness at 100.
- Caring for Babies: Users can click "Care" to improve a baby's health and happiness.
- Baby Aging and Well-being:
- Babies age every second (this is for demonstration; you can adjust the timing).
- Health and happiness decrease over time, requiring the user to care for the babies regularly.
- If a baby's health or happiness drops to 0, they leave your care.
- When a baby reaches age 18, they are promoted to an adult with a randomly assigned occupation.
- Viewing Adults: Displays information about adults, including their name, age, and occupation.
-
Animations and Interactivity:
- CSS Transitions and Keyframes: Smooth transitions for navigation and card interactions.
- Dynamic Rendering: JavaScript updates the UI dynamically based on data changes.
Enhancements and Next Steps
This prototype provides a foundational structure for the baby adoption game. Here are some suggestions to enhance the game:
-
Persistent Storage:
- Use
localStorage or a backend database to save the game state, allowing users to continue where they left off.
-
Detailed Adult Profiles:
- Expand the
adult object to include family information, more detailed occupations, and other personal attributes.
-
Enhanced Care Mechanics:
- Introduce more actions like feeding, playing, education, etc., affecting health and happiness differently.
-
Graphics and Assets:
- Replace placeholder images with custom graphics.
- Add more animations using libraries like GSAP for more complex animations.
-
User Interface Improvements:
- Implement better UI/UX design with responsive layouts for various devices.
- Add modals or pop-ups for detailed views and interactions.
-
Scaling Time:
- Adjust the aging and status decrease rates to more realistic timing (e.g., days, months, years).
-
Sound Effects and Music:
- Add background music and sound effects to enhance the gaming experience.
-
Additional Features:
- Introduce events or challenges that affect babies or adults.
- Implement a scoring or achievement system.
Conclusion
This basic implementation demonstrates how to create an interactive baby adoption game using HTML, CSS, and JavaScript. By expanding upon these foundations, you can develop a more comprehensive and engaging game. Feel free to customize the design, add new features, and enhance the interactivity to suit your vision.
If you have any specific questions or need further assistance with particular features, feel free to ask!