Karob
by Sam Fereday
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/EventEmitter/5.2.2/EventEmitter.min.js"></script>
<button id="send">
Send
</button>
<button id="heal">
Heal
</button>
<button id="train">
Train
</button>
JavaScript
/*
Brief:
Create a hero sim that fits within a low resolution area. Designs will be needed.
You must have the ability to:
- Raise your hero from a young age until the day they depart, making as much fame, change or riches that you can (no infamy however, that'll just be extra dev time needed that I can't give)
- Send your hero on quests whom will return empty handed, with something, leveled up, etc. The mission will be a success or failure depending on their combined stats against the mission difficulty
- Whilst the hero is home, you must tend to their wounds, training needs, food, and sleep
- The above will cost money and resources to survive, so if you run out, they effectively perish
- Whilst it is just a sim, you can call a success when the hero obtains legendary status on either side of the spectrum. Should they perish with this status due to old age or battle, they'll be marked as a hero (will leave out the villain part this time)
Application structure:
The app will be divided between the main stage, which is a global context for the game that'll house things like hero fame, loot, quests and all that.
And the hero, which will be an entity with its own update cycle that will handle quests and travelling. It need not be complicated, it just makes more claritive sense to be separate. the two will still communicate of course.
Finally, a UI layer on top of this.
*/
// Helpers // clamp(value, current, max, min(optional));
function clamp(v, c, mx, mn) {
let n = v + c;
mn = mn ? mn : 0;
return n < mn ? mn : (n > mx ? mx : n);
}
// Data
let aQuest = {
name: "A nice quest",
difficulty: 10,
reward: {
exp: 100,
gil: 20,
fame: 1
}
};
const EVENTS = {
ATHOME: 'onReturned',
ATQUEST: 'onArrival',
RETURNING: 'onReturning',
STOPPEDTRAINING: 'onStoppedTraining'
}
const ACTIONS = {
IDLE: 0,
TRAIN: 1,
QUEST: 2,
HEAL: 3
}
const STATACTIONS = {
GIVEEXP: 4
}
// To add mixins
const ee = new EventEmitter();
// Level helper
let...