Interactive Fiction

After writing a small adventure game in Python a while back I have decided to have a go at writing some more substantial interactive fiction. This time I will use a special purpose tool rather than a general purpose language.

I took a look at the tools currently available and have decided to give Inform 7 a go. This may seen a strange choice from a programming language geek, being a “natural language” system but, as they say, “a change is as good as a rest”!

I will write a short review of Inform once I get a chance to play with it.

Canon G Series

Over the past few weeks I have been taking a lot of photos with my old Canon Powershot G5. It is only five mega-pixels and has some knows issues with purple fringing but I like the form factor and it can take some usable photos if its limitations are kept in mind.

I have programmed one of the custom positions on the main control dial to give me direct access to the Black and White mode. I like taking B&W photos and this mode removes the purple fringing problem. Using the G5 in this way takes me back to when I used an Olympus OM10 with B&W film as a “walk around” camera. The G5 is even butter in many ways but the stand out feature is the articulated screen which gives so many creative framing possibilities.

Here is a link to some of my pictures taken with the G5.

http://www.flickr.com/photos/barrybridgens/tags/g5/

I have been enjoying the G5 so much that I am considering bringing my G Series ownership up to date by getting a G12. This camera is definitely from the same mould as the G5 but is has a much higher resolution sensor and even more “bells and whistles”. More of this anon….

2011 – New Year’s Resolutions

I have two, software related, New Year’s Resolutions that I will try to follow during 2011. These are “Do some Lisp Programming” and “Do some Squeak/Pharo Programming”.

In terms of Lisp I have purchased the e-book version of Land of Lisp after seeing many good reviews of it on the net. So far it has been an entertaining re-introduction to Common Lisp.

As for Squeak/Pharo, I have been re-visiting Morphic and finding it much more interesting that I remembered. I definitely intend to do some more with Morphic over the coming months.

Now to go and starting putting this into practice ….

New Dell laptop with Windows 7

My old HP laptop finally gave up the ghost and totally refused to startup. I had been expecting this for a while as some time ago it badly overheated and various sub-systems have been failing since then. The soundcard failed first followed by the wired network port and finally the DVD drive.

As a replacement I ordered a Dell 15R with a Core i3 processor. Not the best machine in the world but totally suited for my laptop use cases. The machine came with Windows 7 and I am going to use this for general tasks; Internet, e-mail, documents etc. I have created an Ubuntu 10.10 VM under VirtualBox for those software development tasks that Windows just can handle.

So far I am liking Windows 7 on the Dell, it is pretty, stable and fast. I have moved to the taskbar to the left of the screen as this makes best use of the wide ascpect radio of the display. With the taskbar at the bottom the screen felt very cramped vertically but with it at the side there is still plenty of space horisontally. I have downloaded some very nice visual themes from the Microsoft site; Lightening and Blue Water are particular favorites.

I have only had the machine for a few days but so far so good.

Python Adventure Game – Finished

I have now finished my Python Adventure Game by adding some puzzles and a win algorithm. Its a very simple game but was great fun to write.

Source code is below.

#
# Barry's simple adventure game
#
 
# Room data indexs
SHORT_DESC = 0
LONG_DESC = 1
N_EXIT = 2
S_EXIT = 3
E_EXIT = 4
W_EXIT = 5
U_EXIT = 6
D_EXIT = 7
OBJECT = 8
 
# Room Data
rooms = [
['dummy'],
['the entrance', 'the entrance to a rather large looking cave', 2, 0, 0, 0, 0, 0, ''], # 1
['a coridor', 'a coridor that stretches off to the North', 3, 1, 0, 0, 0, 0, 'Lamp'], #2
['a round room', 'a round room with many exits', 7, 2, 4, 0, 20, 6, ''], #3
['a crawlway', 'a narrow east / west crawlway', 0, 0, 5, 3, 0, 0, ''], #4
['a low cave', 'a low dead end cave', 0, 0, 0, 4, 0, 0, 'Knife'], #5
['a well', 'a deep well with no way out', 0, 0, 0, 0, 0, 0, ''], #6
['a crystal cave', 'a beautifull cave with crystal walls', 8, 3, 9, 0, 0, 0, ''], #7
['an alcove', 'a small alcove in the cave wall', 0, 7, 0, 0, 0, 0, ''], #8
['a passage', 'a long east / west passage', 0, 0, 10, 7, 0, 0, ''], #9
['an anteroom', 'a richly decorated anteroom', 13, 11, 12, 9, 0, 0, ''], #10
['a wardrobe', 'a large wardrobe with space for lots of clothes', 10, 0, 0, 0, 0, 0, 'Key'], #11
['the throne room', 'a very large room with a golden throne on a dais', 0, 0, 0, 10, 0, 0, 'Crown'], #12
['the view room', 'a cave with a small hole giving a view along a green valley', 0, 10, 14, 0, 0, 0, ''], #13
['the guard room', 'a room with chairs and a table that looks like it was used as a guard room', 0, 0, 15, 13, 0, 0, ''], #14
['the ballroom', ' a magnificent ballroom with purple and gold walls', 0, 17, 18, 14, 16, 0, ''], #15
['the organ loft', 'a small room containing the controls for a large pipe organ', 0, 0, 0, 0, 0, 15, ''], #16
['the vault', 'a small airtight vault with shelves around the sides', 15, 0, 0, 0, 0, 0, 'Diamond'], #17
['the dining room', 'a long room with a huge dining table and chairs', 0, 0, 19, 15, 0, 0, ''], #18
['the kitchen', 'a large dusty kitchen', 0, 0, 0, 18, 0, 0, ''], #19
['a gallery', 'a high gallery leading off in a number of directions', 24, 22, 23, 21, 0, 3, ''], #20
['the waverfall cave', 'a large cave with a dark lake and a waterfall at the far end', 0, 0, 20, 0, 0, 0, ''], #21
['the echo cave', 'a small cave where sound echoes all around', 20, 0, 0, 0, 0, 0, ''], #22
['the assasin room', 'a small room bare room', 0, 0, 25, 20, 0, 0, 'a dead Masked Man'], #23
['a dark cave', 'a dark cave', 24, 24, 20, 24, 24, 24, ''], #24
['the exit', 'the exit of the cave', 0, 0, 0, 23, 0, 0, ''] #25
]
 
objects = ['dummy']
visits = [0]
for room in range(1, rooms.__len__()):
    objects.append(rooms[room][OBJECT])
    visits.append(0)
 
current_room = 1
visits[current_room] = 1
 
inventory = []
 
battery = 100
 
# Code
 
def describe_room(room):
    print
    if visits[room] > 1:
        print 'You are in ' + rooms[room][SHORT_DESC]
    else:
        print 'You are in ' + rooms[room][LONG_DESC]
    print
    if rooms[room][N_EXIT] != 0:
        print 'There is an exit to the North'
    if rooms[room][S_EXIT] != 0:
        print 'There is an exit to the South'
    if rooms[room][E_EXIT] != 0:
        print 'There is an exit to the East'
    if rooms[room][W_EXIT] != 0:
        print 'There is an exit to the West'
    if rooms[room][U_EXIT] != 0:
        print 'There is an exit leading upwards'
    if rooms[room][D_EXIT] != 0:
        print 'There is an exit leading downwards'
    if objects[room] != '':
        print
        print 'There is a ' + objects[room] + ' here'
    print
 
def move(exit):
    global current_room
    if rooms[current_room][exit] != 0:
        # Can't enter the vault without the key
        if ((current_room == 15) and (rooms[current_room][exit] == 17)):
            if 'Key' in inventory:
                print
                print
                print "You use the key to open the door to the vault"
                current_room = rooms[current_room][exit]
                visits[current_room] += 1
            else:
                print
                print
                print "You can't open the heavy door but it does have a key hole"
        else:
            current_room = rooms[current_room][exit]
            visits[current_room] += 1
    else:
        print
        print
        print '>>> There is no exit in that direction'
 
def north():
    move(N_EXIT)
 
def south():
    move(S_EXIT)
 
def east():
    move(E_EXIT)
 
def west():
    move(W_EXIT)
 
def up():
    move(U_EXIT)
 
def down():
    move(D_EXIT)
 
def get():
    if objects[current_room] == command.split()[1]:
        objects[current_room] = ''
        inventory.append(command.split()[1])
    else:
        print
        print "There is not a " + command.split()[1] + " here"
 
def drop():
    if command.split()[1] in inventory:
        inventory.remove(command.split()[1])
        objects[current_room] = command.split()[1]
    else:
        print
        print "You are not carrying a " + command.split()[1]
 
def inv():
    print("Inventory: ")
    for item in inventory:
        print item
 
commands = {
'north' : north,
'n' : north,
'south' : south,
's' : south,
'east' : east,
'e' : east,
'west' : west,
'w' : west,
'up' : up,
'u' : up,
'down' : down,
'd' : down,
'get' : get,
'inventory' : inv,
'inv' : inv,
'drop' : drop
}
 
# Main game loop
exit = False
while (not exit):
    print
    print
    describe_room(current_room)
    command = raw_input( "What do you want to do: " )
    if command != "":
        command_name = command.split()[0]
    else:
        command_name = "none"
    if command_name in commands.keys():
        commands[command_name]()
    else:
        print
        print
        print '>>> I don\'t understand that'
    # Check lamp
    if 'Lamp' in inventory:
        battery = battery - 1
        if battery == 50:
            print
            print
            print "The battery in your lamp is half used"
        else:
            if battery == 25:
                print
                print
                print "The battery in your lamp is three quarters used"
            else:
                if battery == 10:
                    print
                    print
                    print "The battery in your lamp is almost exhausted"
                else:
                    if battery == 0:
                        print
                        print "Your lamp has failed"
                        print "You fell in a pit and died!!"
                        print
                        exit = True
    else:
        if current_room == 3:
            print
            print
            print "It's dark here, you should find a light source or you might get hurt"
        else:
            if current_room > 3:
                print
                print "You fell in a pit and died!!"
                print
                exit = True
    # Assasin puzzle
    if current_room == 23:
        if 'Knife' in inventory:
            print
            print
            print "You killed a masked man with the knife you were carrying, well done"
        else:
            print
            print "A masked man killed you, you should have looked for a weapon!"
            print
            exit = True
    # Win check
    if current_room == 25:
        if (('Crown' in inventory) and ('Diamond' in inventory)):
            print
            print "Well done, you found all of the treasure"
            print
            exit = True
        else:
            print
            print "There is more treasure to find, go back and keep looking"
            print

wp-syntax

I have just noticed the full list of languages supported by wp-syntax. Below is the list from the wp-syntax WordPress.org Plugin Directory page.

abap, actionscript, actionscript3, ada, apache, applescript, apt_sources, asm, asp, autoit, avisynth, bash, bf, bibtex, blitzbasic, bnf, boo, c, c_mac, caddcl, cadlisp, cil, cfdg, cfm, cmake, cobol, cpp-qt, cpp, csharp, css, d, dcs, delphi, diff, div, dos, dot, eiffel, email, erlang, fo, fortran, freebasic, genero, gettext, glsl, gml, bnuplot, groovy, haskell, hq9plus, html4strict, idl, ini, inno, intercal, io, java, java5, javascript, kixtart, klonec, klonecpp, latex, lisp, locobasic, lolcode lotusformulas, lotusscript, lscript, lsl2, lua, m68k, make, matlab, mirc, modula3, mpasm, mxml, mysql, nsis, oberon2, objc, ocaml-brief, ocaml, oobas, oracle11, oracle8, pascal, per, pic16, pixelbender, perl, php-brief, php, plsql, povray, powershell, progress, prolog, properties, providex, python, qbasic, rails, rebol, reg, robots, ruby, sas, scala, scheme, scilab, sdlbasic, smalltalk, smarty, sql, tcl, teraterm, text, thinbasic, tsql, typoscript, vb, vbnet, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xml, xorg_conf, xpp, z80

This gives me some pointers to programming languages to take another (or first in some cases) look at. Should keep me busy for a while πŸ™‚

Python Adventure Game

As well as the space invaders game mentioned in an earlier post I thought that I would also implement a textual adventure for the nostalgia value.

I sketched the map of the game on paper as shown below.

Map 1

Map 2

And then implemented the data structure in python.

# Room data indexes
SHORT_DESC = 0
LONG_DESC = 1
N_EXIT = 2
S_EXIT = 3
E_EXIT = 4
W_EXIT = 5
U_EXIT = 6
D_EXIT = 7
OBJECT = 8
 
# Room Data
rooms = [
['dummy'],
['the entrance', 'the entrance to a rather large looking cave', 2, 0, 0, 0, 0, 0, ''], # 1
['a corridor', 'a corridor that stretches off to the North', 3, 1, 0, 0, 0, 0, 'Lamp'], #2
['a round room', 'a round room with many exits', 7, 2, 4, 0, 20, 6, ''], #3
['a crawlway', 'a narrow east / west crawlway', 0, 0, 5, 3, 0, 0, ''], #4
['a low cave', 'a low dead end cave', 0, 0, 0, 4, 0, 0, 'Knife'], #5
['a well', 'a deep well with no way out', 0, 0, 0, 0, 0, 0, ''], #6
['a crystal cave', 'a beautiful cave with crystal walls', 8, 3, 9, 0, 0, 0, ''], #7
['an alcove', 'a small alcove in the cave wall', 0, 7, 0, 0, 0, 0, ''], #8
['a passage', 'a long east / west passage', 0, 0, 10, 7, 0, 0, ''], #9
['an anteroom', 'a richly decorated anteroom', 13, 11, 12, 9, 0, 0, ''], #10
['a wardrobe', 'a large wardrobe with space for lots of clothes', 10, 0, 0, 0, 0, 0, 'Key'], #11
['the throne room', 'a very large room with a golden throne on a dais', 0, 0, 0, 10, 0, 0, 'Crown'], #12
['the view room', 'a cave with a small hole giving a view along a green valley', 0, 10, 14, 0, 0, 0, ''], #13
['the guard room', 'a room with chairs and a table that looks like it was used as a guard room', 0, 0, 15, 13, 0, 0, ''], #14
['the ballroom', ' a magnificent ballroom with purple and gold walls', 0, 17, 18, 14, 16, 0, ''], #15
['the organ loft', 'a small room containing the controls for a large pipe organ', 0, 0, 0, 0, 0, 15, ''], #16
['the vault', 'a small airtight vault with shelves around the sides', 15, 0, 0, 0, 0, 0, 'Bag of Money'], #17
['the dining room', 'a long room with a huge dining table and chairs', 0, 0, 19, 15, 0, 0, ''], #18
['the kitchen', 'a large dusty kitchen', 0, 0, 0, 18, 0, 0, ''], #19
['a gallery', 'a high gallery leading off in a number of directions', 24, 22, 23, 21, 0, 0, ''], #20
['the waterfall cave', 'a large cave with a dark lake and a waterfall at the far end', 0, 0, 20, 0, 0, 0, ''], #21
['the echo cave', 'a small cave where sound echoes all around', 20, 0, 0, 0, 0, 0, ''], #22
['the assassin room', 'a small room bare room', 0, 0, 25, 20, 0, 0, 'Masked Man'], #23
['a dark cave', 'a dark cave', 24, 24, 20, 24, 24, 24, ''], #24
['the exit', 'the exit of the cave', 0, 0, 0, 23, 0, 0, ''] #25
]

The game is now mostly working. Only the puzzles left to implement.

Pygame

I have been looking for a project to use as an excuse to write some Python as its been a while since I last used it. Searching around I came across pygame (http://www.pygame.org) and decided to look into it.

It has been many years since I have written a game but the documentation and examples on the pygame site look very good. I have started a good old Space Invaders game and will see how I get on from there.

Line-6 UX1

I have just purchased a Line-6 UX1 interface to allow recording of electric guitar (this was a late birthday present!). The UX1 is a USB interface with inputs for guitar, microphone and line level (for keyboards etc.).

The interface comes with the POD Farm software which is basically an implementation of the POD modelling software running on the PC. POD Farm gives all of the usual Line-6 implementations of virtual amps, cabinets, speakers and stomp boxes provided by the hardware POD family.

So far I have not done any serious recording with the UX1 but I have auditioned some of the sounds and, to my ears at least, they are very good. It more interesting to practice when playing through a (virtual) Marshall stack than through my crappy practice amp πŸ™‚

PDAs over the years

I have been thinking about the number of PDAs (Personal Digital Assistant) that I have owned over the years. I started to put a list together and here are the ones that I can remember.

Psion 2 – LZ64
Psion Series 3
Psion Series 3a
Psion Series 5
Handspring Visor
Palm m505
Sony CLIÉ
Palm Tungsten T5
HTC Touch – Windows Mobile
HTC Hero – Android 1.5

There are a number of distinct phases in the above list. First the three evolutionary Psion ranges, PalmOs, Windows Mobile and finally Android. I look back with fondness to these old machines but I do not want to thing about the ammount of money I have spent on them!