Class: LZRTag::Handler::Count
- Defined in:
- lib/lzrtag/handler/count_handler.rb
Overview
This class provides useful statistics about the current game and situation.
The various readable attributes contain various information on the game, such as current kill count, damage done, team and brightness composition, etc. Most of this information can be used to determine game progress
Direct Known Subclasses
Instance Attribute Summary collapse
-
#brightnessCount ⇒ Object
readonly
Returns a Hash with keys equal to player’s brightnesses, describing how many players have which brightness.
-
#teamCount ⇒ Object
readonly
Returns a Hash with keys 0..7, describing which teams have how many players.
Attributes inherited from Base
Instance Method Summary collapse
- #consume_event(evtName, data) ⇒ Object
-
#initialize(*args, **argHash) ⇒ Count
constructor
A new instance of Count.
Methods inherited from HitArb
#_handle_hitArb, #process_raw_hit
Methods inherited from Base
#[], #add_hook, #each, #num_connected, #remove_hook, #send_event
Constructor Details
#initialize(*args, **argHash) ⇒ Count
Returns a new instance of Count.
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/lzrtag/handler/count_handler.rb', line 20 def initialize(*args, **argHash) super(*args, **argHash); @teamCount = Hash.new(); 7.times do |i| @teamCount[i] = 0; end @brightnessCount = Hash.new(); Player::Hardware.getBrightnessKeys().each do |bKey| @brightnessCount[bKey] = 0; end end |
Instance Attribute Details
#brightnessCount ⇒ Object (readonly)
Returns a Hash with keys equal to player’s brightnesses, describing how many players have which brightness
18 19 20 |
# File 'lib/lzrtag/handler/count_handler.rb', line 18 def brightnessCount @brightnessCount end |
#teamCount ⇒ Object (readonly)
Returns a Hash with keys 0..7, describing which teams have how many players
15 16 17 |
# File 'lib/lzrtag/handler/count_handler.rb', line 15 def teamCount @teamCount end |
Instance Method Details
#consume_event(evtName, data) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/lzrtag/handler/count_handler.rb', line 35 def consume_event(evtName, data) super(evtName, data); case evtName when :playerRegistered @teamCount[data[0].team] += 1; @brightnessCount[data[0].brightness] += 1; when :playerUnregistered @teamCount[data[0].team] -= 1; @brightnessCount[data[0].brightness] -= 1; when :playerTeamChanged @teamCount[data[1]] -= 1; @teamCount[data[0].team] += 1; when :playerBrightnessChanged @brightnessCount[data[1]] -= 1; @brightnessCount[data[0].brightness] += 1; end end |