Okay, here’s a little test game (omitting the versionInfo and gameMain objects) that illustrates some of the basic techniques you’ve been working on implementing. If anything about it isn’t clear, feel free to ask more questions!
[code]// We’re only going to let the player buy one ale, so we don’t need to use
// dynamic object creation or make this a class. It starts out nowhere:
portableAle: Thing ‘foaming of ale/mug’ ‘mug of ale’
"A foaming mug of ale. "
vocabLikelihood { if (gActionIs(Buy)) return -2;
return 2;
}
;
class Shop: Room
;
leakyTub: Shop ‘Start Room’
"A small and not very attractive fish-and-chips shop. On the wall is a menu listing what’s on sale. "
south = beach
;
// For testing purposes, we’ll give the player a couple of inventory items:
++ banana: Thing ‘banana’ ‘banana’
"It looks yummy. "
;
++ galoshes: Thing ‘rubber galoshes shoes boots’ ‘galoshes’
"Your old rubber boots. "
isPlural = true
;
// And now the menu on the wall:
- tubMenu: Fixture, Readable ‘menu list wares’ ‘menu’
"The menu lists the following wares (food substances, one might guess):
\n\tale 4p
\n\tstrong spirits 6p
\n\turchin wine 12p
\n\tred wine 14p
\n\tfish chowder 8p
\n\tlobster rolls 12p
\n\tlobster chowder 8p
\n\tbaked urchin 8p
\n\tsteamed clams 12p
\n\tsteamed mussels 18p "
readDesc = desc
dobjFor(List) {
verify() { logical; }
action () {
replaceAction (Examine, self);
}
}
;
// We’re not going to create a shopkeeper or the money, but we’ll provide something
// you can buy:
- ale: Fixture ‘ale/mug’ ‘mug of ale’
"Yes, indeed – there’s ale on the menu. "
alreadyBoughtOne = nil
dobjFor(Buy) {
verify() {
if (alreadyBoughtOne) illogical ('You wouldn’t want to get tipsy, would you? ');
}
action() {
alreadyBoughtOne = true;
portableAle.moveInto(me);
"The shopkeeper hands you a foaming mug of ale. ";
}
}
;
// This action is for the bare ‘wares’ command:
DefineIAction(Wares)
execAction() {
if (me.location == leakyTub) tubMenu.desc;
else mainReport( 'There seems to be nothing on sale here. ');
}
;
VerbRule(Wares)
‘wares’ | ‘menu’
: WaresAction
verbPhrase = ‘check/checking the wares’
;
// And here’s a custom verb in case the user tries ‘list wares’:
DefineTAction(List)
;
VerbRule(List)
(‘list’ | ‘specify’ | ‘check’ ) singleDobj
: ListAction
verbPhrase = ‘list/listing (what)’
;
modify Thing
dobjFor(List) {
verify() { illogical (’{The dobj/he} {have} nothing to list. ');
}
}
;
// ‘buy’ is not an action that the library defines, and we’ll need it – I haven’t implemented
// the exchange of money, however:
DefineTAction(Buy);
VerbRule(Buy)
(‘buy’ | ‘purchase’) singleDobj
: BuyAction
verbPhrase = ‘buy/buying (what)’
;
modify Thing
dobjFor(Buy) {
verify() { illogical (’{The dobj/he} {is} not for sale. ');
}
}
;
// A second room, purely for testing purposes:
beach: Room ‘Beach’
"A sunny day on the beach. "
north = leakyTub
;
[/code]