Skip to content

Commit

Permalink
Merge pull request #3 from mimiflynn/build-process
Browse files Browse the repository at this point in the history
refactor to use http-server and organize code
  • Loading branch information
mimiflynn committed Jul 18, 2015
2 parents e49bded + 8f7b68e commit e1120a2
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 134 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ Easter egg console.log game in the text based RPG fashion.

## Development Server

Install node.js and run
Install node.js and run this to install dependencies:

```
node server
npm install
```

Open your browser to `http://localhost:1337/index.html'
Then this to start the server:

```
npm start
```

Open your browser to `http://localhost:1337'

## License

Do with it what you will and perhaps refer to this repo.
Do with it what you will so long as you refer to this repo.
22 changes: 22 additions & 0 deletions package.json
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"
}
}
5 changes: 3 additions & 2 deletions index.html → public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
</head>
<body>
<h1>open that console, yo!</h1>
<script type="application/javascript" src="script.js"></script>
<script type="application/javascript" src="/js/console-game.js"></script>
<script type="application/javascript" src="/js/westward-bound.js"></script>
</body>
</html>
</html>
76 changes: 76 additions & 0 deletions public/js/console-game.js
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();
};
}
77 changes: 0 additions & 77 deletions script.js → public/js/westward-bound.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,3 @@
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();
};
}

var game = new Game('Westward Bound', {
actions: {
cardinalDirections: {
Expand Down
51 changes: 0 additions & 51 deletions server.js

This file was deleted.

0 comments on commit e1120a2

Please sign in to comment.