aboutsummaryrefslogtreecommitdiff
path: root/02-hub3.rb
blob: f3c6e3dace3200f12f26902193750be51f93a113 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require './level'
require './frame'

$levels << Level.new do
  @interfaces = %w(1 2 3)
  @description = <<~EOD
    You are now a three-port hub. Your job is to forward frames from one interface to all the others.
  EOD

  def target(frame)
    case frame.iface
    when ?1
      [frame.to(?2), frame.to(?3)]
    when ?2
      [frame.to(?1), frame.to(?3)]
    when ?3
      [frame.to(?1), frame.to(?2)]
    else
      []
    end
  end

  def generate
    frame = Frame.new(interfaces.sample, @count)
    @count += 1
    frame
  end

  def click
  end
end