diff --git a/game_engine.coffee b/game_engine.coffee
index 0e07952..14999b3 100644
--- a/game_engine.coffee
+++ b/game_engine.coffee
@@ -8,10 +8,13 @@ class GameLog
@content += "
> " + text + "
"
@onChange(this)
- writeln: (text="")->
- @content += text.replace(/\n/g, "
") + "
"
+ write: (text="")->
+ @content += text.replace(/\n/g, "
")
@onChange(this)
+ writeln: (text="")->
+ @write(text + "\n")
+
########################################################################################################################
@@ -63,11 +66,17 @@ class Item
@description = "non-descript item"
@fixed = options.fixed
+ @story = null
# Public Methods ###############################################################################
- attemptTake: ->
- return true
+ take: ->
+ if @fixed
+ @story.log.writeln("You cannot take the #{@name}.")
+ return false
+ else
+ @story.log.writeln("Taken.")
+ return true
describe: ->
return @description
@@ -320,23 +329,21 @@ class Player
take: (item)->
localItems = @story.currentLocation.inventory
if not item
- tookSomething = false
+ foundTakeableItem = false
localItems.eachItem (item)=>
if not item.fixed
+ @story.log.write("#{item}: ")
+ foundTakeableItem = true
@take(item)
- tookSomething = true
- if not tookSomething then @story.log.writeln("There's nothing here you can take.")
+ if not foundTakeableItem then @story.log.writeln("There's nothing here you can take.")
else if localItems.has(item)
console.log(item)
- if not item.fixed
+ if item.take()
localItems.remove(item)
@inventory.add(item)
- @story.log.writeln("Took the #{item.name}.")
- else
- @story.log.writeln("You can't take the #{item.name}.")
else
- throw new ParseError("You can't take #{item} because there isn't one here.")
+ throw new ParseError("There isn't a #{item} here.")
########################################################################################################################
@@ -407,6 +414,7 @@ class Story
addItem: (name, options={})->
item = new Item(name, options)
+ item.story = this
@items.push(item)
return item
diff --git a/story.coffee b/story.coffee
index 51a9dca..87337cf 100644
--- a/story.coffee
+++ b/story.coffee
@@ -2,10 +2,13 @@ window.STORY = s = new Story("A Walk Through My House")
# Items ################################################################################################################
-boxOfTile = s.addItem("box of tiles", fixed: true)
+boxOfTile = s.addItem("box of tiles")
boxOfTile.description =
"This appears to be a box of flooring tiles. The tiles appear to be a very light color of natural stone. It is
quite heavy."
+boxOfTile.take = ->
+ s.log.writeln("Oof! It's too heavy.")
+ return false
hose = s.addItem("garden hose")
hose.description = "It's a pretty ordinary garden hose about 20' long."