Permalink
Browse files

bug free winning!

  • Loading branch information...
1 parent 09a925a commit 1256e1636cf92902ff871f6ac6da936eb441e5aa @seanhess committed Nov 11, 2012
View
@@ -18,6 +18,13 @@ Hit List
* Fix rounds / winning
* Fix closed-lid players
* Explosion
+* Rocket animation?
+* BUG: must click to play
+
+* use signals/events instead of $rootScope.broadcast
+
+* CLEANUP: going back to the main page should clean up the game.
+* IDEA: switch game/matches when you switch matches?
* DONE move/fire after dead
@@ -26,8 +33,27 @@ Next Features
* facebook / twitter login
* invite only
-
Not Yet
-------
* Update payments
* matchmaking via geolocation
+* Cannonical server? Ditch firebase?
+
+
+
+
+If you can only kill yourself, you have that stupid timeout problem
+ - mark someone as pending dead
+ - then change to dead unless they correct it in the meantime
+
+Something simple?
+ - killer marks you as dead, rather than vice versa.
+ - simple way, haven't even tried it the other way :)
+
+Solve the timeout problem:
+ - heartbeat?
+
+Long term fix: use your own system
+ + heartbeat
+ + server evaluates hits
+
@@ -92,8 +92,6 @@ angular.module('controllers')
players.current.x = position.x
players.current.y = position.y
players.current.direction = position.direction
- console.log(players.current.direction)
-
Players.move(players, players.current);
// WILL I HIT ANY OTHER PLAYERS?
@@ -1,7 +1,6 @@
///<reference path="../def/angular.d.ts"/>
///<reference path="../def/jquery.d.ts"/>
-console.log("KEYPRESS")
angular.module('directives')
.directive('keypress', function($parse) {
return function(scope:ng.IScope, element:JQuery, attrs) {
@@ -48,6 +48,7 @@ angular.module('directives')
frame = 0
stopWalking() // don't double animate!
interval = setInterval(animateFrame, FRAME_DURATION)
+ animateFrame()
}
function stopWalking() {
@@ -28,7 +28,7 @@
<div id="board" keypress="keypress(e)" ng-click="test()">
- <h1 class="winner" ng-show="players.winner">{{players.winner.name}} Wins!</h1>
+ <h1 class="winner" ng-show="players.winner">{{players.winner}} Wins!</h1>
<div class="player avatar {{player.avatar}}"
ng-repeat="player in players.all | filter:{state:'alive'}"
@@ -102,9 +102,11 @@ angular.module('services')
// Check to see if the missile hits anyone
var hitPlayer = <IPlayer> Board.findHit(players.all, missile)
if (hitPlayer) {
- explodeMissile(missile)
- if (hitPlayer == players.current)
- Players.killPlayer(players, players.current, missile.sourcePlayer)
+ explodeMissile(missile) // if you see it hit, then remove it
+
+ // if it's YOUR missile, blow them up!
+ if (missile.sourcePlayer == players.current.name)
+ Players.killPlayer(players, hitPlayer, missile.sourcePlayer)
}
}
View
@@ -28,7 +28,7 @@ interface IPlayer {
// only variables
interface IPlayerState {
current: IPlayer;
- winner: IPlayer;
+ winner: string;
taunt: string;
isPaid: bool;
all: IPlayer [];
@@ -51,6 +51,9 @@ interface IPlayerService {
join(state:IPlayerState, player:IPlayer);
killPlayer(state:IPlayerState, player:IPlayer, killerName:string);
move(state:IPlayerState, player:IPlayer);
+
+ // TODO no reset, make a NEW game
+ resetGame(state:IPlayerState);
}
angular.module('services')
@@ -68,7 +71,8 @@ angular.module('services')
connect: connect,
join: join,
killPlayer: killPlayer,
- move: move
+ move: move,
+ resetGame: resetGame,
}
function connect(gameId:string):IPlayerState {
@@ -93,6 +97,8 @@ angular.module('services')
playersRef.on('child_changed', FB.apply((p) => onUpdate(state,p)))
playersRef.on('child_removed', FB.apply((p) => onQuit(state,p)))
+ gameRef.child('winner').on('value', FB.apply((n) => onWinner(state,n)))
+
return state
}
@@ -150,7 +156,9 @@ angular.module('services')
if (remotePlayer.killer) player.killer = remotePlayer.killer
if (player.state == STATE.DEAD) {
+ console.log("DEATH", player.name)
$rootScope.$broadcast("kill", player)
+ // EVERYONE needs to check the win, because otherwise the game doesn't end!
checkWin(state)
}
}
@@ -159,60 +167,38 @@ angular.module('services')
state.all = state.all.filter((p) => p.name != player.name)
}
- function checkWin(state:IPlayerState) {
- var alive = alivePlayers(state.all)
-
- if (alive.length > 1) return
- var winner = alive[0]
- if (state.current == null || winner != state.current) return
-
- // only if is ME
- // why not share the winner with everyone?
- winner.wins += 1
- state.playersRef.child(winner.name).child("wins").set(winner.wins)
- state.gameRef.child("winner").removeOnDisconnect();
- FB.update(state.gameRef.child("winner"), winner)
- // Nobody else should be able to act (already because they are dead)
-
- // game is set to OVER (missiles finish hitting? like, can you still die?)
- // save the WINNER!
-
- // YOU WIN
-
- // kick the game back to zero
- // restart the game in 3 seconds!
- // then turn everyone back to alive! (the winner does this?)
- }
-
- function onWinner(state:IPlayerState, player:IPlayer) {
+ function onWinner(state:IPlayerState, name:string) {
- // this can get called with null
- if (!player) {
- state.winner = null
+ // ignore nulls
+ if (!name) {
+ state.winner = name
state.taunt = null
return
}
- // don't "WIN" twice if you're already the winner
- if (state.winner && state.winner.name == player.name)
- return
+ // ignore if it hasn't changed
+ if (name == state.winner) return
- // set the winner on all computers
- state.winner = player
+ state.winner = name
state.taunt = TAUNT_LIST[Math.floor(Math.random()*TAUNT_LIST.length)];
+ console.log("WE HAVE A WINNER", state.winner)
+ $rootScope.$broadcast("winner", name)
- // only one person should reset the game
- //console.log("ON WINNER")
- //if (players.current) console.log(" - me ", players.current.name)
- //if (player) console.log(" - win", player.name)
- //if (players.winner) console.log(" - old", players.winner.name)
- //console.log("PASSED")
+ // Now EVERYONE resets the game together
+ setTimeout(() => resetGame(state), 1000)
- if (state.current && state.current.name == player.name) {
- setTimeout(() => resetGame(state), 3000)
- }
+ // don't "WIN" twice if you're already the winner
+ //if (state.winner && state.winner.name == player.name)
+ //return
+
+ //if (state.current && state.current.name == player.name) {
+ //setTimeout(() => resetGame(state), 3000)
+ //}
}
+ // reset game
+ // immediately makes it playable?
+ // I could move them back
function resetGame(state:IPlayerState) {
console.log("Initialize Game")
// build walls?? (how t
@@ -230,12 +216,34 @@ angular.module('services')
// killPlayer ONLY happens from the current player's perspective. yOu can only kill yourself
function killPlayer(state:IPlayerState, player:IPlayer, killerName:string) {
+ console.log("KILL", player.name, "by", killerName)
player.state = STATE.DEAD
player.losses += 1
player.killer = killerName
FB.update(state.playersRef.child(player.name), player)
}
+ // EVERYONE sets winner / game state to over
+ // but only the winner can add his score if he's paying attention
+ function checkWin(state:IPlayerState) {
+ var alive = alivePlayers(state.all)
+ if (alive.length > 1) return
+
+ var winner = alive[0]
+ console.log("WINNER", winner)
+ //if (state.current == null || winner != state.current) return
+
+ // Game is OVER, set the winner
+ state.gameRef.child("winner").removeOnDisconnect();
+ state.gameRef.child("winner").set(winner.name)
+
+ // only if it is ME, then give yourself a point
+ if (winner.name == state.current.name) {
+ winner.wins += 1
+ state.playersRef.child(winner.name).child("wins").set(winner.wins)
+ }
+ }
+
function move(state:IPlayerState, player:IPlayer) {
var playerRef = state.playersRef.child(player.name)
FB.update(playerRef, player)

0 comments on commit 1256e16

Please sign in to comment.