Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed ruben/.DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions ruben/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

node_modules/
test/test_bundle.js
package.json
45 changes: 45 additions & 0 deletions ruben/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"rules": {
"no-console": 0,
"indent": [
2,
2,
{
"SwitchCase": 1
}
],
"quotes": [
2,
"single"
],
"linebreak-style": [
2,
"unix"
],
"semi": [
2,
"always"
]
},
"env": {
"es6": true,
"node": true,
"browser": true,
"mocha": true,
"jasmine": true
},
"globals": {
"describe": false,
"it": false,
"beforeEach": false,
"afterEach": false,
"before": false,
"after": false
},
"ecmaFeatures": {
"modules": true,
"experimentalObjectRestSpread": true,
"impliedStrict": true
},
"extends": "eslint:recommended"
}
2 changes: 2 additions & 0 deletions ruben/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules/
build/
test/test_bundle.js
202 changes: 99 additions & 103 deletions ruben/app/js/game/controllers/game-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,121 +5,117 @@ module.exports = function(app) {
};

function GameController() {
this.userLocation = 'start';
this.userHasBall = false;
this.command = '';
this.gamelog = [];
this.location = {
'start': {
commands: ['Enter ? for available commands at any time.'],
prompt: 'Welcome to the NBA Finals. You are in a stadium with a Monstar from Space Jam.'
},
'stadium': {
commands: ['take ball', 'look for the basket', 'say <message>', 'walk onto court'],
prompt: 'You are on the court. There is a spalding ball on the halfcourt line.'
},
'courtwithoutball': {
commands: ['walk through door', 'say <message>'],
prompt: 'You are on the court with a Monstar.'
},
'courtwithball': {
commands: ['shoot ball'],
prompt: 'You are on the court with a Monstar and you have a ball.'
}
}
};
GameController.prototype.startGame = function() {
this.gamelog = [];
this.userLocation = 'start';
this.userHasBall = false;
this.command = '';
this.userLocation = 'start';
this.userHasBall = false;
this.command = '';
this.gamelog = [];
this.location = {
'start': {
commands: ['Enter ? for available commands.'],
prompt: 'Welcome to the NBA Finals. You are in a stadium with a Monstar from Space Jam.'
},
'stadium': {
commands: ['walk onto court'],
prompt: 'You are on the court. There is a spalding ball on the halfcourt line.'
},
'courtwithoutball': {
commands: ['take ball'],
prompt: 'You are on the court with a Monstar and there is a ball'
},
'courtwithball': {
commands: ['shoot ball'],
prompt: 'Shoot the ball!'
}
};
}
GameController.prototype.startGame = function() {
this.gamelog = [];
this.userLocation = 'start';
this.userHasBall = false;
this.command = '';
this.gamelog.push({
src: 'game',
msg: this.location.start.prompt
});
var gamelog = this.gamelog;
this.location.start.commands.forEach(function(item) {
gamelog.push({
src: 'command',
msg: item
});
});
this.userLocation = 'courtwithoutball';
};
GameController.prototype.processInput = function() {
this.gamelog.push({
src: 'user',
msg: this.command
});

switch (this.command) {
case '?':
this.gamelog.push({
src: 'game',
msg: this.location.start.prompt
});
var gamelog = this.gamelog;
this.location.start.commands.forEach(function(item) {
gamelog.push({
src: 'command',
msg: item
});
});
this.userLocation = 'courtwithoutball';
};
GameController.prototype.processInput = function() {
this.gamelog.push({
src: 'user',
msg: this.command
msg: this.currentHelpMsg()
});

switch (this.command) {
case '?':
break;
case 'walk onto court':
var currentLocation = this.userLocation;
if (currentLocation === 'stadium') {
currentLocation = this.userLocation = this.userHasBall ? 'courtwithball' : 'courtwithoutball';
this.gamelog.push({
src: 'game',
msg: this.currentHelpMsg()
msg: this.location[currentLocation].prompt
});
break;
case 'walk onto court':
var currentLocation = this.userLocation;
if (currentLocation === 'stadium') {
currentLocation = this.userLocation = this.userHasWeapon ? 'courtwithball' : 'courtwithoutball';
this.gamelog.push({
src: 'game',
msg: this.location[currentLocation].prompt
});
} else {
this.userLocation = 'stadium';
this.gamelog.push({
src: 'game',
msg: this.location.weaponroom.prompt
});
}


} else {
this.userLocation = 'stadium';
this.gamelog.push({
src: 'game',
msg: this.currentHelpMsg()
msg: this.location.stadium.prompt
});
break;

case 'take ball':
this.userHasWeapon = true;
break;

default:
var sayArr = this.command.split(' ');
if (sayArr[0] === 'say') {
this.gamelog.push({
src: 'game',
msg: sayArr[1] || 'SAY SOMETHING!'
});
} else {
this.gamelog.push({
src: 'game',
msg: 'BAD COMMAND: Enter ? to see commands'
});
}
}
this.command = ''; //clear command after processing

};
GameController.prototype.currentHelpMsg = function() {
var str = '';
switch (this.userLocation) {

case 'stadium':
this.location.weaponroom.commands.forEach(function(item, index) {
str += index > 0 ? ' | ' : '';
str += item;
this.gamelog.push({
src: 'game',
msg: this.currentHelpMsg()
});
break;
case 'take ball':
this.userHasBall = true;
break;
default:
var sayArr = this.command.split(' ');
if (sayArr[0] === 'say') {
this.gamelog.push({
src: 'game',
msg: sayArr[1] || 'SAY SOMETHING!'
});
break;

case 'courtwithoutball':
this.location.courtwithoutball.commands.forEach(function(item, index) {
str += index > 0 ? ' | ' : '';
str += item;
} else {
this.gamelog.push({
src: 'game',
msg: 'BAD COMMAND: Enter ? to see commands'
});
break;
}
return str;
};
}
this.command = ''; //clear command after processing

};
GameController.prototype.currentHelpMsg = function() {
var str = '';
switch (this.userLocation) {
case 'stadium':
this.location.stadium.commands.forEach(function(item, index) {
str += index > 0 ? ' | ' : '';
str += item;
});
break;
case 'courtwithoutball':
this.location.courtwithoutball.commands.forEach(function(item, index) {
str += index > 0 ? ' | ' : '';
str += item;
});
break;
}
return str;
};
Loading