Class: Room

Inherits:
Object
  • Object
show all
Defined in:
lib/room.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, n, s, e, w, npc, denarii, item) ⇒ Room

Returns a new instance of Room.



3
4
5
6
7
8
9
10
11
12
# File 'lib/room.rb', line 3

def initialize(name, n, s, e, w, npc, denarii, item)
  @name = name
  @n = n
  @s = s
  @e = e
  @w = w
  @npc = npc
  @denarii = denarii
  @item = item
end

Instance Attribute Details

#denariiObject

Returns the value of attribute denarii.



2
3
4
# File 'lib/room.rb', line 2

def denarii
  @denarii
end

#directionObject

Returns the value of attribute direction.



2
3
4
# File 'lib/room.rb', line 2

def direction
  @direction
end

#eObject

Returns the value of attribute e.



2
3
4
# File 'lib/room.rb', line 2

def e
  @e
end

#itemObject

Returns the value of attribute item.



2
3
4
# File 'lib/room.rb', line 2

def item
  @item
end

#nObject

Returns the value of attribute n.



2
3
4
# File 'lib/room.rb', line 2

def n
  @n
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/room.rb', line 2

def name
  @name
end

#npcObject

Returns the value of attribute npc.



2
3
4
# File 'lib/room.rb', line 2

def npc
  @npc
end

#sObject

Returns the value of attribute s.



2
3
4
# File 'lib/room.rb', line 2

def s
  @s
end

#wObject

Returns the value of attribute w.



2
3
4
# File 'lib/room.rb', line 2

def w
  @w
end

Instance Method Details

#lookObject



14
15
16
17
18
19
20
21
22
# File 'lib/room.rb', line 14

def look
  puts 'You are in ' + $player.location.name + '.'
  unless $player.location.npc.nil?
    puts 'There is a ' + $player.location.npc.name + ' in the room.'
  end
  unless $player.location.item.nil? 
    puts 'It contains a ' + $player.location.item.to_s + '.'
  end
end

#searchObject



24
25
26
27
28
29
30
31
32
# File 'lib/room.rb', line 24

def search
  if $player.location.denarii > 0
    $player.gain
    puts 'You find ' + $player.location.denarii.to_s + ' denarii in the room. You now have ' + $player.denarii.to_s + ' denarii.'
    $player.location.denarii = 0
  else
    puts 'There is no money in this room.'
  end
end