Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
9 changes: 9 additions & 0 deletions vic-class22-assignment/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
**/node_modules/*
**/vendor/*
**/build/*
**/*.min.js
*_bundle.js
*.md
package.json
Procfile
npm-debug.log
42 changes: 42 additions & 0 deletions vic-class22-assignment/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"rules": {
"no-console": 0,
"indent": [
2,
2
],
"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"
}
3 changes: 3 additions & 0 deletions vic-class22-assignment/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
build
*_bundle.js
20 changes: 20 additions & 0 deletions vic-class22-assignment/app/css/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
main ul {
list-style-type: none;
margin: 5px;
display: block;
height: 400px;
width: 600px;
border: 1px solid black;
}

span.game-input {
color: green;
}

span.command-input {
color: blue;
}

span.user-input {
color: red;
}
Empty file.
27 changes: 27 additions & 0 deletions vic-class22-assignment/app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="./app.css" rel="stylesheet" type="text/css">
<title>Text Adventure Game</title>
</head>
<body data-ng-app="adventureApp">
<main data-ng-controller="GameController as settings" data-ng-init="settings.startGame()">
<h1>Adventure Game:</h1>
<form name="userInputForm" data-ng-submit="settings.processInput()">
<label for="command">Command:
<input type="text" required data-ng-model="settings.model.command"/>
</label>
<button type="submit">Continue</button>
</form>
<ul id="inputlog">
<li data-ng-repeat="choice in settings.model.gamelog">
<span class="{{choice.src}}-input">{{choice.msg}}</span>
</li>
</ul>
</main>
<script src="bundle.js"></script>
</body>
</html>
6 changes: 6 additions & 0 deletions vic-class22-assignment/app/js/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

const angular = require('angular');

var adventureApp = angular.module('adventureApp', []);
require('./game/game')(adventureApp);
128 changes: 128 additions & 0 deletions vic-class22-assignment/app/js/game/controllers/game-controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
'use strict';

module.exports = function(app) {
app.controller('GameController', GameController);
};

function GameController() {
this.model = {
userLocation: 'start',
userHasWeapon: false,
command: '',
gamelog: [],
location: {
'start': {
commands: ['Enter ? for available commands at any time', 'enter door on left', 'enter door on right'],
prompt: 'Welcome to your Quest. You must acquire a weapon to defeat the a monster in order to leave this building.'
},
'weaponroom': {
commands: ['take the dick\'s burger', 'take the beard oil', 'take the soccerball', 'take the iced tea', 'say <message>', 'walk through door'],
prompt: 'You are in the weapon room. There is a weapon in each corner, a dick\'s burger, beard oil, a soccerball, and iced tea. One of these items may defeat the monster you encounter.'
},
'monsterroomwithoutweapon': {
commands: ['walk through door', 'say <message>'],
prompt: 'You are in a room with a hairy monster.'
},
'monsterroomwithweapon': {
commands:['pour beard oil on floor', 'feed monster dick\'s burger', 'quench monster thirst with iced tea', 'distract with soccerball'],
prompt: 'You are in a room with a monster and you have a weapon.'
}
}
};
GameController.prototype.startGame = function() {
this.model.gamelog = [];
this.model.userLocation = 'start';
this.model.userHasWeapon = false;
this.model.command = '';
this.model.gamelog.push({
src: 'game',
msg: this.model.location.start.prompt
});
this.model.location.start.commands.forEach((choice) => {
this.model.gamelog.push({
src: 'command',
msg: choice
});
});
this.model.userLocation = 'start';
};
GameController.prototype.processInput = function() {
this.model.gamelog.push({
src: 'user',
msg: this.model.command
});

switch (this.model.command) {
case '?':
this.model.gamelog.push({
src: 'command',
msg: this.currentHelpMsg()
});
break;
case 'enter door on left':
var currentLocation = this.model.userLocation;
if(currentLocation === 'weaponroom') {
currentLocation = this.model.userLocation = this.model.userHasWeapon ? 'monsterroomwithweapon' : 'monsterroomwithoutweapon';
this.model.gamelog.push({
src: 'game',
msg: this.model.location[currentLocation].prompt
});
} else {
this.model.userLocation = 'weaponroom';
this.model.gamelog.push({
src: 'game',
msg: this.model.location.weaponroom.prompt
});
}

this.model.gamelog.push({
src: 'game',
msg: this.currentHelpMsg()
});
break;
case 'take the dick\'s burger':
this.model.userHasWeapon = true;
break;

default:

var sayArr = this.model.command.split(' ');
if(sayArr[0] === 'say') {
this.model.gamelog.push({
src:'game',
msg: sayArr.split(1, sayArr.length).join(' ') || 'SPEAK!'
});
} else {
this.model.gamelog.push({
src: 'game',
msg: 'BAD COMMAND: Enter ? to see commands'
});
}
}
this.model.command = '';
};
GameController.prototype.currentHelpMsg = function() {
var str = '';
switch(this.model.userLocation) {
case 'start':
this.model.location.start.commands.forEach((choice, index) => {
str += index > 0 ? ' | ' : '';
str += choice;
});
break;
case 'weaponroom':
this.model.location.weaponroom.commands.forEach((choice, index) => {
str += index > 0 ? ' | ' : '';
str += choice;
});
break;
case 'monsterroomwithoutweapon':
this.model.location.monsterroomwithoutweapon.commands.forEach((choice, index) => {
str += index > 0 ? ' | ' : '';
str += choice;
});
break;
}
return str;
};
}
3 changes: 3 additions & 0 deletions vic-class22-assignment/app/js/game/game.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function(app) {
require('./controllers/game-controller')(app);
};
57 changes: 57 additions & 0 deletions vic-class22-assignment/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'use strict';

const gulp = require('gulp');
const eslint = require('gulp-eslint');
const webpack = require('webpack-stream');

var files = ['*.js', './app/*.js', './app/js/*.js', './app/js/game/*.js', './app/js/game/controllers/*.js'];

const paths = {
js:__dirname + '/app/js/*.js',
html:__dirname + '/app/index.html',
css:__dirname + '/app/css/*.css'
};

gulp.task('lint', () => {
return gulp.src(files)
.pipe(eslint())
.pipe(eslint.format());
});

gulp.task('webpack:dev', () => {
return gulp.src(paths.js)
.pipe(webpack({
output: {
filename: 'bundle.js'
}
}))
.pipe(gulp.dest('build/'));
});

gulp.task('staticfiles:dev', () => {
return gulp.src(paths.html)
.pipe(gulp.dest('./build'));
});

gulp.task('staticcssfiles:dev', () => {
return gulp.src(paths.css)
.pipe(gulp.dest('./build'));
});

gulp.task('bundle:test', () => {
return gulp.src(__dirname + '/test/*_test.js')
.pipe(webpack({
output: {
filename: 'test_bundle.js'
}
}))
.pipe(gulp.dest(__dirname + '/test'));
});

gulp.task('build:dev', ['staticfiles:dev', 'staticcssfiles:dev', 'webpack:dev']);

gulp.task('watch', () => {
gulp.watch(paths.js, ['lint', 'webpack:dev']);
gulp.watch(paths.html, ['staticfiles:dev']);
gulp.watch(paths.css, ['staticcssfiles:dev']);
});
69 changes: 69 additions & 0 deletions vic-class22-assignment/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Karma configuration
// Generated on Thu Jun 16 2016 10:07:33 GMT-0700 (PDT)

module.exports = function(config) {
config.set({

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',


// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],


// list of files / patterns to load in the browser
files: [
'test/test_bundle.js'
],


// list of files to exclude
exclude: [
],


// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},


// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],


// web server port
port: 9876,


// enable / disable colors in the output (reporters and logs)
colors: true,


// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,


// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,


// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],


// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true,

// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
});
};
25 changes: 25 additions & 0 deletions vic-class22-assignment/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "vic-class22-assignment",
"version": "1.0.0",
"description": "",
"main": "gulpfile.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"angular": "^1.5.6",
"express": "^4.13.4",
"express-static": "^1.0.3"
},
"devDependencies": {
"angular-mocks": "^1.5.7",
"gulp": "^3.9.1",
"gulp-eslint": "^2.0.0",
"gulp-watch": "^4.3.6",
"webpack-stream": "^3.2.0"
}
}
Loading