Add the look command
This commit is contained in:
+24
-9
@@ -30,15 +30,11 @@ class Inventory
|
|||||||
options.simple ?= false
|
options.simple ?= false
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
needsDelimiter = false
|
|
||||||
for name, item of @items
|
for name, item of @items
|
||||||
if needsDelimiter
|
|
||||||
result.push("\n")
|
|
||||||
if options.simple
|
if options.simple
|
||||||
result.push(item.name)
|
result.push(item.name)
|
||||||
else
|
else
|
||||||
result.push("There is a #{item.name} here.")
|
result.push("There is a #{item.name} here.")
|
||||||
needsDelimiter = true
|
|
||||||
|
|
||||||
return result.join("\n")
|
return result.join("\n")
|
||||||
|
|
||||||
@@ -62,6 +58,9 @@ class Item
|
|||||||
constructor: (@name)->
|
constructor: (@name)->
|
||||||
@description = "non-descript item"
|
@description = "non-descript item"
|
||||||
|
|
||||||
|
describe: ->
|
||||||
|
return @description
|
||||||
|
|
||||||
toString: ->
|
toString: ->
|
||||||
return @name
|
return @name
|
||||||
|
|
||||||
@@ -84,10 +83,11 @@ class Location
|
|||||||
@inventory.add(item)
|
@inventory.add(item)
|
||||||
return this
|
return this
|
||||||
|
|
||||||
describe: ->
|
describe: (options={})->
|
||||||
|
options.verbose ?= false
|
||||||
result = [@name]
|
result = [@name]
|
||||||
|
|
||||||
if not @visited
|
if (not @visited) or options.verbose
|
||||||
result.push("\n")
|
result.push("\n")
|
||||||
result.push(@description)
|
result.push(@description)
|
||||||
|
|
||||||
@@ -192,7 +192,7 @@ class Parser
|
|||||||
|
|
||||||
highestCount = 0
|
highestCount = 0
|
||||||
mostPopular = []
|
mostPopular = []
|
||||||
for candidate in candidates.values()
|
for candidate in candidates
|
||||||
if candidate.count is highestCount
|
if candidate.count is highestCount
|
||||||
mostPopular.push(candidate)
|
mostPopular.push(candidate)
|
||||||
else if candidate.count > highestCount
|
else if candidate.count > highestCount
|
||||||
@@ -204,7 +204,7 @@ class Parser
|
|||||||
"I'm not sure what you meant by #{rawWord}... which did you mean: #{mostPopular.join(", ")}"
|
"I'm not sure what you meant by #{rawWord}... which did you mean: #{mostPopular.join(", ")}"
|
||||||
)
|
)
|
||||||
|
|
||||||
sentence.addWord(new WordToken(rawWord, "item", mostPopular[0]))
|
sentence.addWord(new WordToken(rawWord, "item", mostPopular[0].item))
|
||||||
return true
|
return true
|
||||||
|
|
||||||
_useAsVerb: (rawWord, sentence)->
|
_useAsVerb: (rawWord, sentence)->
|
||||||
@@ -389,13 +389,22 @@ class Story
|
|||||||
@parser.addDirections(
|
@parser.addDirections(
|
||||||
"north", "northeast", "east", "southeast", "south", "southwest", "west", "northwest", "up", "down"
|
"north", "northeast", "east", "southeast", "south", "southwest", "west", "northwest", "up", "down"
|
||||||
)
|
)
|
||||||
@parser.addFillerWords("of", "the", "a", "an", "to")
|
@parser.addFillerWords(
|
||||||
|
"a",
|
||||||
|
"an",
|
||||||
|
"around",
|
||||||
|
"at",
|
||||||
|
"of",
|
||||||
|
"the",
|
||||||
|
"to"
|
||||||
|
)
|
||||||
@parser.addAliases({
|
@parser.addAliases({
|
||||||
"d": "down",
|
"d": "down",
|
||||||
"e": "east",
|
"e": "east",
|
||||||
"everything": "all",
|
"everything": "all",
|
||||||
"g": "go"
|
"g": "go"
|
||||||
"i": "inventory"
|
"i": "inventory"
|
||||||
|
"l": "look",
|
||||||
"n": "north",
|
"n": "north",
|
||||||
"ne": "northeast",
|
"ne": "northeast",
|
||||||
"nw": "northwest",
|
"nw": "northwest",
|
||||||
@@ -419,6 +428,12 @@ class Story
|
|||||||
@log.writeln("You have:")
|
@log.writeln("You have:")
|
||||||
@log.writeln(@player.inventory.describe(simple: true))
|
@log.writeln(@player.inventory.describe(simple: true))
|
||||||
|
|
||||||
|
@player.addVerb "look", (sentence)=>
|
||||||
|
if sentence.has(item: 1)
|
||||||
|
@log.writeln(sentence.item.describe(verbose: true))
|
||||||
|
else
|
||||||
|
@log.writeln(@currentLocation.describe(verbose: true))
|
||||||
|
|
||||||
@player.addVerb "take", (sentence)=>
|
@player.addVerb "take", (sentence)=>
|
||||||
if sentence.has(item: 1)
|
if sentence.has(item: 1)
|
||||||
@player.take(sentence.item)
|
@player.take(sentence.item)
|
||||||
|
|||||||
Reference in New Issue
Block a user