diff --git a/main.rb b/main.rb new file mode 100644 index 00000000..86aaab65 --- /dev/null +++ b/main.rb @@ -0,0 +1,94 @@ +require_relative 'planet' +require_relative 'solar_system' +require 'faker' +require 'ruby_figlet' +require 'colorize' +def colors(string) + string.chars.map {|char| char.colorize([:light_red, :light_cyan, :light_green, :light_blue].sample)}.join +end + +def user_add_planet(solar_system) + puts "\nAdding a planet is for scientists ONLY. Are you a real scientist? (Y/N)" + y_n = gets.chomp.upcase + if y_n == "Y" + puts "" + puts "Please provide some data:" + print "Name of planet: " + name = gets.chomp + print "Surface color: " + color = gets.chomp + print "Planetary mass in kilograms/10^24?: " + mass_kg = gets.chomp.to_f + print "Orbital radius in kilometers/10^22: " + distance_from_sun = gets.chomp.to_f + fun_fact = "" + new_planet = Planet.new(name, color, mass_kg, distance_from_sun, fun_fact) + solar_system.add_planet(new_planet) + puts "\nThank you for the science.\n" + else + puts "Please try again with more scientific integrity." + end +end + +def display_data(solar_system) + print "What is the name of the planet you wish to learn about? " + query = gets.chomp + found_planet = solar_system.find_planet_by_name(query) + return found_planet +end + +def main + solar_system = SolarSystem.new(Faker::Space.star) + + 8.times do |x| + new_planet = [] + new_planet[x] = Planet.new(Faker::Books::Dune.unique.planet, Faker::Color.color_name, rand(100...10000), rand(100...10000), "") + solar_system.add_planet(new_planet[x]) + x += 1 + end + + loooop = true + while loooop == true do + puts + puts colors("-----------------------------------------------------------") + puts + puts "What would you like to do next?\n" + puts "1. List Planets".colorize(:green) + puts "2. See Planet Details".colorize(:blue) + puts "3. Add Planet".colorize(:magenta) + puts "4. Quit".colorize(:red) + puts + print "Enter the number of your choice: " + control = gets.chomp.to_i + case control + when 1 + puts "#{solar_system.list_planets}\n" + when 2 + the_query = display_data(solar_system) + puts colors(the_query.summary) + when 3 + user_add_planet(solar_system) + when 4 + puts "Goodbye!" + exit + else + puts "That is not a valid choice.\n\n".colorize(:red) + end + puts colors("------------------------------------------------------------") + sleep 1 + end +end +puts "Welcome to ...\n\n" +sleep 0.5 +puts colors(" ▀▄ ▄▀ ▀▄ ▄▀ ▀▄ ▄▀ ▀▄ ▄▀") +sleep 0.5 +puts colors(" ▄█▀███▀█▄ ▄█▀███▀█▄ ▄█▀███▀█▄ ▄█▀███▀█▄") +sleep 0.6 +puts colors(" █▀███████▀█ ▀▀███▀▀███▀▀ █▀███████▀█ █▀███████▀█") +sleep 0.7 +puts colors(" ▀ ▀▄▄ ▄▄▀ ▀ ▀█▄ ▄█▀ ▀▄ ▄▀ ▀ ▀▄▄ ▄▄▀ ▀ <3") +puts "\n\n" +space_title = RubyFiglet::Figlet.new "* Solar *\nSYSTEM", 'pebbles' +space_title.show +puts "\n" +main \ No newline at end of file diff --git a/planet.rb b/planet.rb new file mode 100644 index 00000000..3455b091 --- /dev/null +++ b/planet.rb @@ -0,0 +1,25 @@ +require 'faker' +def autofactoid(planet_name) + return ["On #{planet_name}, an atmospheric event called a #{Faker::Games::Pokemon.move} is a rare but spectacular sensory experience causing a thick, soupy #{Faker::Color.color_name} cloud of #{Faker::Coffee.notes}-scented mist to roll over the surface of the planet", + "#{planet_name} was first spotted by an unnamed #{Faker::Military.marines_rank} working for the #{Faker::Space.agency} who originally named it #{Faker::Movies::Hobbit.character} in honor of the office dog. The name was only changed to #{planet_name} in #{rand(1900...1999)}", "#{Faker::GreekPhilosophers.name} famously postulated that #{planet_name} was merely a rumor"].sample +end + +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) + raise ArgumentError.new("Kilograms invalid. Try again.") if mass_kg.to_i <= 0 + raise ArgumentError.new("Kilometers invalid. Try again.") if distance_from_sun_km.to_i <= 0 + @name = name + @color = color + @mass_kg = mass_kg + @distance_from_sun_km = distance_from_sun_km + @fun_fact = autofactoid(name) + end + + def summary + return ("\n#{@name} has a #{@color} color and mass of #{@mass_kg}x10^24 kg." + + "\nIt is #{@distance_from_sun_km}x10^6 km away from the sun." + + "\n\n#{@fun_fact}.\n") + end +end diff --git a/solar_system.rb b/solar_system.rb new file mode 100644 index 00000000..124064e4 --- /dev/null +++ b/solar_system.rb @@ -0,0 +1,31 @@ +class SolarSystem + attr_reader :star_name, :planets + + def initialize(star_name) + @star_name = star_name + @planets = [] + end + + def add_planet(planet) + @planets << planet + end + + def list_planets + planets_string = "\nPlanets orbiting #{@star_name}:\n" + @planets.each_with_index do |planet, i| + planets_string += "#{i+1}. #{planet.name} \n" + end + return planets_string + end + + def find_planet_by_name(query) + matches = @planets.select do |planet| + planet.name == query.capitalize + end + if matches == [] + raise ArgumentError, "Sorry, no planet called #{query} was found.".colorize(:red) + else + return matches[0] + end + end +end \ No newline at end of file