Allow entering the car and ending the game

This commit is contained in:
Andrew Miner
2018-05-28 20:53:41 -06:00
parent e2488b0abb
commit ade2fe2339
2 changed files with 18 additions and 9 deletions
+9 -4
View File
@@ -10,14 +10,15 @@ configureDefaults = (story)->
parser = story.parser parser = story.parser
parser.addDirections( parser.addDirections(
"north", "northeast", "east", "southeast", "south", "southwest", "west", "northwest", "up", "down" "north", "northeast", "east", "southeast", "south", "southwest", "west", "northwest", "up", "down", "in", "out"
) )
parser.addFillerWords( parser.addFillerWords(
"a", "all", "an", "around", "at", "everything", "of", "it", "the", "to", "thing" "a", "all", "an", "around", "at", "everything", "of", "it", "the", "to", "thing"
) )
parser.addAliases({ parser.addAliases({
"d": "down", "e": "east", "g": "go", "i": "inventory", "l": "look", "n": "north", "ne": "northeast", "d": "down", "e": "east", "g": "go", "get": "take", "i": "inventory", "into": "in", "l": "look",
"nw": "northwest", "s": "south", "se": "southeast", "sw": "southwest", "u": "up", "w": "west", "leave": "exit", "n": "north", "ne": "northeast", "nw": "northwest", "s": "south", "se": "southeast",
"sw": "southwest", "u": "up", "w": "west"
}) })
######################################################################################################################## ########################################################################################################################
@@ -185,7 +186,6 @@ class Location extends Actor
result.push("\n") result.push("\n")
result.push(@description) result.push(@description)
console.log("@inventory.length: #{@inventory.length}")
if @inventory.length > 0 if @inventory.length > 0
result.push("") result.push("")
result.push(@inventory.describe()) result.push(@inventory.describe())
@@ -238,6 +238,7 @@ class Parser
@verbs[verb] = verb @verbs[verb] = verb
interpret: (userInput)-> interpret: (userInput)->
userInput = userInput.toLowerCase()
sentence = new Sentence sentence = new Sentence
for rawWord in userInput.split(/\s\s*/) for rawWord in userInput.split(/\s\s*/)
rawWord = @_resolveAliases(rawWord) rawWord = @_resolveAliases(rawWord)
@@ -492,6 +493,7 @@ class Story extends Actor
@onRestart = onRestart @onRestart = onRestart
@parser = new Parser(this) @parser = new Parser(this)
@player = new Player(this) @player = new Player(this)
@possibleScore = undefined
@title = title @title = title
# Properties ################################################################################### # Properties ###################################################################################
@@ -528,6 +530,9 @@ class Story extends Actor
location.visited = true location.visited = true
endGame: ->
@log.writeln("\n\nThanks for playing! Say: \"restart\" to play again!\n\n\n")
interpret: (userInput)-> interpret: (userInput)->
try try
@log.echoInput(userInput) @log.echoInput(userInput)
+9 -5
View File
@@ -18,16 +18,19 @@ window.STORY = new Story "A Walk Through My House", ->
car = @addLocation "Your Car" car = @addLocation "Your Car"
car.description = car.description =
"Your car isn't anything special, but it does get you around." "Your car isn't anything special, but it does get you around."
car.addVerb "leave", "drive", "start", => car.addVerb "drive", "start", =>
@log.writeln("Having finished your visit, you drive back home again.") @log.writeln("Having finished your visit, you drive back home again.")
@endGame() @endGame()
driveway = @addLocation "Driveway" driveway = @addLocation "Driveway"
driveway.description = driveway.description =
"The driveway extends slightly uphill a short way to the west back to the street. At this part, it's recessed a "The driveway is paved with concrete, and quite large: room enough for five or six cars. Your own car is the
little below the level of the lawn with a stone wall defining the boundary. To the south are three garage doors only one here at the moment, though. The driveway extends slightly uphill a short way to the west back to the
which make up the entire side of the house. Above the doors are a few windows. The back yard is to the east, and street. At this part, it's recessed a little below the level of the lawn with a stone wall defining the
the some steps lead up to the front porch to the southwest." boundary.\n\nFrom where you're standing, it looks like most of the property has been left wild with tall,
scraggly pine trees swaying in a light breeze. Immediately surrounding the house is a short-cropped lawn. To the
south are three garage doors which make up the entire side of the house. Above the doors are a few windows. The
back yard is to the east, and the some steps lead up to the front porch to the southwest."
driveway.addItem hose driveway.addItem hose
frontPorch = @addLocation "Front Porch" frontPorch = @addLocation "Front Porch"
@@ -40,6 +43,7 @@ window.STORY = new Story "A Walk Through My House", ->
# Configure Map #################################################################################################### # Configure Map ####################################################################################################
driveway.addTransition "in", car
driveway.addTransition "southwest", frontPorch driveway.addTransition "southwest", frontPorch
frontPorch.addTransition "north", driveway frontPorch.addTransition "north", driveway