Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions main.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
require_relative "planet.rb"
require_relative "solar_system.rb"

def main_menu
puts "Welcome to make yo own planet!"
puts "What would you like to do next? You can choose from: \n 1. List Planets \n 2. Planet Details \n 3. Add Planet \n 4. Exit"
main
end

def main
earth = Planet.new("Earth", "blue-green", 5.972e24, 1.496e8, "Only planet known to support life")
cloudster = Planet.new("Cloudster", "pink", 5, 23, "Hello Kitty Universe planet")
puffy = Planet.new("Puffy", "periwinkle", 124234, 325623, "Hello Kitte bioverse")
glitterish = Planet.new("Glitterish", "surruliean", 35435472, 23513541, "Hello Kitty world with lots of water and grass")

# Solar System 1
solar_system = SolarSystem.new("Ethereal")
solar_system.add_planets(earth)
solar_system.add_planets(cloudster)
list = solar_system.list_planets

# solar_system = SolarSystem.new("Ethereal")
# solar_system.add_planet(earth)
# solar_system.add_planet(cloudster)
# solar_system.add_planet(puffy)
# solar_system.add_planet(glitterish)

user_input = "y"
while user_input == "y"
puts $\
puts "Make a selection"
choice = gets.chomp.to_i

list = solar_system.list_planets

if choice == 1
print list
elsif choice == 2
puts "Lets find out more about the planets"
print list
planet_info = gets.chomp
found_planet = solar_system.find_planet_by_name(planet_info)

if found_planet
puts "You have chosen #{found_planet.name}."
puts found_planet.summary
end

elsif choice == 3
solar_system.create_planet
elsif choice == 4
answer = "y"
while answer == "y"
puts "Do you want to play again? Yes or No?"
answer = gets.chomp
if answer == "yes"
main_menu
else
break
end
end
exit
end
end
end
main_menu

#push!
16 changes: 16 additions & 0 deletions planet.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Planet
attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact

def initialize(name, color, mass_kg, distance_from_sun_km, fun_fact)
@name = name
@color = color
@mass_kg = mass_kg
@distance_from_sun_km = distance_from_sun_km
@fun_fact = fun_fact
end

def summary
return "The planet of #{name} is the color #{color} and weighs #{mass_kg} in kg. You might also find it intereesting that it is #{distance_from_sun_km} km away from Earth. The best part of planet #{name} is that it is #{fun_fact}."
end
end
#push!
45 changes: 45 additions & 0 deletions solar_system.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
class SolarSystem
attr_reader :star_name, :planets

def initialize(star_name)
@star_name = star_name
@planets = []
end

def add_planets(planet)
@planets << planet
end

def list_planets
list = @planets.each_with_index.map do |planet, i|
"#{i +1}. #{planet.name}."
end
return "Planets orbiting #{@star_name}: \n#{list.join("\n")}"
end

def find_planet_by_name(planet_name)
return @planets.find do |planet|
planet.name == planet_name.capitalize
end
end

def create_planet
puts "To make a new planet, enter planet details"
puts "enter the name"
new_name = gets.chomp
puts "what color is the planet?"
new_color_planet = gets.chomp
puts "whats the mass in kg"
new_mass_kg = gets.chomp.to_f
puts "what is the distance from the sun"
new_distance_from_sun = gets.chomp.to_i
puts "tell me your planets fun fact"
new_fun_fact = gets.chomp

user_planet = Planet.new(new_name, new_color_planet,new_mass_kg, new_distance_from_sun, new_fun_fact)
add_planets(user_planet)
end


end
#push!