// A simple online cultivation simulation game
const readline = require('readline');
// Define the player class
class Player {
constructor(name) {
this.name = name;
this.level = 1;
this.experience = 0;
this.energy = 100;
this.realm = 'Mortal';
}
cultivate() {
if (this.energy > 0) {
const gainedExp = Math.floor(Math.random() * 10) + 1;
this.experience += gainedExp;
this.energy -= 10;
console.log(`${this.name} cultivated and gained ${gainedExp} experience points.`);
this.checkLevelUp();
} else {
console.log("Not enough energy to cultivate. Rest to recover energy.");
}
}
rest() {
const recoveredEnergy = Math.floor(Math.random() * 20) + 10;
this.energy = Math.min(100, this.energy + recoveredEnergy);
console.log(`${this.name} rested and recovered ${recoveredEnergy} energy.`);
}
checkLevelUp() {
const levelThreshold = this.level * 50;
if (this.experience >= levelThreshold) {
this.level++;
this.experience -= levelThreshold;
this.upgradeRealm();
console.log(`${this.name} leveled up to level ${this.level}!`);
}
}
upgradeRealm() {
const realms = ['Mortal', 'Foundation', 'Core Formation', 'Nascent Soul', 'Immortal'];
const newRealmIndex = Math.min(realms.length - 1, Math.floor(this.level / 5));
this.realm = realms[newRealmIndex];
console.log(`${this.name} has advanced to the ${this.realm} realm!`);
}
}
// Game logic
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function startGame() {
rl.question("Enter your cultivator's name: ", (name) => {
const player = new Player(name);
console.log(`Welcome, ${player.name}! Begin your cultivation journey in the ${player.realm} realm.`);
gameLoop(player);
});
}
function gameLoop(player) {
console.log("\nOptions: 1) Cultivate 2) Rest 3) Check Status 4) Exit");
rl.question("Choose an action: ", (choice) => {
switch (choice) {
case '1':
player.cultivate();
break;
case '2':
player.rest();
break;
case '3':
console.log(`\nName: ${player.name}\nLevel: ${player.level}\nExperience: ${player.experience}\nEnergy: ${player.energy}\nRealm: ${player.realm}`);
break;
case '4':
console.log("Exiting the game. Goodbye!");
rl.close();
return;
default:
console.log("Invalid choice. Try again.");
}
gameLoop(player);
});
}
startGame();