def test_tick(): period = Period() clock = Clock(period) clock.tick() assert_true(clock.clock > 0) period = Period() clock = Clock(period) clock.tick(30) assert_equal(30, clock.clock)
class Match(object): def __init__(self, show_events=False): self.show_events = show_events self.event = Event() self.home = Team('Calgary Flames', 'CGY') self.road = Team('Edmonton Oilers', 'EDM') self.period = Period() self.start_period() def start_period(self): self.period.next_period() self.clock = Clock(self.period) self.zone = Zone() self.possession = Possession() self.play = Play(self.home, self.road, self.zone, self.possession) self.event.add(self.period, self.clock, self.play(), self.zone) self.event.add(self.period, self.clock, self.play(), self.zone) while self.clock.running: self.next_event() def end_period(self): self.clock.end() self.event.add(self.period, self.clock, self.play.end(), self.zone) if self.period < 3: self.start_period() else: self.end_game() def next_event(self): self.clock.tick() self.home.lineup.lines.add_toi(self.clock.since_last_tick) self.road.lineup.lines.add_toi(self.clock.since_last_tick) if not self.clock.running: self.end_period() else: self.home.lineup.lines.line_change() self.road.lineup.lines.line_change() self.event.add(self.period, self.clock, self.play(), self.zone) def end_game(self): if self.show_events: self.event.show()
def test_since_last_tick(): period = Period() clock = Clock(period) clock.tick(30) assert_equal(30, clock.since_last_tick)
def test_remaining(): period = Period() clock = Clock(period) assert_equal('20:00', clock.remaining) clock.tick(30) assert_equal('19:30', clock.remaining)
def test_elapsed(): period = Period() clock = Clock(period) assert_equal('00:00', clock.elapsed) clock.tick(30) assert_equal('00:30', clock.elapsed)