The Beast of Torrack Moor

An interactive fiction by Linda Wright (2007) - the Inform 7 source text

Home page

Contents
Previous
Next

Complete text
Section 8 - Money

[ There are some coins and a five pound note. "count money" gives the total of all money held. The fiver will automatically be changed before buying something, if necessary ]
Worth is a kind of value. £3.99 specifies a worth with parts pounds and pence.

Total money is a worth that varies.

Currency is a kind of thing. Currency has a worth.

To say (price - a worth) in words:
    say "£[pounds part of price].[pence part of price]"

Carry out counting money:
    say "Altogether, you have [total worth].".

Before examining currency:
    try counting money instead.

Some coins are currency in the pocket. Understand "money" as the coins. They are pocketable. The worth of the coins is £2.60.
    
A fiver is currency. It is pocketable. Understand "five pound note" as the fiver. The worth of the fiver is £5.00.

[ This is probably overkill - there are only two money objects! - but was a useful exercise ]
To calculate funds:
    change total money to £0.00;
    repeat with possession running through currency
    begin;
        if possession is enclosed by the player,
            change total money to total money + the worth of possession;
    end repeat.

To say total worth:
    Calculate funds;
    say total money.

To spend (amount - a worth):
    if the coins are enclosed by the player and the worth of the coins is greater than amount begin;
        change the worth of the coins to the worth of the coins minus amount;
    otherwise;
        if the fiver is enclosed by the player begin;
            remove the fiver from play;
            if the coins are not enclosed by the player begin;
                move the coins to the player;
                change the worth of the coins to £0.00;
            end if;
            change the worth of the coins to the worth of the coins plus £5.00;
            change the worth of the coins to the worth of the coins minus amount;
        end if;
    end if;
    if the worth of the coins is £0.00 and the fiver is not carried by the player begin;
        say "You're now broke!";
        remove the coins from play;
    end if.

[ ITEMS THAT CAN BE BOUGHT ]
    
A purchasable is a kind of thing. A purchasable can be for sale or bought. A purchasable is usually for sale. A purchasable has a worth called the cost.

Instead of buying a purchasable:
    if the noun is bought begin;
        say "But...you already have!";
    otherwise;
        calculate funds;
        if total money is less than the cost of the noun begin;
            say "You don't have enough money!";
        otherwise;
            spend the cost of the noun;
            now the noun is bought;
            move the noun to the player;
            say "You buy [the noun].";
        end if;
    end if.

[ Special buying action for non-objects ]
Miscbuying is an action applying to one topic.
Understand "buy [text]" as miscbuying.

Carry out buying:
    say "You can't buy that here."

Carry out miscbuying:
    say "You can't buy that here."

[ Buying a beer in the pub and tea/coffee in the tea shop are basically the same ]
A beverage is a kind of value. The beverages are tea, coffee and beer.

To buy a beverage for (price - a worth):
    calculate funds;
    if total money is less than the price begin;
        say "You don't have enough money!";
    otherwise;
        spend price;
        say "OK, that's done.";
        say "You drink it down, and feel refreshed.";
    end if;