@@ -11,6 +11,7 @@ import java.util.{Date,Random}
1111import play .api .Logger
1212import controllers .Gaming
1313import controllers .MessageID .TIME_UP
14+ import play .api .i18n .Messages
1415
1516
1617class Game (val id : String , val roomId : Long , val board : Board , val goal : Goal , val startDate : Date , val endDate : Date , val robots : Map [Color , Robot ], val gamePhase : Phase ){
@@ -33,30 +34,22 @@ class Game(val id:String, val roomId: Long, val board:Board, val goal: Goal, val
3334 // switch to next game phase unless already at the end of the cycle
3435 val endedGame = toPhase(SHOW_SOLUTION )
3536 endedGame.timer.start()
36- // TODO: update room scores, show them during game too
37- println(DbRoomScores .scoresInRoom(roomId).foldLeft(new HashMap [String , (String , Int )]) {
38- // first fold: first the winner of each game
39- (map : HashMap [String , (String , Int )], gameScore : DbRoomScores ) => {
40- val gameId = gameScore.gameId
41- map.get(gameId) match {
42- case None => map + (gameId -> (gameScore.playerName, gameScore.score))
43- case Some ((playerName, score)) => if (score < gameScore.score) {
44- map
45- } else {
46- map + (gameId -> (gameScore.playerName, gameScore.score))
47- }
48- }
49- }
50- }.foldLeft(new HashMap [String , Int ]) {
51- // second fold: count number of victories for each winner
52- (map : HashMap [String , Int ], victory : (String , (String , Int ))) => map.get(victory._2._1) match {
37+ val winners = DbRoomScores .winnersOfRoomId(roomId)
38+ val winner = winners.get(id) match {
39+ case None => " "
40+ case Some ((username, _, _)) => username
41+ }
42+ val scores = winners.foldLeft(new HashMap [String , Int ]) {
43+ // fold to count number of victories for each winner
44+ (map : HashMap [String , Int ], victory : (String , (String , Int , Date ))) => map.get(victory._2._1) match {
5345 case None => map + (victory._2._1 -> 1 )
5446 case Some (count) => map + (victory._2._1 -> (count+ 1 ))
5547 }
56- })
48+ }.map(pair => pair._1 + " : " + pair._2).toList
49+ Gaming .notifyRoom(DbRoom .findById(roomId).get.name, TIME_UP , winner :: scores)
50+ } else {
51+ Gaming .notifyRoom(DbRoom .findById(roomId).get.name, TIME_UP , Seq ())
5752 }
58- // announce game dead to the rooms
59- Gaming .notifyRoom(DbRoom .findById(roomId).get.name, TIME_UP , Seq ())
6053 }
6154
6255 // game init
0 commit comments