@@ -184,6 +184,13 @@ Session.prototype.getStatsFor = function(pid) {
184184 stats . cardsLeft = this . deck . cards . length ;
185185 return stats
186186}
187+ Session . prototype . getAllPlayerStats = function ( ) {
188+ var cardsLeft = this . deck . cards . length ;
189+ return Object . keys ( this . players ) . map ( function ( pid , i ) {
190+ var s = this . players [ pid ] . stats ;
191+ return { playerNum : i + 1 , points : s . points , goodAttempts : s . goodAttempts , badAttempts : s . badAttempts , cardsLeft : cardsLeft } ;
192+ } , this ) ;
193+ }
187194Session . prototype . drawCards = function ( cidsToDelete , count ) {
188195 var that = this ;
189196 count = count || 3 ;
@@ -340,6 +347,7 @@ io.on('connection', function(socket){
340347 else if ( session . isSolution ( solutionCids ) ) {
341348 var newCards = session . drawCards ( solutionCids ) ;
342349 stats = session . turnEnd ( 'good solution' ) ;
350+ var allStats = session . getAllPlayerStats ( ) ;
343351 //needs a check if this has worked!
344352
345353 // Auto-deal if no valid set remains on board
@@ -353,14 +361,16 @@ io.on('connection', function(socket){
353361 oldCardsCids : solutionCids ,
354362 newCards : newCards ,
355363 autoDeal : autoDeal ,
356- stats : stats
364+ stats : stats ,
365+ allPlayerStats : allStats
357366 } ) ) ;
358367
359368 socket . broadcast . emit ( 'solution_found' , JSON . stringify ( {
360369 oldCardsCids : solutionCids ,
361370 newCards : newCards ,
362371 autoDeal : autoDeal ,
363- stats : { cardsLeft : session . deck . cards . length }
372+ stats : { cardsLeft : session . deck . cards . length } ,
373+ allPlayerStats : allStats
364374 } ) ) ;
365375 }
366376 else {
0 commit comments