startshape realStart rule realStart { start { x 2 } } background { b -1 } rule start { terminal4 { r 12 } } rule start { terminal1 { r 12 } } rule start { terminal4 { r 12 } } rule start { terminal4 { r 12 } } rule start .05 { terminal2 { r 12 } } rule terminal4 { SQUARE { b 0.50 s .055 sat 0.40 hue 95 } SQUARE { b 1 s .055 a -.8 } train { x .06 } train { r 90 y .06 } train { r 180 x -.06 } train { r 270 y -.06 } } rule terminal2 2 { SQUARE { b 1 s .055 a -.85 } train { r 90 y .06 } train { r 270 y -.06 } } rule terminal2 1 { SQUARE { b 1 s .055 a -.8 } train { x .06 } train { r 90 y .06 } } rule terminal2 1 { SQUARE { b 1 s .055 a -.85 } train { x.06 } train { r 270 y -.06 } } rule terminal1 { CIRCLE { b 1 s .055 a -.9 } train { r 90 y .06 } } rule terminal1 { CIRCLE { b 1 s .055 a -.9 } train { r -90 y -.06 } } rule train 1 { CIRCLE { b 1 s .045 a -.9 } train { x .06 } } rule train 2 { terminal1 { } } rule train .02 { terminal2 { } } rule train .005 { terminal4 { } } rule train .03 { CIRCLE { b 1 s .03 a -.9 r -95 } }

Keith's Blog

A teen's .net musings

JSAdventure Items

Posted on May 6, 2010 at 1:20 AM

I have now added item support to my text adventure. I will now tentatively do a post a day on it with new features every post. This post is on the items. I made a new function called item which I can then use to create a new object as though it were a constructor like so…

function item(name, container, carryable) { 
    this.name = name;
    this.container = container;
    if (container) {
        this.container.items.push(this);
    }
    else {
        inventory.push(this);
    }
    this.carryable = carryable;
}

This does two main things: First, it allows me to create a new object with the name, container, and carryable properties set on it, and second, it makes it so that I don’t have to add the object to the inventory or list of items in the room because it does it for me. I did this mainly because I’m lazy ( As a side note I had a book that told me that was a good thing in programming. How wrong that was! ) but also because it makes it so that I don’t have to think about that ever again while I am coding. I also have been working on adding locking capabilities to exit and I made it so that some of the items can not be carryable ( is that a word? ) and will display a nice message saying go try again. Later I plan to make a property on item that allows me to assign a function that is executed through a command on items to do other things than just pickup, drop, and unlock doors. Any way if you have any suggestions, please feel free to leave a comment.

You do not have javascript enabled currently. Please enable javascript to play my game.

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading