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
8 changes: 8 additions & 0 deletions kevinChuang/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
**/node_modules/*
**/vendor/*
**/*.min.js
**/build/*
**/test/*_bundle*
*.md
package.json
test_bundle
43 changes: 43 additions & 0 deletions kevinChuang/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"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"
}
86 changes: 86 additions & 0 deletions kevinChuang/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@

# application specific
db/

# Created by https://www.gitignore.io/api/node,osx,vim

### Node ###
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history


### OSX ###
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk


### Vim ###
# swap
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
# session
Session.vim
# temporary
.netrwhist
*~
# auto-generated tag files
tags
21 changes: 21 additions & 0 deletions kevinChuang/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2016 Kevin Chuang

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Empty file added kevinChuang/README.md
Empty file.
4 changes: 4 additions & 0 deletions kevinChuang/app/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const angular = require('angular');

var textAdventure = angular.module('textAdventure',[]);
require('./js/game/game.js')(textAdventure);
Empty file added kevinChuang/app/css/app.css
Empty file.
29 changes: 29 additions & 0 deletions kevinChuang/app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Text Adventure</title>
<link rel="stylesheet" href="/css/app.css" media="screen" title="no title" charset="utf-8">
</head>
<body data-ng-app="textAdventure">
<main data-ng-controller="GameController as controller" ng-cloak ng-init="controller.startGame()">
<h1>Text Adventure</h1>

<form name="userInput" data-ng-submit="controller.processInput()">
<label for="Command">Command:
<input type="text" required data-ng-model="controller.model.command">
</label>
<button type="submit">Go</button>
</form>

<ul id="inputLog">
<li data-ng-repeat="item in controller.model.gamelog">
<span class="{{item.src}}-input">{{item.msg}}</span>
</li>
</ul>

</main>
<script src="bundle.js" charset="utf-8"></script>
</body>
</html>
152 changes: 152 additions & 0 deletions kevinChuang/app/js/game/controllers/game-controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
module.exports = function(app) {
app.controller('GameController', GameController);
};

function GameController() {
this.model = {
userLocation: 'start',
hasWeapon: false,
command: '',
gamelog: [],
location: {
'start': {
commands: ['?'],
prompt: 'Welcome to the dungeon, you are in a room with a monster. There is a room to your left. Enter ? for avaliable commands at any time'
},
'weaponRoom': {
commands:['take sword', 'look', 'say <message>', 'walk right'],
prompt: 'You are in the weapon room. There is a sword on a rack.'
},
'monsterRoomWithoutWeapon': {
commands: ['walk left', 'look','say <message>'],
prompt: 'You are in a room with a monster.'
},
'monsterRoomWithWeapon' :{
commands: ['walk left','look','say <message>','fight monster'],
prompt: 'You are in a room with a monster. You have a sword in hand.'
}
}
};
GameController.prototype.startGame = function() {
this.model.gamelog = [];
this.model.userLocation = 'monsterRoomWithoutWeapon';
this.model.hasWeapon = false;
this.model.command = '';
this.model.gamelog.push({
src: 'game',
msg: this.model.location.start.prompt
});
this.model.location.start.commands.forEach(function(item) {
this.model.gamelog.push({
src: 'command',
msg: item
});
});
// this.model.userLocation = 'monsterRoomWithoutWeapon';
};

GameController.prototype.processInput = function() {

this.model.gamelog.push({
src: 'user',
msg: this.model.command
});

switch (this.model.command) {

case '?':
this.model.gamelog.push({
src: 'game',
msg: this.currentHelpMsg()
});
break;

case 'walk left':
this.model.userLocation = 'weaponRoom';
this.model.gamelog.push({
src: 'game',
msg: this.model.location.weaponRoom.prompt
});
break;

case 'walk right':
this.model.userLocation = this.model.hasWeapon ? 'monsterRoomWithWeapon' : 'monsterRoomWithoutWeapon';

var currentRoom = this.model.userLocation;

this.model.gamelog.push({
src: 'game',
msg: this.model.location[currentRoom].prompt
});
break;

case 'take sword':
this.model.hasWeapon = true;
this.model.gamelog.push({
src: 'game',
msg: 'Sword taken.'
});
break;

case 'look':
var lookRoom = this.model.userLocation;
this.model.gamelog.push({
src: 'game',
msg: this.model.location[lookRoom].prompt
});
break;

case 'fight monster':
this.model.gamelog.push({
src: 'game',
msg: 'You have slain the monster. Thanks for playing!'
});
break;

default:

var sayArr = this.model.command.split(' ');
if(sayArr[0]==='say') {
this.model.gamelog.push({
src: 'game',
msg: sayArr[1] || 'Say something!'
});
} else {
this.model.gamelog.push({
src: 'game',
msg: 'Bad Command, enter ? for available commands'
});
}
}
this.model.command = '';
};

GameController.prototype.currentHelpMsg = function() {
var str ='';

switch (this.model.userLocation) {

case 'weaponRoom':
this.model.location.weaponRoom.commands.forEach(function(item,index) {
str += index > 0 ? ' | ' : '';
str += item;
});
break;

case 'monsterRoomWithoutWeapon':
this.model.location.monsterRoomWithoutWeapon.commands.forEach(function(item,index) {
str += index > 0 ? ' | ' : '';
str += item;
});
break;

case 'monsterRoomWithWeapon':
this.model.location.monsterRoomWithWeapon.commands.forEach(function(item,index) {
str += index > 0 ? ' | ' : '';
str += item;
});
break;
}
return str;
};
}
3 changes: 3 additions & 0 deletions kevinChuang/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);
};
Loading