diff --git a/PlanetClass.rb b/PlanetClass.rb new file mode 100644 index 00000000..232628c7 --- /dev/null +++ b/PlanetClass.rb @@ -0,0 +1,112 @@ +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 +# +# brockt = Planet.new("Brockt", "yellow", "medium") +# camdoor = Planet.new("Camdoor", "red", "extra-large") +# drri = Planet.new("Drri", "purple", "extra-small") +# ethar = Planet.new("Ethar", "green", "large") +# furdip = Planet.new("Furdip", "light-brown", "medium") +# grondel = Planet.new("Grondel", "mauve", "large") +# +# planet_array = [atorp, brockt, camdoor, drri, ethar, furdip, grondel] + +# puts "Let's learn about some planets!\nPick a planet that you want to learn about:" +# # sets up a loop to let the user pick again and again what planet they want to learn about until they indicate that they are done +# gooodbye_count = 0 +# +# while gooodbye_count == 0 do +# pt = 0 +# # checks that imput is an int, asks for new imput until given a number +# while pt < planet_array.length do +# puts "#{pt + 1}. #{planet_array[pt].name}" +# pt += 1 +# end +# print ">> " +# list_num = gets.chomp.to_i +# while list_num == 0 do +# puts "Give me the number assoicated with the planet.\nForexample, if you want to learn about Camdoor, type \"3\"." +# print ">> " +# list_num = gets.chomp.to_i +# end +# # prints the infomation about the selecte planet, then asks if they want more +# pt_name = planet_array[list_num - 1] +# #land_status = pt_name.land +# puts "You picked \##{list_num}, #{pt_name.name}." +# puts "#{pt_name.name} is a #{pt_name.size}, #{pt_name.color} planet with #{pt_name.number_of_moons} moons. It has #{pt_name.air} atmosphere, and #{pt_name.liquid} liquid water. It is populated by #{pt_name.land.populated}." +# puts "Facinating! Would you like to hear about another planet?" +# print ">> " +# another = gets.chomp.downcase +# +# case another +# when "no", "nope", "nah", "no thank you" +# puts "Goodbye!" +# gooodbye_count = 1 +# when "yes", "yup", "yeah!", "please" +# puts "Awesome! Pick the next planet that you want to learn about:" +# else +# puts "hmmm.. I didn't quite catch that. Why don't you pick another planet:" +# end +# end diff --git a/SolarSystemClass.rb b/SolarSystemClass.rb new file mode 100644 index 00000000..20ba69bf --- /dev/null +++ b/SolarSystemClass.rb @@ -0,0 +1,35 @@ +class SolarSystem + +require "./PlanetClass" + +attr_reader :name, :planets + + def initialize(name) + @name = name + @planets = [] + end + + def mk1_planet_in_sys(planet_name, planet_hash) + planet_name = Planet.new(planet_hash) + @planets.push(planet_name) + end + + def add_planet_array_in_sys(planet_array) + planet_array.each do |pt| + @planets.push(pt) + end + end + + def list_planets + puts "The planets in the #{@name} solar system are:" + @planets.each do |plt| + puts plt.name + end + end + + def distance_between_planets(planet_a, planet_b) + distace_bettween = (planet_a.distance_from_the_sun - planet_b.distance_from_the_sun).abs + puts "The distance between #{planet_a.name} and #{planet_b.name} is #{distace_bettween} million km's." + end + +end diff --git a/SolarSystemProgram.rb b/SolarSystemProgram.rb new file mode 100644 index 00000000..1f65d100 --- /dev/null +++ b/SolarSystemProgram.rb @@ -0,0 +1,82 @@ +require "./SolarSystemClass" + +# This is the genereric planet construction hash +# planet_hash = { +# name: "Name" +# color: "color" +# size: "size" +# } + +atorp_hash = { + name: "Atorp", + color: "brown", + size: "small" +} + +# make this list of planet.news into hashes so that they can be made into planets + +brockt_hash ={ + name: "Brockt", + color: "yellow", + size: "medium" +} + +camdoor_hash = { + name: "Camdoor", + color: "red", + size: "extra-large" +} + +drri_hash = { + name: "Drri", + color: "purple", + size: "extra-small" +} + +ethar_hash = { + name: "Ethar", + color: "green", + size: "large" +} + +furdip_hash = { + name: "Furdip", + color: "light-brown", + size: "medium" +} + +grondel_hash = { + name: "Grondel", + color: "mauve", + size: "large" +} + +brockt = Planet.new(brockt_hash) +camdoor = Planet.new(camdoor_hash) +drri = Planet.new(drri_hash) +ethar = Planet.new(ethar_hash) +furdip = Planet.new(furdip_hash) +grondel = Planet.new(grondel_hash) + +my_system = SolarSystem.new("GDanger") + +my_system.mk1_planet_in_sys("Atorp", atorp_hash) + +puts "One planet added to the #{my_system.name} solar system:" +my_system.list_planets + +planet_array = [brockt, camdoor, drri, ethar, furdip, grondel] + +my_system.add_planet_array_in_sys(planet_array) + +puts "A whole list of planets added to the #{my_system.name} solar system:" +my_system.list_planets + +random_planet = planet_array[rand(0..(planet_array.length-1))] +random_planet2 = planet_array[rand(0..(planet_array.length-1))] + +puts "#{random_planet.name} is a #{random_planet.size}, #{random_planet.color} planet with #{random_planet.number_of_moons} moons. It has #{random_planet.air} atmosphere, and #{random_planet.liquid} liquid water. It is populated by #{random_planet.populated}." + +puts "The rain on #{random_planet.name} is #{random_planet.weather} when there are clouds but #{random_planet.weather(false)} when there are no clouds." + +my_system.distance_between_planets(random_planet, random_planet2)