import React, { useState, useEffect } from "react";
 
const INITIAL_GAME = {
date: "2026-12-05",
age: 18,
day: 1,
character: "Princess Arabella",
title: "Her Royal Highness",
location: "Aveloria Royal Palace",
money: 250000,
health: 95,
happiness: 85,
reputation: 80,
education: 75,
stress: 15,
relationships: {
Alexander: 90,
Nicholas: 85,
Father: 75,
Mother: 90,
"Second Heir": 70
},
flags: {
dating: false,
engaged: false,
married: false,
children: 0
},
events: [
"Arabella begins her royal journey at age 18."
],
news: [
"Princess Arabella continues her royal education."
],
history: [],
activity: "Enjoying royal life"
};
 
const tabs = [
"Dashboard",
"My Life",
"Royal Family",
"Relationships",
"Royal Duties",
"Kingdom",
"News",
"History"
];
 
export default function PrincessGame() {
const [game, setGame] = useState(() => {
try {
return JSON.parse(localStorage.getItem("aveloria-save")) || INITIAL_GAME;
} catch {
return INITIAL_GAME;
}
});
 
const [tab, setTab] = useState("Dashboard");
const [notification, setNotification] = useState("");
const [event, setEvent] = useState(null);
 
useEffect(() => {
localStorage.setItem("aveloria-save", JSON.stringify(game));
}, [game]);
 
const notify = (message) => {
setNotification(message);
setTimeout(() => setNotification(""), 3000);
};
 
const update = (changes) => {
setGame(prev => ({ ...prev, ...changes }));
};
 
const relationship = (name, amount) => {
setGame(prev => ({
...prev,
relationships: {
...prev.relationships,
[name]: Math.max(
0,
Math.min(100, prev.relationships[name] + amount)
)
}
}));
};
 
const record = (message) => {
setGame(prev => ({
...prev,
events: [message, ...prev.events]
}));
};
 
const advanceDay = () => {
setGame(prev => {
const nextDate = new Date(prev.date + "T12:00:00");
nextDate.setDate(nextDate.getDate() + 1);
 
const newDate = nextDate.toISOString().split("T")[0];
const birthday = nextDate.getMonth() === 5 &&
nextDate.getDate() === 15;
 
return {
...prev,
date: newDate,
age: birthday ? prev.age + 1 : prev.age,
day: prev.day + 1,
stress: Math.max(0, prev.stress - 2),
history: [
`Day ${prev.day}: ${prev.activity}`,
...prev.history
].slice(0, 100)
};
});
 
notify("A new day begins in Aveloria.");
};
 
const action = (name, changes, message) => {
setGame(prev => ({
...prev,
...changes,
activity: name,
events: [message, ...prev.events],
history: [
`Day ${prev.day}: ${name}`,
...prev.history
].slice(0, 100)
}));
advanceDayAfterAction();
};
 
const advanceDayAfterAction = () => {
setGame(prev => {
const date = new Date(prev.date + "T12:00:00");
date.setDate(date.getDate() + 1);
 
const birthday = date.getMonth() === 5 &&
date.getDate() === 15;
 
return {
...prev,
date: date.toISOString().split("T")[0],
day: prev.day + 1,
age: birthday ? prev.age + 1 : prev.age,
stress: Math.max(0, prev.stress - 1)
};
});
};
 
const romance = (kind) => {
if (kind === "date") {
if (game.flags.married) {
notify("You are already married.");
return;
}
 
if (game.flags.engaged) {
notify("You are already engaged.");
return;
}
 
if (game.relationships.Nicholas < 40) {
notify("Nicholas needs more time to develop feelings.");
return;
}
 
relationship("Nicholas", 5);
action(
"Private meeting with Nicholas",
{ happiness: Math.min(100, game.happiness + 8) },
"Arabella spends a private evening with Prince Nicholas."
);
}
 
if (kind === "proposal") {
if (game.relationships.Nicholas < 85) {
notify("Your relationship needs more trust before a proposal.");
return;
}
 
if (game.flags.engaged || game.flags.married) return;
 
update({
flags: { ...game.flags, engaged: true }
});
relationship("Nicholas", 3);
record("Prince Nicholas and Princess Arabella announce their engagement.");
notify("Engagement accepted!");
}
 
if (kind === "marry") {
if (!game.flags.engaged) {
notify("You must be engaged first.");
return;
}
 
update({
flags: {
...game.flags,
engaged: false,
married: true
}
});
record("The royal wedding of Arabella and Nicholas takes place.");
notify("A royal wedding!");
}
};
 
const generateEvent = () => {
const events = [
{
title: "An Invitation to the Palace",
description: "The King invites Arabella to a private family meeting.",
choices: [
{
label: "Attend the meeting",
result: "The King appreciates your presence.",
changes: { reputation: 3 }
},
{
label: "Decline politely",
result: "The King is slightly disappointed.",
changes: { reputation: -2 }
}
]
},
{
title: "A Newspaper Story",
description: "A newspaper publishes an article about Arabella's public image.",
choices: [
{
label: "Release an official statement",
result: "The palace clarifies the situation.",
changes: { reputation: 3, money: -500 }
},
{
label: "Remain silent",
result: "The story continues circulating.",
changes: { stress: 5 }
}
]
},
{
title: "Alexander's Health",
description: "Crown Prince Alexander requests a private conversation.",
choices: [
{
label: "Spend time with him",
result: "Alexander appreciates his sister's support.",
changes: { happiness: 5 }
},
{
label: "Attend another engagement",
result: "Alexander understands, although he feels disappointed.",
changes: { stress: 3 }
}
]
},
{
title: "A Diplomatic Reception",
description: "A foreign royal family invites Arabella to an official reception.",
choices: [
{
label: "Accept the invitation",
result: "Arabella strengthens Aveloria's diplomatic relationships.",
changes: { reputation: 4, stress: 3 }
},
{
label: "Decline",
result: "The invitation is politely declined.",
changes: { reputation: -2 }
}
]
}
];
 
const selected = events[Math.floor(Math.random() * events.length)];
setEvent(selected);
};
 
const chooseEvent = (choice) => {
update({
...choice.changes
});
 
record(choice.result);
setEvent(null);
advanceDayAfterAction();
notify(choice.result);
};
 
const saveGame = () => {
localStorage.setItem("aveloria-save", JSON.stringify(game));
notify("Game saved successfully.");
};
 
const loadNewGame = () => {
if (window.confirm("Start a new game? Existing progress will be replaced.")) {
setGame(INITIAL_GAME);
setEvent(null);
notify("New game started.");
}
};
 
const Stat = ({ label, value }) => (
<div className="space-y-1">
<div className="flex justify-between text-sm">
<span>{label}</span>
<b>{value}/100</b>
</div>
<div className="h-2 rounded-full bg-stone-200 overflow-hidden">
<div
className="h-full bg-[#a88a54] rounded-full transition-all"
style={{ width: `${Math.max(0, Math.min(100, value))}%` }}
/>
</div>
</div>
);
 
const Button = ({ children, onClick }) => (
<button
onClick={onClick}
className="bg-[#14263e] hover:bg-[#263d59] text-white px-4 py-3 rounded-lg text-sm transition"
>
{children}
</button>
);
 
return (
<div className="min-h-screen bg-[#f4f0e8] text-[#252525] font-sans">
<header className="bg-[#14263e] text-white p-6 text-center border-b-4 border-[#b69a60]">
<div className="text-[#d5bc83] text-xs tracking-[5px] mb-2">
THE KINGDOM OF AVELORIA
</div>
<h1 className="text-3xl md:text-4xl font-serif tracking-wide">
PRINCESS: A SINGLE LIFE
</h1>
<p className="text-sm text-stone-300 mt-2">
Royal Life Simulation
</p>
</header>
 
<nav className="bg-[#203650] flex gap-2 p-3 overflow-x-auto">
{tabs.map(item => (
<button
key={item}
onClick={() => setTab(item)}
className={`whitespace-nowrap px-4 py-2 rounded text-sm ${
tab === item
? "bg-[#b69a60] text-[#14263e]"
: "text-white hover:bg-white/10"
}`}
>
{item}
</button>
))}
</nav>
 
<main className="max-w-6xl mx-auto p-4 md:p-7 space-y-5">
 
{notification && (
<div className="bg-[#e7dfca] border border-[#b69a60] p-3 rounded-lg text-center">
{notification}
</div>
)}
 
{event && (
<div className="bg-white border-2 border-[#b69a60] rounded-xl p-6 space-y-4 shadow">
<div className="text-xs tracking-widest text-[#9a7941]">
SPECIAL EVENT
</div>
<h2 className="text-2xl font-serif">{event.title}</h2>
<p>{event.description}</p>
{event.choices.map((choice, index) => (
<Button key={index} onClick={() => chooseEvent(choice)}>
{choice.label}
</Button>
))}
</div>
)}
 
{tab === "Dashboard" && (
<>
<section className="bg-[#14263e] text-white rounded-xl p-6 md:p-8">
<p className="text-[#d5bc83] tracking-widest text-xs">
HER ROYAL HIGHNESS
</p>
<h2 className="text-3xl font-serif mt-2">
Princess Arabella
</h2>
<p className="text-stone-300 mt-2">
{game.title} · Age {game.age}
</p>
<div className="grid grid-cols-2 md:grid-cols-4 gap-4 mt-7">
<div>
<p className="text-xs text-stone-400">DATE</p>
<p className="font-semibold">{game.date}</p>
</div>
<div>
<p className="text-xs text-stone-400">LOCATION</p>
<p className="font-semibold">{game.location}</p>
</div>
<div>
<p className="text-xs text-stone-400">WEALTH</p>
<p className="font-semibold">
£{game.money.toLocaleString()}
</p>
</div>
<div>
<p className="text-xs text-stone-400">MARITAL STATUS</p>
<p className="font-semibold">
{game.flags.married ? "Married" :
game.flags.engaged ? "Engaged" :
"Single"}
</p>
</div>
</div>
</section>
 
<div className="grid md:grid-cols-2 gap-5">
<section className="bg-white p-5 rounded-xl shadow-sm space-y-4">
<h3 className="font-serif text-xl">Personal Statistics</h3>
<Stat label="Health" value={game.health}/>
<Stat label="Happiness" value={game.happiness}/>
<Stat label="Public Reputation" value={game.reputation}/>
<Stat label="Education" value={game.education}/>
<Stat label="Stress" value={game.stress}/>
</section>
 
<section className="bg-white p-5 rounded-xl shadow-sm space-y-3">
<h3 className="font-serif text-xl">Daily Activities</h3>
<Button onClick={() => action(
"Studying royal history",
{ education: Math.min(100, game.education + 3) },
"Arabella spends the day studying royal history."
)}>Study royal history</Button>
 
<Button onClick={() => action(
"Relaxing in the gardens",
{ happiness: Math.min(100, game.happiness + 5) },
"Arabella enjoys a peaceful afternoon in the palace gardens."
)}>Relax in gardens</Button>
 
<Button onClick={() => action(
"Exercise",
{ health: Math.min(100, game.health + 3) },
"Arabella completes her daily exercise."
)}>Exercise</Button>
 
<Button onClick={() => action(
"Private royal audience",
{ reputation: Math.min(100, game.reputation + 2) },
"Arabella attends a private royal audience."
)}>Attend royal audience</Button>
</section>
</div>
 
<section className="bg-white rounded-xl p-5 shadow-sm">
<h3 className="font-serif text-xl mb-3">Recent Events</h3>
{game.events.slice(0, 5).map((item, i) => (
<p key={i} className="border-b py-3 text-sm">{item}</p>
))}
</section>
 
<div className="flex flex-wrap gap-3">
<Button onClick={advanceDay}>End Day →</Button>
<Button onClick={generateEvent}>Generate Event</Button>
<Button onClick={saveGame}>Save Game</Button>
</div>
</>
)}
 
{tab === "My Life" && (
<section className="bg-white p-6 rounded-xl space-y-4">
<h2 className="text-2xl font-serif">My Life</h2>
<p>Name: Princess Arabella</p>
<p>Age: {game.age}</p>
<p>Title: {game.title}</p>
<p>Residence: {game.location}</p>
<p>Education: {game.education}/100</p>
<p>Personal Wealth: £{game.money.toLocaleString()}</p>
<p>Status: {game.flags.married ? "Married" : game.flags.engaged ? "Engaged" : "Single"}</p>
</section>
)}
 
{tab === "Royal Family" && (
<section className="bg-white p-6 rounded-xl space-y-4">
<h2 className="text-2xl font-serif">The Royal Family</h2>
{[
["King", "Father", "Monarch"],
["Queen", "Mother", "Queen Consort"],
["Alexander", "Eldest brother", "Crown Prince"],
["Second Heir", "Older brother", "Royal Prince"],
["Arabella", "Youngest child", "Princess"]
].map(([name, relation, title]) => (
<div key={name} className="border rounded-lg p-4">
<b>{name}</b>
<p className="text-sm text-stone-500">{relation} · {title}</p>
</div>
))}
</section>
)}
 
{tab === "Relationships" && (
<section className="bg-white p-6 rounded-xl space-y-5">
<h2 className="text-2xl font-serif">Relationships</h2>
{Object.entries(game.relationships).map(([name, value]) => (
<Stat key={name} label={name} value={value}/>
))}
<div className="border-t pt-5 space-y-3">
<h3 className="font-serif text-xl">Nicholas</h3>
<p>Relationship status: {game.flags.married ? "Husband" : game.flags.engaged ? "Fiancé" : game.flags.dating ? "Dating" : "Unmarried"}</p>
<Button onClick={() => romance("date")}>Spend time with Nicholas</Button>
<Button onClick={() => romance("proposal")}>Propose marriage</Button>
<Button onClick={() => romance("marry")}>Arrange royal wedding</Button>
</div>
</section>
)}
 
{tab === "Royal Duties" && (
<section className="bg-white p-6 rounded-xl space-y-4">
<h2 className="text-2xl font-serif">Royal Duties</h2>
<p>Represent the Crown through official engagements.</p>
<Button onClick={() => action(
"Hospital charity visit",
{ reputation: Math.min(100, game.reputation + 5), stress: Math.min(100, game.stress + 3) },
"Arabella visits a children's hospital."
)}>Visit children's hospital</Button>
<Button onClick={() => action(
"Charity event",
{ reputation: Math.min(100, game.reputation + 3), money: game.money - 1000 },
"Arabella attends a royal charity fundraiser."
)}>Attend charity event</Button>
<Button onClick={() => action(
"Diplomatic reception",
{ reputation: Math.min(100, game.reputation + 4) },
"Arabella welcomes foreign dignitaries."
)}>Attend diplomatic reception</Button>
</section>
)}
 
{tab === "Kingdom" && (
<section className="bg-white p-6 rounded-xl space-y-4">
<h2 className="text-2xl font-serif">Kingdom of Aveloria</h2>
<p>Government: Constitutional Monarchy</p>
<p>Head of State: King of Aveloria</p>
<p>Royal Heir: Crown Prince Alexander</p>
<p>Royal Household: Aveloria Royal Palace</p>
<p>Princess Arabella's public reputation: {game.reputation}/100</p>
<div className="border-t pt-4">
<p className="font-semibold">Constitutional principle</p>
<p className="text-sm text-stone-600">
The monarch serves as head of state. Elected representatives
and the government manage ordinary political affairs.
</p>
</div>
</section>
)}
 
{tab === "News" && (
<section className="bg-white p-6 rounded-xl space-y-4">
<h2 className="text-2xl font-serif">Aveloria Daily</h2>
{game.news.map((item, i) => (
<article key={i} className="border-b pb-4">
<p className="text-xs text-[#a88a54]">ROYAL NEWS</p>
{item}
</article>
))}
<Button onClick={() => {
const headlines = [
"Royal observers discuss Princess Arabella's growing public profile.",
"The Crown prepares for another season of royal engagements.",
"Aveloria's royal household announces upcoming activities."
];
const headline = headlines[Math.floor(Math.random() * headlines.length)];
update({ news: [headline, ...game.news] });
}}>Check latest headlines</Button>
</section>
)}
 
{tab === "History" && (
<section className="bg-white p-6 rounded-xl space-y-4">
<h2 className="text-2xl font-serif">Life History</h2>
{game.history.length === 0
? <p>No previous activities recorded.</p>
: game.history.map((item, i) => (
<p key={i} className="border-b pb-3 text-sm">{item}</p>
))
}
<h3 className="font-serif text-lg pt-3">Important Events</h3>
{game.events.map((item, i) => (
<p key={i} className="text-sm border-b pb-2">{item}</p>
))}
</section>
)}
 
<footer className="flex flex-wrap gap-3 border-t pt-5">
<Button onClick={saveGame}>Save Progress</Button>
<Button onClick={() => {
const data = JSON.stringify(game, null, 2);
const blob = new Blob([data], {type: "application/json"});
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = "aveloria-save.json";
link.click();
URL.revokeObjectURL(url);
}}>Export Save</Button>
<Button onClick={loadNewGame}>New Game</Button>
</footer>
</main>
</div>
);
}
 
Code will run automatically after changes.
TryCode — realtime collaborative code editor | game 1