Module: Robot

Defined in:
lib/robot.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#actionsObject

the action hash of your robot



38
39
40
# File 'lib/robot.rb', line 38

def actions
  @actions
end

#eventsObject

the event hash of your robot



41
42
43
# File 'lib/robot.rb', line 41

def events
  @events
end

#ordersObject

Returns the value of attribute orders.



43
44
45
# File 'lib/robot.rb', line 43

def orders
  @orders
end

#skin_prefixObject

path to where your robot’s optional skin images are



46
47
48
# File 'lib/robot.rb', line 46

def skin_prefix
  @skin_prefix
end

#stateObject

the state hash of your robot. also accessible through the attr_state methods



35
36
37
# File 'lib/robot.rb', line 35

def state
  @state
end

Class Method Details

.attr_action(*names) ⇒ Object



11
12
13
14
15
16
# File 'lib/robot.rb', line 11

def self.attr_action(*names)
  names.each{|n|
    n = n.to_sym
    define_method(n){|param| @actions[n] = param }
  }
end

.attr_event(*names) ⇒ Object



25
26
27
28
29
30
# File 'lib/robot.rb', line 25

def self.attr_event(*names)
  names.each{|n|
    n = n.to_sym
    define_method(n){ @events[n] }
  }
end

.attr_order(*names) ⇒ Object



18
19
20
21
22
23
# File 'lib/robot.rb', line 18

def self.attr_order(*names)
  names.each{|n|
    n = n.to_sym
    define_method(n){ @orders[n] = true }
  }
end

.attr_state(*names) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/robot.rb', line 3

def self.attr_state(*names)
  names.each{|n|
    n = n.to_sym
    attr_writer n
    attr_reader n
  }
end

Instance Method Details

#stopObject

accelerates negativ if moving forward (and vice versa), may take 8 ticks to stop (and you have to call it every tick)



95
96
97
# File 'lib/robot.rb', line 95

def stop
  accelerate((speed > 0) ? -1 : ((speed < 0) ? 1 :0))
end