Goals, Hints, and Scores: Scorecard Longhand
Scorecards are a system for creating points, updating a player's score, printing score update messages, and setting the score in the status bar. The longhand method shown here offers a more control than the shorthand method, by letting authors create goal objects directly. The longhand method takes plain Javascript objects, and uses them to build goal data objects. Each point consists minimally of a name and a point value, though the longhand method also allows authors to customize several other score properties.
Example Code
MyGame.scorecard.set({
"take lamp": 1,
"take sword": 1,
"kill orc": 1,
"get key": 1,
"unlock chest": 1,
"take treasure": 1,
// Set negative points
"eat orc": -5,
// Customize a point's messaging
"eat treasure": {
value: 1,
award_text: "[ ** Whoa! Who thought THAT would work? ** ]",
},
// Bonus points are counted above the game's maximum score
"drop treasure": {
value: 1,
bonus: true
},
// Set points before game start
"preset points": {
value: 5,
awarded: true, // this must be true
recorded: true // this must be true
},
// If true and multiple points are earned simultaneously,
// scorecard will print a summary rather than multiple messages.
summarize_updates: true,
});
example game
var MyGame = new adventurejs.Game("MyGame", "MyGameDisplay");
MyGame.settings.set({
debug: {
general: true,
},
});
MyGame.disableAllVerbsBut([
"take",
"kill",
"score",
"unlock",
"open",
"eat",
"drop",
"look",
"examine",
]);
MyGame.scorecard.set({
points: {
"take lamp": 1,
"take sword": 1,
"kill orc": 1,
"take key": 1,
"unlock chest": 1,
"take treasure": 1,
// Set negative points
"eat orc": -1,
// Customize a point's messaging
"eat treasure": {
value: 1,
award_text: "[ ** Whoa! Who would've thought THAT would work? ** ]",
},
// Bonus points are counted above the game's maximum score
"drop treasure": {
value: 1,
bonus: true,
},
// Set points before game start
"preset points": {
value: 94,
awarded: true, // this must be true
recorded: true, // this must be true
},
},
// If true and multiple points are earned simultaneously,
// scorecard will print a summary rather than multiple messages.
summarize_updates: true,
});
MyGame.createAsset({
class: "Room",
name: "Vault",
description: `This small vault houses a modest treasure. `,
});
MyGame.createAsset({
class: "Player",
name: "MyHero",
});
// lamp
MyGame.createAsset({
class: "Lantern",
name: "lamp",
place: { in: "Vault" },
doTake: function () {
MyGame.scorecard.awardPoint("take lamp");
},
});
// sword
MyGame.createAsset({
class: "Sword",
name: "sword",
place: { in: "Vault" },
doTake: function () {
MyGame.scorecard.awardPoint("take sword");
},
});
// orc
const orc = MyGame.createAsset({
class: "NPC",
name: "orc",
a: "an", // <- shortcut to asset.indefinite_article
use_proper_name: false,
use_definite_article: true,
place: { in: "Vault" },
dov: {
kill: { with_assets: ["sword"] },
eat: true,
},
doKill: function () {
MyGame.scorecard.awardPoint("kill orc");
},
doEat: function () {
if (this.is.dead) {
let msg = `{We} choke down the entire orc. But at what cost? `;
MyGame.overrideOutput(msg); // override the verb's default output
MyGame.scorecard.awardPoint("eat orc");
this.destroy(); // move orc to limbo
// not returning false allows the verb action to complete
} else {
let msg = "The orc objects. ";
MyGame.print(msg); // print immediately
return false; // halt the verb action
}
},
});
// key
MyGame.createAsset({
class: "Key",
name: "key",
place: { in: "Vault" },
doTake: function () {
MyGame.scorecard.awardPoint("take key");
},
});
// chest
MyGame.createAsset({
class: "Chest",
name: "chest",
place: { in: "Vault" },
doUnlock: function () {
if (orc.is.dead) {
MyGame.scorecard.awardPoint("unlock chest");
} else {
let msg = "The orc blocks {our} way. ";
MyGame.print(msg); // print immediately
return false; // halt the verb action
}
},
dov: { unlock: { with_assets: ["key"] } },
});
// treasure
MyGame.createAsset({
class: "Thing",
name: "treasure",
place: { in: "chest" },
dov: { take: true, eat: true, drop: true },
doTake: function () {
MyGame.scorecard.awardPoint("take treasure");
},
doDrop: function () {
console.warn(`drop treasure`);
MyGame.scorecard.awardPoint("drop treasure");
},
doEat: function () {
MyGame.scorecard.awardPoint("eat treasure");
this.destroy();
},
});