Permalink
Browse files

switched back to module style. I needed to make the interface anyway

  • Loading branch information...
1 parent 94c27dd commit fdc0386f2c3174558804c5fd32bd07dc8353d8c1 @seanhess committed Nov 9, 2012
Showing with 138 additions and 117 deletions.
  1. +1 −0 public/controllers/Identify.js
  2. +3 −1 public/controllers/Identify.ts
  3. +65 −69 public/services/Players.js
  4. +69 −47 public/services/Players.ts
@@ -8,6 +8,7 @@ define(["require", "exports"], function(require, exports) {
$scope.intro = "show";
});
}, 1200);
+ console.log("WAHOO");
$scope.version = AppVersion;
$scope.player = CurrentPlayer.loadPreferences();
$scope.gameId = $scope.player.gameId || "global";
@@ -25,7 +25,7 @@ export interface Scope extends ng.IScope {
}
export class Controller {
- constructor ($scope: Scope, $location: any, Players:ps.PlayerService, CurrentPlayer: any, AppVersion: any) {
+ constructor ($scope: Scope, $location: any, Players:ps.IPlayerService, CurrentPlayer: any, AppVersion: any) {
// HACKY way to do the transition
$scope.intro = "intro"
@@ -36,6 +36,8 @@ export class Controller {
})
}, 1200)
+ console.log("WAHOO")
+
$scope.version = AppVersion
// see if they have a preferred name and gameId
View
@@ -3,16 +3,19 @@ define(["require", "exports", "../app"], function(require, exports, __app__) {
- var PlayerService = (function () {
- function PlayerService($rootScope, FB, Board, AppVersion) {
- this.$rootScope = $rootScope;
- this.FB = FB;
- this.Board = Board;
- this.AppVersion = AppVersion;
- }
- PlayerService.prototype.connect = function (gameId) {
- var _this = this;
- var gameRef = this.FB.game(gameId);
+ app.main.factory('Players', function ($rootScope, FB, Board, AppVersion) {
+ return {
+ isAlive: isAlive,
+ alivePlayers: alivePlayers,
+ playerByName: playerByName,
+ latestVersion: latestVersion,
+ connect: connect,
+ join: join,
+ killPlayer: killPlayer,
+ move: move
+ };
+ function connect(gameId) {
+ var gameRef = FB.game(gameId);
var playersRef = gameRef.child('players');
var state = {
myname: null,
@@ -21,49 +24,49 @@ define(["require", "exports", "../app"], function(require, exports, __app__) {
current: null,
winner: null,
taunt: null,
- isPaid: this.isPaid(),
+ isPaid: isPaid(),
all: []
};
- playersRef.on('child_added', this.FB.apply(function (p) {
- return _this.onJoin(state, p);
+ playersRef.on('child_added', FB.apply(function (p) {
+ return onJoin(state, p);
}));
- playersRef.on('child_changed', this.FB.apply(function (p) {
- return _this.onUpdate(state, p);
+ playersRef.on('child_changed', FB.apply(function (p) {
+ return onUpdate(state, p);
}));
- playersRef.on('child_removed', this.FB.apply(function (p) {
- return _this.onQuit(state, p);
+ playersRef.on('child_removed', FB.apply(function (p) {
+ return onQuit(state, p);
}));
return state;
- };
- PlayerService.prototype.isAlive = function (p) {
+ }
+ function isAlive(p) {
return (p.state == STATE.ALIVE);
- };
- PlayerService.prototype.alivePlayers = function (players) {
- return players.filter(this.isAlive);
- };
- PlayerService.prototype.join = function (state, player) {
+ }
+ function alivePlayers(players) {
+ return players.filter(isAlive);
+ }
+ function join(state, player) {
state.myname = player.name;
- player.x = this.Board.randomX();
- player.y = this.Board.randomY();
+ player.x = Board.randomX();
+ player.y = Board.randomY();
player.sprite = '1';
player.facing = "down";
player.state = STATE.ALIVE;
player.wins = player.wins || 0;
player.losses = player.losses || 0;
player.message = null;
- player.version = this.AppVersion.num;
+ player.version = AppVersion.num;
var ref = state.playersRef.child(player.name);
ref.removeOnDisconnect();
- this.FB.update(ref, player);
- };
- PlayerService.prototype.onJoin = function (state, player) {
+ FB.update(ref, player);
+ }
+ function onJoin(state, player) {
if(!state.current && player.name == state.myname) {
state.current = player;
}
state.all.push(player);
- };
- PlayerService.prototype.onUpdate = function (state, remotePlayer) {
- var player = this.playerByName(state.all, remotePlayer.name);
+ }
+ function onUpdate(state, remotePlayer) {
+ var player = playerByName(state.all, remotePlayer.name);
if(!player) {
return console.log("Error, player not found: " + remotePlayer.name);
}
@@ -77,17 +80,17 @@ define(["require", "exports", "../app"], function(require, exports, __app__) {
player.killer = remotePlayer.killer;
}
if(player.state == STATE.DEAD) {
- this.$rootScope.$broadcast("kill", player);
- this.checkWin(state);
+ $rootScope.$broadcast("kill", player);
+ checkWin(state);
}
- };
- PlayerService.prototype.onQuit = function (state, player) {
+ }
+ function onQuit(state, player) {
state.all = state.all.filter(function (p) {
return p.name != player.name;
});
- };
- PlayerService.prototype.checkWin = function (state) {
- var alive = this.alivePlayers(state.all);
+ }
+ function checkWin(state) {
+ var alive = alivePlayers(state.all);
if(alive.length > 1) {
return;
}
@@ -98,10 +101,9 @@ define(["require", "exports", "../app"], function(require, exports, __app__) {
winner.wins += 1;
state.playersRef.child(winner.name).child("wins").set(winner.wins);
state.gameRef.child("winner").removeOnDisconnect();
- this.FB.update(state.gameRef.child("winner"), winner);
- };
- PlayerService.prototype.onWinner = function (state, player) {
- var _this = this;
+ FB.update(state.gameRef.child("winner"), winner);
+ }
+ function onWinner(state, player) {
if(!player) {
state.winner = null;
state.taunt = null;
@@ -114,51 +116,45 @@ define(["require", "exports", "../app"], function(require, exports, __app__) {
state.taunt = TAUNT_LIST[Math.floor(Math.random() * TAUNT_LIST.length)];
if(state.current && state.current.name == player.name) {
setTimeout(function () {
- return _this.resetGame(state);
+ return resetGame(state);
}, 3000);
}
- };
- PlayerService.prototype.resetGame = function (state) {
- var _this = this;
+ }
+ function resetGame(state) {
console.log("Initialize Game");
state.gameRef.child('winner').remove();
state.all.forEach(function (player) {
- player.x = _this.Board.randomX();
- player.y = _this.Board.randomY();
+ player.x = Board.randomX();
+ player.y = Board.randomY();
player.sprite = '1';
player.facing = "down";
player.state = STATE.ALIVE;
- _this.FB.update(state.playersRef.child(player.name), player);
+ FB.update(state.playersRef.child(player.name), player);
});
- };
- PlayerService.prototype.killPlayer = function (state, player, killerName) {
+ }
+ function killPlayer(state, player, killerName) {
player.state = STATE.DEAD;
player.losses += 1;
player.killer = killerName;
- this.FB.update(state.playersRef.child(player.name), player);
- };
- PlayerService.prototype.move = function (state, player) {
+ FB.update(state.playersRef.child(player.name), player);
+ }
+ function move(state, player) {
var playerRef = state.playersRef.child(player.name);
- this.FB.update(playerRef, player);
- };
- PlayerService.prototype.playerByName = function (players, name) {
+ FB.update(playerRef, player);
+ }
+ function playerByName(players, name) {
return players.filter(function (p) {
return (p.name == name);
})[0];
- };
- PlayerService.prototype.latestVersion = function (players) {
+ }
+ function latestVersion(players) {
return _.max(players, function (player) {
return player.version;
});
- };
- PlayerService.prototype.isPaid = function () {
+ }
+ function isPaid() {
return (localStorage.getItem("payment_status") == "paid");
- };
- return PlayerService;
- })();
- exports.PlayerService = PlayerService;
- app.main.factory('Players', function ($rootScope, FB, Board, AppVersion) {
- return new PlayerService($rootScope, FB, Board, AppVersion);
+ }
});
var TAUNT_LIST = [
"Oooh yeah!",
Oops, something went wrong.

0 comments on commit fdc0386

Please sign in to comment.