Skip to content

Instantly share code, notes, and snippets.

@lgranger
Last active September 30, 2015 05:45
Show Gist options
  • Save lgranger/a8914b6cc5e381caefe5 to your computer and use it in GitHub Desktop.
Save lgranger/a8914b6cc5e381caefe5 to your computer and use it in GitHub Desktop.
class Planet
attr_reader :name, :color, :size, :number_of_moons, :rotation, :distance_from_the_sun, :rain
def initialize(planet_hash)
@name = planet_hash[:name]
@color = planet_hash[:color]
@size = planet_hash[:size]
@number_of_moons = rand(0..3)
@rotation = @name.length/2
@distance_from_the_sun = (@color.length) * (@number_of_moons + 1)
end
def air
if rand(1..5) > 2
@atmosphere = "a breathable"
else
@atmosphere = "a poisionous"
end
end
def liquid
if @atmosphere == "a breathable"
if (@name.length > 6) && (@number_of_moons > 0)
@water = "tidal"
else
@water = "fresh"
end
else
if (@name.length > 6) && (@number_of_moons == 0)
@water = "brackish"
else
@water = "no"
end
end
end
def populated
@dry = rand(1..3) > 1
if @water == "fresh" && @dry == true
@populated = "mamals"
elsif ((@water == "brackish") || (@water == "tidal")) && @dry != true
@populated = "amphibians"
else
@populated = "no species"
end
end
def weather(clouds = true)
if (@atmosphere == "a breathable")
if (clouds == true)
@rain = "frequent and plentiful"
else
@rain = "comes rarely"
end
else
if (clouds == true)
@rain = "frequent and acidic"
else
@rain = "comes rarely and acidic"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment