Class: RTanque::Match::TickGroup

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rtanque/match/tick_group.rb

Instance Method Summary collapse

Constructor Details

#initializeTickGroup

Returns a new instance of TickGroup


6
7
8
9
10
# File 'lib/rtanque/match/tick_group.rb', line 6

def initialize
  @members = []
  @pre_tick = nil
  @post_tick = nil
end

Instance Method Details

#add(*members) ⇒ Object


24
25
26
# File 'lib/rtanque/match/tick_group.rb', line 24

def add(*members)
  @members += members.flatten
end

#all_but(*to_exclude) ⇒ Object


16
17
18
# File 'lib/rtanque/match/tick_group.rb', line 16

def all_but(*to_exclude)
  self.to_a - to_exclude
end

#delete_if(&block) ⇒ Object


20
21
22
# File 'lib/rtanque/match/tick_group.rb', line 20

def delete_if(&block)
  @members.delete_if(&block)
end

#each(&block) ⇒ Object


12
13
14
# File 'lib/rtanque/match/tick_group.rb', line 12

def each(&block)
  @members.each(&block)
end

#post_tick(&block) ⇒ Object


32
33
34
# File 'lib/rtanque/match/tick_group.rb', line 32

def post_tick(&block)
  @post_tick = block
end

#pre_tick(&block) ⇒ Object


28
29
30
# File 'lib/rtanque/match/tick_group.rb', line 28

def pre_tick(&block)
  @pre_tick = block
end

#tickObject


36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rtanque/match/tick_group.rb', line 36

def tick
  self.delete_if do |member|
    if member.dead?
      true
    else
      @pre_tick.call(member) if @pre_tick
      member.tick
      @post_tick.call(member) if @post_tick
      false
    end
  end
end