Advertisement
Guest User

Untitled

a guest
Jun 29th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.31 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 time = startTime
  12.  
  13.         def weirdTime =
  14.                 if(internalTime == startTime) System.currentTimeMillis - startTime
  15.                 else time
  16.  
  17.         val goals = new TimedMap<GoalEvent>();
  18.        
  19.         def getScore(time: Long, team: Team) = {
  20.                 goals.
  21.                         takeWhile( _.getTime <= time).
  22.                         count( _.getScoringTeam == team )
  23.         }
  24.  
  25.         /** team : the team who scored the goal
  26.          * return value : whether the goal was accepted */
  27.         def signalGoal(team: Team) = signalGoal(weirdTime, timeteam);
  28.  
  29.         /** team : the team who scored the goal
  30.          * return value : whether the goal was accepted */
  31.         def signalGoal(time: Long, team: Team) = {
  32.                 val goal = new GoalEvent(babyFoot, time, team);
  33.                 if(!goal.isValid(rs)) {
  34.                         false
  35.                 } else {
  36.                         goals.put(time, goal)
  37.                         true
  38.                 }
  39.         }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement