Class: Biome
- Inherits:
-
Object
- Object
- Biome
- Defined in:
- lib/biome.rb
Constant Summary collapse
- SNOW =
Biome.new(name: 'snow', flora_range: nil, colour: AnsiColours::Background::WHITE)
- ROCKS =
Biome.new(name: 'rocks', flora_range: nil, colour: AnsiColours::Background::GREY)
- MOUNTAIN =
Biome.new(name: 'mountain', flora_range: nil, colour: AnsiColours::Background::BROWN)
- MOUNTAIN_FOOT =
Biome.new(name: 'mountain_foot', flora_range: 10, colour: AnsiColours::Background::RED_BROWN)
- GRASSLAND =
Biome.new(name: 'grassland', flora_range: 1, colour: AnsiColours::Background::DARK_GREEN)
- VALLEY =
Biome.new(name: 'valley', flora_range: 1, colour: AnsiColours::Background::GREEN)
- DEEP_VALLEY =
Biome.new(name: 'deep_valley', flora_range: 1, colour: AnsiColours::Background::LIGHT_GREEN)
- DESERT =
Biome.new(name: 'desert', flora_range: 1, colour: AnsiColours::Background::DESERT_YELLOW)
- DEEP_DESERT =
Biome.new(name: 'deep_desert', flora_range: 1, colour: AnsiColours::Background::DESERT_LIGHT_YELLOW)
- STEPPE_DESERT =
Biome.new(name: 'steppe_desert', flora_range: 1, colour: AnsiColours::Background::DESERT_DARK_YELLOW)
- SWAMP =
Biome.new(name: 'swamp', flora_range: nil, colour: AnsiColours::Background::GREEN_SWAMP)
- COASTLINE =
Biome.new(name: 'coastline', flora_range: nil, colour: AnsiColours::Background::SANDY)
- SHOAL =
Biome.new(name: 'shoal', flora_range: nil, colour: AnsiColours::Background::SHOAL_BLUE)
- OCEAN =
Biome.new(name: 'ocean', flora_range: nil, colour: AnsiColours::Background::LIGHT_BLUE)
- DEEP_OCEAN =
Biome.new(name: 'deep_ocean', flora_range: nil, colour: AnsiColours::Background::BLUE)
- TAIGA_PLAIN =
Biome.new(name: 'taiga_plain', flora_range: 1.5, colour: AnsiColours::Background::TAIGA_PLAIN)
- TAIGA_VALLEY =
Biome.new(name: 'taiga_valley', flora_range: 1.5, colour: AnsiColours::Background::TAIGA_VALLEY)
- TAIGA_HIGHLAND =
Biome.new(name: 'taiga_highland', flora_range: 1.5, colour: AnsiColours::Background::TAIGA_HIGHLAND)
- TAIGA_COAST =
Biome.new(name: 'taiga_coast', flora_range: nil, colour: AnsiColours::Background::TAIGA_COAST)
- ICE =
Biome.new(name: 'ice', flora_range: nil, colour: AnsiColours::Background::ICE)
- ALL_TERRAIN =
[ SNOW, ROCKS, MOUNTAIN, MOUNTAIN_FOOT, GRASSLAND, VALLEY, COASTLINE, SHOAL, OCEAN, DEEP_OCEAN, DESERT, DEEP_DESERT, STEPPE_DESERT, SWAMP, TAIGA_PLAIN, TAIGA_HIGHLAND, TAIGA_VALLEY, TAIGA_COAST, ICE ].freeze
- WATER_TERRAIN =
[ SHOAL, OCEAN, DEEP_OCEAN ].freeze
- DESERT_TERRAIN =
[ DESERT, DEEP_DESERT, STEPPE_DESERT ].freeze
- GRASSLAND_TERRAIN =
[ GRASSLAND, VALLEY, DEEP_VALLEY, MOUNTAIN_FOOT ].freeze
- TAIGA_TERRAIN =
[ TAIGA_PLAIN, TAIGA_HIGHLAND, TAIGA_VALLEY, TAIGA_COAST ].freeze
- HIGH_MOUNTAIN =
[ SNOW, ROCKS, MOUNTAIN ].freeze
- LAND_TERRAIN =
(ALL_TERRAIN - WATER_TERRAIN).freeze
Instance Attribute Summary collapse
-
#colour ⇒ Object
Returns the value of attribute colour.
-
#flora_range ⇒ Object
Returns the value of attribute flora_range.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #desert? ⇒ Boolean
- #flora ⇒ Object
- #flora_available ⇒ Object
- #grassland? ⇒ Boolean
- #high_mountain? ⇒ Boolean
-
#initialize(name:, colour:, flora_range: nil) ⇒ Biome
constructor
A new instance of Biome.
- #land? ⇒ Boolean
- #taiga? ⇒ Boolean
- #to_h ⇒ Object
- #water? ⇒ Boolean
Constructor Details
#initialize(name:, colour:, flora_range: nil) ⇒ Biome
Returns a new instance of Biome.
9 10 11 12 13 |
# File 'lib/biome.rb', line 9 def initialize(name:, colour:, flora_range: nil) @name = name @flora_range = flora_range @colour = colour end |
Instance Attribute Details
#colour ⇒ Object
Returns the value of attribute colour.
7 8 9 |
# File 'lib/biome.rb', line 7 def colour @colour end |
#flora_range ⇒ Object
Returns the value of attribute flora_range.
7 8 9 |
# File 'lib/biome.rb', line 7 def flora_range @flora_range end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/biome.rb', line 7 def name @name end |
Class Method Details
.from(elevation, moist, temp) ⇒ Object
66 67 68 |
# File 'lib/biome.rb', line 66 def self.from(elevation, moist, temp) terrain_selection(elevation, moist, temp) end |
Instance Method Details
#desert? ⇒ Boolean
27 28 29 |
# File 'lib/biome.rb', line 27 def desert? DESERT_TERRAIN.include?(self) end |
#flora ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/biome.rb', line 43 def flora @flora ||= if flora_available if desert? Flora.new(Flora::CACTUS) elsif grassland? Flora.new(Flora::DECIDUOUS_TREE) elsif taiga? Flora.new(Flora::EVERGREEN_TREE) else raise StandardError, "Unknown flora #{to_h}" end end end |
#flora_available ⇒ Object
39 40 41 |
# File 'lib/biome.rb', line 39 def flora_available !flora_range.nil? end |
#grassland? ⇒ Boolean
23 24 25 |
# File 'lib/biome.rb', line 23 def grassland? GRASSLAND_TERRAIN.include?(self) end |
#high_mountain? ⇒ Boolean
35 36 37 |
# File 'lib/biome.rb', line 35 def high_mountain? HIGH_MOUNTAIN.include?(self) end |
#taiga? ⇒ Boolean
31 32 33 |
# File 'lib/biome.rb', line 31 def taiga? TAIGA_TERRAIN.include?(self) end |
#to_h ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/biome.rb', line 58 def to_h { name: name, flora_range: flora_range, colour: colour } end |
#water? ⇒ Boolean
15 16 17 |
# File 'lib/biome.rb', line 15 def water? WATER_TERRAIN.include?(self) end |