-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from mimiflynn/build-process
refactor to use http-server and organize code
- Loading branch information
Showing
7 changed files
with
112 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "console-game", | ||
"description": "Easter egg console.log game in the text based RPG fashion.", | ||
"version": "0.1.2", | ||
"author": { | ||
"name": "Mimi Flynn", | ||
"email": "mimiflynn@gmail.com" | ||
}, | ||
"engines": { | ||
"node": "0.10.x" | ||
}, | ||
"scripts": { | ||
"start": "NODE_PATH= NODE_ENV=development ./node_modules/.bin/http-server public -a 127.0.0.1 -p 1337" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:mimiflynn/console-game.git" | ||
}, | ||
"devDependencies": { | ||
"http-server": "^0.8.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
function Game(name, options) { | ||
|
||
var actions = options.actions; | ||
var steps = options.steps; | ||
var count = 0; | ||
var correctAnswer; | ||
var causeOfDeath; | ||
|
||
var utils = { | ||
outputChoices: function (arr) { | ||
var output = ''; | ||
var length = arr.length - 1; | ||
arr.forEach(function (e, i) { | ||
output += (i !== length) ? e + ', ' : e; | ||
}); | ||
return output; | ||
}, | ||
readInput: function (input) { | ||
console.log(input); | ||
if (input !== correctAnswer) { | ||
console.log(causeOfDeath); | ||
} else { | ||
play(count); | ||
} | ||
}, | ||
showPrompt: function (option) { | ||
console.log(option.prompt + '(' + utils.outputChoices(option.options) + ')'); | ||
}, | ||
setCorrectAnswer: function (step) { | ||
if (step.answer !== undefined) { | ||
var answer = actions[step.prompt].options[step.answer]; | ||
correctAnswer = answer; | ||
} | ||
}, | ||
setCauseOfDeath: function (step) { | ||
if (step.die) { | ||
var die = step.die; | ||
causeOfDeath = die; | ||
} | ||
}, | ||
outputMessage: function (step) { | ||
console.log(step.message); | ||
if (step.prompt) { | ||
utils.showPrompt(actions[step.prompt]); | ||
} | ||
} | ||
}; | ||
|
||
var play = function () { | ||
var step = steps[count]; | ||
utils.setCorrectAnswer(step); | ||
utils.setCauseOfDeath(step); | ||
utils.outputMessage(step); | ||
count++; | ||
}; | ||
|
||
var directions = function () { | ||
console.log(name + '\n' + 'To make a move use player.move(). Refresh to start again.\n---------------------------------------------------------\n'); | ||
}; | ||
|
||
// public methods | ||
|
||
this.player = { | ||
move: function (input) { | ||
utils.readInput(input); | ||
}, | ||
end: function () { | ||
console.log('quitter'); | ||
} | ||
}; | ||
|
||
this.init = function () { | ||
directions(); | ||
play(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters