Permalink
Browse files

Merge branch 'master' of github.com:leecrossley/appsassin

  • Loading branch information...
2 parents 149e837 + 4d4e2aa commit 697499e99f541039afec6d0fe86580f71e336928 @edhiley edhiley committed Oct 27, 2013
View
22 app/controllers/game.js
@@ -29,20 +29,22 @@ exports.eliminate = function(req, res) {
exports.eliminatebyimage = function(req, res) {
Game.findById(req.params.id, function(error, game) {
- game.poshEliminate(req.body.user, req.body.picture, function(photo) {
- if (!photo) {
+ game.poshEliminate(req.headers.host, req.body.user, req.body.picture, function(photo) {
+ console.log(photo);
+ if (!photo || !photo.uids) {
res.json({
status: 'missed'
});
- }
- var user = User.find().where('username').equals(photo.uids[0].prediction).exec(function() {
- game.eliminate(user._id);
- });
+ } else {
+ var user = User.find().where('username').equals(photo.uids[0].prediction).exec(function() {
+ game.eliminate(user._id);
+ });
- res.json({
- status: 'hit',
- photo: photo
- });
+ res.json({
+ status: 'hit',
+ photo: photo
+ });
+ }
});
});
};
View
64 app/models/game.js
@@ -1,6 +1,7 @@
var mongoose = require('mongoose'),
_ = require('underscore'),
request = require('request'),
+ Picture = require('../models/picture'),
Schema = mongoose.Schema;
var GameSchema = new Schema({
@@ -16,7 +17,10 @@ var GameSchema = new Schema({
default: "open"
},
players: [{
- user: {type:Schema.Types.ObjectId,required:true},
+ user: {
+ type: Schema.Types.ObjectId,
+ required: true
+ },
pseudonym: String
}],
missions: [{
@@ -41,12 +45,28 @@ var GameSchema = new Schema({
}]
});
+
+var generatePictureUrl = function(host, id) {
+ return host + "/pictures/" + id;
+ };
+var createPictureTarget = function(encoded) {
+ var picture = createPicture(encoded);
+ picture.isTarget = true;
+ return picture;
+ };
+
+var createPicture = function(encoded) {
+ var picture = new Picture();
+ picture.encoded = encoded;
+ return picture;
+ };
+
GameSchema.methods.addPlayer = function(userid, continuation) {
var game = this;
request("http://namey.muffinlabs.com/name.json?count=1&with_surname=true", function(error, response, body) {
if (game.requiredPlayers <= game.requiredPlayers.length) return;
if (!(game.players.length !== 0 && _.find(game.players, function(p) {
- if(!p.user) return;
+ if (!p.user) return;
return p.user.equals(userid);
}))) {
game.players.push({
@@ -81,20 +101,17 @@ GameSchema.methods.startIfFull = function() {
}
};
-GameSchema.methods.poshEliminate = function(victim,picture,callback)
-{
+GameSchema.methods.poshEliminate = function(host, victim, picture, callback) {
var picture = createPictureTarget(picture);
picture.save(function() {
- var url = generatePictureUrl(req.headers.host, picture.id);
-
- console.log("Trying to recognise player via url: " + url);
+ var url = generatePictureUrl(host, picture.id);
var album = "appsassin2";
var albumkey = "533e6074bc68a3e207f78b4ce6851a3b37e7466ffb34a9e8b60888d527707c70";
-
+ var game = this;
request.post({
url: 'https://lambda-face-recognition.p.mashape.com/recognize?album=' + album + "&albumkey=" + albumkey,
headers: {
@@ -108,26 +125,32 @@ GameSchema.methods.poshEliminate = function(victim,picture,callback)
}, function(error, response, body) {
console.log(body);
if (error) {
- console.log("there was an error sending picture for recog: " + response.body.error);
- // TODO: return matches ...
+ console.log("there was an error sending picture for recog: " + error);
+ callback();
+ }
+ else {
+ var photo = _.find(JSON.parse(body).photos, function(p) {
+ return p.uids[0].prediction == victim.username;
+ });
+ callback(photo);
}
-
});
});
}
+
GameSchema.methods.findVictim = function(userId) {
- console.log("Find victim for user: " + userId);
- return _.find(this.missions.reverse(), function(m) {
- return m.assassin.equals(userId);
- });
+ console.log("Find victim for user: " + userId);
+ return _.find(this.missions.reverse(), function(m) {
+ return m.assassin.equals(userId);
+ });
};
GameSchema.methods.findAssassin = function(userId) {
- console.log("Find assassin for user: " + userId);
- return _.find(this.missions.reverse(), function(m) {
- return m.victim.equals(userId);
- });
+ console.log("Find assassin for user: " + userId);
+ return _.find(this.missions.reverse(), function(m) {
+ return m.victim.equals(userId);
+ });
};
@@ -142,8 +165,7 @@ GameSchema.methods.eliminate = function(user) {
});
- if(!(am || vm))
- return;
+ if (!(am || vm)) return;
this.kills.push({
assassin: user,
View
2 app/models/picture.js
@@ -7,4 +7,4 @@ var PictureSchema = new Schema({
potentialTarget: {type:Boolean,default:false}
});
-mongoose.model('Picture', PictureSchema);
+module.exports = mongoose.model('Picture', PictureSchema);
View
2 app/models/user.js
@@ -7,4 +7,4 @@ var UserSchema = new Schema({
});
-mongoose.model('User', UserSchema);
+module.exports = mongoose.model('User', UserSchema);
View
20 client/platforms/android/assets/www/complete.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+ <body>
+ <header>
+ <h1>APPSASSIN</h1>
+ </header>
+ <div class="container">
+ <div class="winner" style="display:none;">
+ <h3>CONGRATULATIONS!</h3>
+ <h3>You're the last Appsassin standing!</h3>
+ <button class="reset">End</button>
+ </div>
+ <div class="loser" style="display:none;">
+ <h3>YOU'VE BEEN KILLED!</h3>
+ <h3>Better luck next time!</h3>
+ <button class="reset">End</button>
+ </div>
+ </div>
+ </body>
+</html>
View
87 client/platforms/android/assets/www/js/appsassin.js
@@ -2,8 +2,8 @@ var appsassin = (function () {
var appsassin = {},
currentView;
- appsassin.userId,
- appsassin.currentGame;
+ appsassin.userId = null;
+ appsassin.currentGame = null;
// Called when the app is loaded
appsassin.init = function () {
@@ -143,6 +143,7 @@ var appsassin = (function () {
function handleGames(games) {
if (games && games.length > 0) {
appsassin.currentGame = games[0];
+ localStorage.setItem("game", appsassin.currentGame);
server.joinGame(games[0]._id, appsassin.userId, otherPlayers);
} else {
navigator.notification.alert("There are no local games available to join", null, "Appsassin");
@@ -155,6 +156,7 @@ var appsassin = (function () {
function otherPlayers(updatedGame) {
if (appsassin.currentGame && appsassin.currentGame.state) {
appsassin.currentGame = updatedGame;
+ localStorage.setItem("game", appsassin.currentGame);
}
if (appsassin.currentGame.state === "inprogress") {
appsassin.switchView("game");
@@ -178,12 +180,14 @@ var appsassin = (function () {
// Game screen - handles game play
appsassin.game = (function () {
- var game = {};
+ var game = {},
+ map;
game.init = function () {
- var map = new Tracker.Map();
- // Tracks my position on the map
+ map = new Tracker.Map();
+ // Tracks position on the map
map.watchPosition();
+ trackGame();
$(".shoot").bind("click", function(e) {
e.preventDefault();
@@ -199,8 +203,55 @@ var appsassin = (function () {
});
};
- function cameraSuccess(result) {
- alert("TODO validate kill");
+ // Uses the server data to determine if you're still alive :)
+ game.isStillAlive = function () {
+ if (appsassin.currentGame.kills && appsassin.currentGame.kills.length > 0) {
+ var i = 0;
+ while (i < appsassin.currentGame.kills.length) {
+ var kill = appsassin.currentGame.kills[i];
+ if (kill.victim === appsassin.userId) {
+ return false;
+ }
+ i++;
+ }
+ }
+ return true;
+ };
+
+ // Polls the server and keeps track of the game status
+ function trackGame(game) {
+ if (game && game.state) {
+ appsassin.currentGame = game;
+ localStorage.setItem("game", appsassin.currentGame);
+ }
+ if (appsassin.currentGame.state === "complete") {
+ map.clearWatch();
+ appsassin.switchView("complete");
+ } else {
+ if (appsassin.game.isStillAlive()) {
+ setTimeout(function() {
+ server.getGame(appsassin.currentGame._id, trackGame);
+ }, 5000);
+ } else {
+ map.clearWatch();
+ appsassin.switchView("complete");
+ }
+ }
+ }
+
+ function cameraSuccess(imageData) {
+ server.shootTarget(appsassin.user, imageData, appsassin.currentGame._id, shotResult);
+ }
+
+ function shotResult(result) {
+ if (result && result.status === "hit") {
+ navigator.notification.alert("Direct Hit!", null, "Appsassin");
+ if (appsassin.currentGame.state !== "complete") {
+ setTimeout(function() {
+ navigator.notification.alert("You have a new target...", null, "Appsassin");
+ }, 5000);
+ }
+ }
}
function cameraFail(message) {
@@ -210,6 +261,28 @@ var appsassin = (function () {
return game;
})();
+ // Game complete (either you have been killed or have won)
+ appsassin.complete = (function () {
+ var complete = {};
+
+ complete.init = function () {
+ if (appsassin.game.isStillAlive()) {
+ $(".winner").show();
+ } else {
+ $(".loser").show();
+ }
+ $(".reset").bind("click", function(e) {
+ e.preventDefault();
+ e.stopPropagation();
+ appsassin.init();
+ });
+ localStorage.setItem("game", null);
+ appsassin.currentGame = null;
+ };
+
+ return complete;
+ })();
+
return appsassin;
})();
View
10 client/platforms/android/assets/www/js/server.js
@@ -66,13 +66,13 @@ var server = (function () {
doPost("/location/track", data, callback);
};
- server.eliminateTarget = function (user, photo, callback) {
- console.log("killing...");
+ server.shootTarget = function (user, photo, gameId, callback) {
+ console.log("shooting...");
var data = {
- "username": user,
- "image": photo
+ "user": user,
+ "picture": photo
};
- doPost("/eliminate", data, callback);
+ doPost("/shoot/" + gameId, data, callback);
};
return server;
View
6 client/platforms/android/assets/www/js/tracker.js
@@ -47,14 +47,12 @@ var Tracker = Tracker || {};
console.log("Issue with target location");
return;
}
- console.log(data[0]);
- console.log(data[1]);
var point = new OpenLayers.Geometry.Point(data[0], data[1])
.transform(new OpenLayers.Projection("EPSG:4326"), self.map.getProjectionObject());
self.drawTargetMarker(point);
self.map.zoomToExtent(self.vector.getDataExtent());
- };
+ }
};
Tracker.Map.prototype.watchPosition = function () {
@@ -65,6 +63,8 @@ var Tracker = Tracker || {};
};
this.watchId = navigator.geolocation.watchPosition(this.watchedPosition, function(e) {
console.log(e);
+ this.clearWatch();
+ this.watchPosition();
}, options);
};
View
BIN ...n.xcodeproj/project.xcworkspace/xcuserdata/lee.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
View
20 client/platforms/ios/www/complete.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+ <body>
+ <header>
+ <h1>APPSASSIN</h1>
+ </header>
+ <div class="container">
+ <div class="winner" style="display:none;">
+ <h3>CONGRATULATIONS!</h3>
+ <h3>You're the last Appsassin standing!</h3>
+ <button class="reset">End</button>
+ </div>
+ <div class="loser" style="display:none;">
+ <h3>YOU'VE BEEN KILLED!</h3>
+ <h3>Better luck next time!</h3>
+ <button class="reset">End</button>
+ </div>
+ </div>
+ </body>
+</html>
View
87 client/platforms/ios/www/js/appsassin.js
@@ -2,8 +2,8 @@ var appsassin = (function () {
var appsassin = {},
currentView;
- appsassin.userId,
- appsassin.currentGame;
+ appsassin.userId = null;
+ appsassin.currentGame = null;
// Called when the app is loaded
appsassin.init = function () {
@@ -143,6 +143,7 @@ var appsassin = (function () {
function handleGames(games) {
if (games && games.length > 0) {
appsassin.currentGame = games[0];
+ localStorage.setItem("game", appsassin.currentGame);
server.joinGame(games[0]._id, appsassin.userId, otherPlayers);
} else {
navigator.notification.alert("There are no local games available to join", null, "Appsassin");
@@ -155,6 +156,7 @@ var appsassin = (function () {
function otherPlayers(updatedGame) {
if (appsassin.currentGame && appsassin.currentGame.state) {
appsassin.currentGame = updatedGame;
+ localStorage.setItem("game", appsassin.currentGame);
}
if (appsassin.currentGame.state === "inprogress") {
appsassin.switchView("game");
@@ -178,12 +180,14 @@ var appsassin = (function () {
// Game screen - handles game play
appsassin.game = (function () {
- var game = {};
+ var game = {},
+ map;
game.init = function () {
- var map = new Tracker.Map();
- // Tracks my position on the map
+ map = new Tracker.Map();
+ // Tracks position on the map
map.watchPosition();
+ trackGame();
$(".shoot").bind("click", function(e) {
e.preventDefault();
@@ -199,8 +203,55 @@ var appsassin = (function () {
});
};
- function cameraSuccess(result) {
- alert("TODO validate kill");
+ // Uses the server data to determine if you're still alive :)
+ game.isStillAlive = function () {
+ if (appsassin.currentGame.kills && appsassin.currentGame.kills.length > 0) {
+ var i = 0;
+ while (i < appsassin.currentGame.kills.length) {
+ var kill = appsassin.currentGame.kills[i];
+ if (kill.victim === appsassin.userId) {
+ return false;
+ }
+ i++;
+ }
+ }
+ return true;
+ };
+
+ // Polls the server and keeps track of the game status
+ function trackGame(game) {
+ if (game && game.state) {
+ appsassin.currentGame = game;
+ localStorage.setItem("game", appsassin.currentGame);
+ }
+ if (appsassin.currentGame.state === "complete") {
+ map.clearWatch();
+ appsassin.switchView("complete");
+ } else {
+ if (appsassin.game.isStillAlive()) {
+ setTimeout(function() {
+ server.getGame(appsassin.currentGame._id, trackGame);
+ }, 5000);
+ } else {
+ map.clearWatch();
+ appsassin.switchView("complete");
+ }
+ }
+ }
+
+ function cameraSuccess(imageData) {
+ server.shootTarget(appsassin.user, imageData, appsassin.currentGame._id, shotResult);
+ }
+
+ function shotResult(result) {
+ if (result && result.status === "hit") {
+ navigator.notification.alert("Direct Hit!", null, "Appsassin");
+ if (appsassin.currentGame.state !== "complete") {
+ setTimeout(function() {
+ navigator.notification.alert("You have a new target...", null, "Appsassin");
+ }, 5000);
+ }
+ }
}
function cameraFail(message) {
@@ -210,6 +261,28 @@ var appsassin = (function () {
return game;
})();
+ // Game complete (either you have been killed or have won)
+ appsassin.complete = (function () {
+ var complete = {};
+
+ complete.init = function () {
+ if (appsassin.game.isStillAlive()) {
+ $(".winner").show();
+ } else {
+ $(".loser").show();
+ }
+ $(".reset").bind("click", function(e) {
+ e.preventDefault();
+ e.stopPropagation();
+ appsassin.init();
+ });
+ localStorage.setItem("game", null);
+ appsassin.currentGame = null;
+ };
+
+ return complete;
+ })();
+
return appsassin;
})();
View
10 client/platforms/ios/www/js/server.js
@@ -66,13 +66,13 @@ var server = (function () {
doPost("/location/track", data, callback);
};
- server.eliminateTarget = function (user, photo, callback) {
- console.log("killing...");
+ server.shootTarget = function (user, photo, gameId, callback) {
+ console.log("shooting...");
var data = {
- "username": user,
- "image": photo
+ "user": user,
+ "picture": photo
};
- doPost("/eliminate", data, callback);
+ doPost("/shoot/" + gameId, data, callback);
};
return server;
View
6 client/platforms/ios/www/js/tracker.js
@@ -47,14 +47,12 @@ var Tracker = Tracker || {};
console.log("Issue with target location");
return;
}
- console.log(data[0]);
- console.log(data[1]);
var point = new OpenLayers.Geometry.Point(data[0], data[1])
.transform(new OpenLayers.Projection("EPSG:4326"), self.map.getProjectionObject());
self.drawTargetMarker(point);
self.map.zoomToExtent(self.vector.getDataExtent());
- };
+ }
};
Tracker.Map.prototype.watchPosition = function () {
@@ -65,6 +63,8 @@ var Tracker = Tracker || {};
};
this.watchId = navigator.geolocation.watchPosition(this.watchedPosition, function(e) {
console.log(e);
+ this.clearWatch();
+ this.watchPosition();
}, options);
};
View
20 client/www/complete.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+ <body>
+ <header>
+ <h1>APPSASSIN</h1>
+ </header>
+ <div class="container">
+ <div class="winner" style="display:none;">
+ <h3>CONGRATULATIONS!</h3>
+ <h3>You're the last Appsassin standing!</h3>
+ <button class="reset">End</button>
+ </div>
+ <div class="loser" style="display:none;">
+ <h3>YOU'VE BEEN KILLED!</h3>
+ <h3>Better luck next time!</h3>
+ <button class="reset">End</button>
+ </div>
+ </div>
+ </body>
+</html>
View
87 client/www/js/appsassin.js
@@ -2,8 +2,8 @@ var appsassin = (function () {
var appsassin = {},
currentView;
- appsassin.userId,
- appsassin.currentGame;
+ appsassin.userId = null;
+ appsassin.currentGame = null;
// Called when the app is loaded
appsassin.init = function () {
@@ -143,6 +143,7 @@ var appsassin = (function () {
function handleGames(games) {
if (games && games.length > 0) {
appsassin.currentGame = games[0];
+ localStorage.setItem("game", appsassin.currentGame);
server.joinGame(games[0]._id, appsassin.userId, otherPlayers);
} else {
navigator.notification.alert("There are no local games available to join", null, "Appsassin");
@@ -155,6 +156,7 @@ var appsassin = (function () {
function otherPlayers(updatedGame) {
if (appsassin.currentGame && appsassin.currentGame.state) {
appsassin.currentGame = updatedGame;
+ localStorage.setItem("game", appsassin.currentGame);
}
if (appsassin.currentGame.state === "inprogress") {
appsassin.switchView("game");
@@ -178,12 +180,14 @@ var appsassin = (function () {
// Game screen - handles game play
appsassin.game = (function () {
- var game = {};
+ var game = {},
+ map;
game.init = function () {
- var map = new Tracker.Map();
- // Tracks my position on the map
+ map = new Tracker.Map();
+ // Tracks position on the map
map.watchPosition();
+ trackGame();
$(".shoot").bind("click", function(e) {
e.preventDefault();
@@ -199,8 +203,55 @@ var appsassin = (function () {
});
};
- function cameraSuccess(result) {
- alert("TODO validate kill");
+ // Uses the server data to determine if you're still alive :)
+ game.isStillAlive = function () {
+ if (appsassin.currentGame.kills && appsassin.currentGame.kills.length > 0) {
+ var i = 0;
+ while (i < appsassin.currentGame.kills.length) {
+ var kill = appsassin.currentGame.kills[i];
+ if (kill.victim === appsassin.userId) {
+ return false;
+ }
+ i++;
+ }
+ }
+ return true;
+ };
+
+ // Polls the server and keeps track of the game status
+ function trackGame(game) {
+ if (game && game.state) {
+ appsassin.currentGame = game;
+ localStorage.setItem("game", appsassin.currentGame);
+ }
+ if (appsassin.currentGame.state === "complete") {
+ map.clearWatch();
+ appsassin.switchView("complete");
+ } else {
+ if (appsassin.game.isStillAlive()) {
+ setTimeout(function() {
+ server.getGame(appsassin.currentGame._id, trackGame);
+ }, 5000);
+ } else {
+ map.clearWatch();
+ appsassin.switchView("complete");
+ }
+ }
+ }
+
+ function cameraSuccess(imageData) {
+ server.shootTarget(appsassin.user, imageData, appsassin.currentGame._id, shotResult);
+ }
+
+ function shotResult(result) {
+ if (result && result.status === "hit") {
+ navigator.notification.alert("Direct Hit!", null, "Appsassin");
+ if (appsassin.currentGame.state !== "complete") {
+ setTimeout(function() {
+ navigator.notification.alert("You have a new target...", null, "Appsassin");
+ }, 5000);
+ }
+ }
}
function cameraFail(message) {
@@ -210,6 +261,28 @@ var appsassin = (function () {
return game;
})();
+ // Game complete (either you have been killed or have won)
+ appsassin.complete = (function () {
+ var complete = {};
+
+ complete.init = function () {
+ if (appsassin.game.isStillAlive()) {
+ $(".winner").show();
+ } else {
+ $(".loser").show();
+ }
+ $(".reset").bind("click", function(e) {
+ e.preventDefault();
+ e.stopPropagation();
+ appsassin.init();
+ });
+ localStorage.setItem("game", null);
+ appsassin.currentGame = null;
+ };
+
+ return complete;
+ })();
+
return appsassin;
})();
View
10 client/www/js/server.js
@@ -66,13 +66,13 @@ var server = (function () {
doPost("/location/track", data, callback);
};
- server.eliminateTarget = function (user, photo, callback) {
- console.log("killing...");
+ server.shootTarget = function (user, photo, gameId, callback) {
+ console.log("shooting...");
var data = {
- "username": user,
- "image": photo
+ "user": user,
+ "picture": photo
};
- doPost("/eliminate", data, callback);
+ doPost("/shoot/" + gameId, data, callback);
};
return server;
View
6 client/www/js/tracker.js
@@ -47,14 +47,12 @@ var Tracker = Tracker || {};
console.log("Issue with target location");
return;
}
- console.log(data[0]);
- console.log(data[1]);
var point = new OpenLayers.Geometry.Point(data[0], data[1])
.transform(new OpenLayers.Projection("EPSG:4326"), self.map.getProjectionObject());
self.drawTargetMarker(point);
self.map.zoomToExtent(self.vector.getDataExtent());
- };
+ }
};
Tracker.Map.prototype.watchPosition = function () {
@@ -65,6 +63,8 @@ var Tracker = Tracker || {};
};
this.watchId = navigator.geolocation.watchPosition(this.watchedPosition, function(e) {
console.log(e);
+ this.clearWatch();
+ this.watchPosition();
}, options);
};
View
1 config/routes.js
@@ -17,6 +17,7 @@ module.exports = function(app){
app.get('/api/v1/opengames',game.open);
app.post('/api/v1/joingame/:id',game.join);
app.post('/api/v1/eliminate/:id',game.eliminate);
+ app.post('/api/v1/shoot/:id',game.eliminatebyimage);
var location = require('../app/controllers/location');
app.post('/api/v1/location/track', location.track);
View
2 package.json
@@ -1,6 +1,6 @@
{
"name": "appsassin",
- "version": "0.0.1-30",
+ "version": "0.0.1-32",
"private": true,
"scripts": {
"start": "app.js"

0 comments on commit 697499e

Please sign in to comment.