Class: HarlemBits::Arena

Inherits:
Object
  • Object
show all
Includes:
CliRendering
Defined in:
lib/harlem_bits/arena.rb

Constant Summary

Constants included from CliRendering

CliRendering::COLORS

Instance Method Summary collapse

Methods included from CliRendering

#draw

Constructor Details

#initialize(width, height) ⇒ Arena

Returns a new instance of Arena.



5
6
7
8
9
10
11
12
# File 'lib/harlem_bits/arena.rb', line 5

def initialize(width, height)
  @width, @height, @arena = width.to_i, height.to_i, []
  @height.times do |h|
    @arena << (1..@width).map do |i| 
      Bit.new rand_color
    end
  end
end

Instance Method Details

#centerObject



14
15
16
# File 'lib/harlem_bits/arena.rb', line 14

def center
  @arena[@height/2][@width/2]
end

#clearObject



18
19
20
# File 'lib/harlem_bits/arena.rb', line 18

def clear
  @arena.each { |row| row.each { |bit| bit.off } }
end

#randomObject



26
27
28
29
30
31
32
33
34
# File 'lib/harlem_bits/arena.rb', line 26

def random
  found = []
  @arena.each do |row|
    row.each do |bit|
      found << bit if rand(@width) < @width/3
    end
  end
  found
end

#random!Object



22
23
24
# File 'lib/harlem_bits/arena.rb', line 22

def random!
  random.map { |bit| bit.switch }
end