Class: Zarta::Room

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

Overview

Where all the magic happens. Not really. Magic hasn’t been implemented.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dungeon) ⇒ Room

Returns a new instance of Room.



93
94
95
96
97
98
99
100
101
102
# File 'lib/zarta/dungeon.rb', line 93

def initialize(dungeon)
  @dungeon              = dungeon
  @description          = new_description
  @next_rooms           = [] # A list of room objects. Well, it will be.
  @dungeon.stairs_time += 1
  @stairs               = false

  @enemy = []
  populate_room
end

Instance Attribute Details

#descriptionObject

The description of the room



79
80
81
# File 'lib/zarta/dungeon.rb', line 79

def description
  @description
end

#dungeonObject

The dungeon. The main guy. The big cheese.



76
77
78
# File 'lib/zarta/dungeon.rb', line 76

def dungeon
  @dungeon
end

#enemyObject

If an enemy spawned in this room, he’ll be in here



85
86
87
# File 'lib/zarta/dungeon.rb', line 85

def enemy
  @enemy
end

#next_roomsObject

A list of rooms that are ‘connected’ to this one



82
83
84
# File 'lib/zarta/dungeon.rb', line 82

def next_rooms
  @next_rooms
end

#stairsObject

Stairs, yes or no?



91
92
93
# File 'lib/zarta/dungeon.rb', line 91

def stairs
  @stairs
end

#weaponObject

See above. Except this one is for weapons. If that wasn’t clear.



88
89
90
# File 'lib/zarta/dungeon.rb', line 88

def weapon
  @weapon
end

Instance Method Details

#enemy_spawnedObject

These next three functions handle the amazingly complex algorithm that determines if objects spawn in this room.



129
130
131
132
# File 'lib/zarta/dungeon.rb', line 129

def enemy_spawned
  enemy_chance = ENEMY_CHANCE_BASE + (@dungeon.level + ENEMY_CHANCE_MOD)
  enemy_chance > rand(100)
end

#new_descriptionObject

Buys itself something pretty. As long as its a random word from a yaml file.



106
107
108
# File 'lib/zarta/dungeon.rb', line 106

def new_description
  @dungeon.room_list[rand(0...@dungeon.room_list.length)]
end

#new_roomsObject

I can’t call this in the initialization or else it will endlessly spawn rooms and break everything.



119
120
121
122
123
124
125
# File 'lib/zarta/dungeon.rb', line 119

def new_rooms
  min_rooms = MIN_NEXT_ROOMS
  max_rooms = MAX_NEXT_ROOMS
  rand(min_rooms..max_rooms).times do
    @next_rooms << Zarta::Room.new(@dungeon)
  end
end

#populate_roomObject

If anything exciting is going to happen in this room, it starts in here.



111
112
113
114
115
# File 'lib/zarta/dungeon.rb', line 111

def populate_room
  @enemy  = Zarta::Enemy.new(@dungeon) if enemy_spawned
  @weapon = Zarta::Weapon.new(@dungeon) if weapon_spawned
  @stairs = stairs_spawned
end

#stairs_spawnedObject



139
140
141
142
143
144
145
# File 'lib/zarta/dungeon.rb', line 139

def stairs_spawned
  return false if @dungeon.level == @dungeon.max_level
  @dungeon.stairs_time += 1
  return false unless STAIRS_CHANCE + @dungeon.stairs_time > rand(100)
  @dungeon.stairs_time = 0
  true
end

#weapon_spawnedObject



134
135
136
137
# File 'lib/zarta/dungeon.rb', line 134

def weapon_spawned
  weapon_chance = WEAPON_CHANCE_BASE + (@dungeon.level + WEAPON_CHANCE_MOD)
  weapon_chance > rand(100)
end