Advertisement
Guest User

Untitled

a guest
Jun 29th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.41 KB | None | 0 0
  1. package fr.enst.pact43.model;
  2.  
  3. import fr.enst.pact43.model.events.GoalEvent
  4. import fr.enst.pact43.rules.RuleSet
  5.  
  6. class GameManager(val babyFoot: BabyFoot) {
  7.         val state = new BabyFootState();
  8.         val rs = new RuleSet();
  9.        
  10.         val startTime = System.currentTimeMillis;
  11.         var internalTime = startTime
  12.  
  13.         def time =
  14.                 if(internalTime == startTime) System.currentTimeMillis - startTime
  15.                 else time
  16.         def time_=(t: Long) {
  17.                 internalTime = t
  18.         }
  19.  
  20.         val goals = new TimedMap<GoalEvent>();
  21.        
  22.         def getScore(time: Long, team: Team) = {
  23.                 //Scala-it
  24.                 goals.
  25.                         takeWhile( _.getTime <= time).
  26.                         count( _.getScoringTeam == team )
  27.         }
  28.  
  29.         /** team : the team who scored the goal
  30.          * return value : whether the goal was accepted */
  31.         def signalGoal(team: Team) = signalGoal(time, team);
  32.  
  33.         /** team : the team who scored the goal
  34.          * return value : whether the goal was accepted */
  35.         def signalGoal(time: Long, team: Team) = {
  36.                 val goal = new GoalEvent(babyFoot, time, team);
  37.                 if(!goal.isValid(rs)) {
  38.                         false
  39.                 } else {
  40.                         goals.put(time, goal)
  41.                         true
  42.                 }
  43.         }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement