Class: Dictionary

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-doom.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDictionary

Returns a new instance of Dictionary.



271
272
273
274
275
276
277
278
279
# File 'lib/ruby-doom.rb', line 271

def initialize
  @things = []
  @things << ThingInfo.new(1, "Player 1", "@")
  @things << ThingInfo.new(9, "Sergeant", "s")
  @things << ThingInfo.new(65, "Commando", "c")
  @things << ThingInfo.new(2001, "Shotgun", "g")
  @things << ThingInfo.new(3001, "Imp", "i")
  @things << ThingInfo.new(2035, "Barrel", "b")
end

Class Method Details

.getObject



265
266
267
268
269
270
# File 'lib/ruby-doom.rb', line 265

def Dictionary.get
  if @self.nil?
    @self = Dictionary.new
  end
  return @self
end

Instance Method Details

#direction_for_angle(angle) ⇒ Object



288
289
290
291
292
293
294
295
296
# File 'lib/ruby-doom.rb', line 288

def direction_for_angle(angle)
  case angle
  when (0..45 or 316..360) then return "east"
  when 46..135 then return "north"
  when 136..225 then return "west"
  when 225..315 then return "south"
  end
  raise "Angle must be between 0 and 360"
end

#thing_for_name(name) ⇒ Object



285
286
287
# File 'lib/ruby-doom.rb', line 285

def thing_for_name(name) 
  @things.find {|x| x.name == name}
end

#thing_for_type_id(id) ⇒ Object



280
281
282
283
284
# File 'lib/ruby-doom.rb', line 280

def thing_for_type_id(id) 
  t = @things.find {|x| x.id == id}
  return ThingInfo.new(-999, "Unknown thing", "?") if t.nil?
  t
end