diff --git a/main.rb b/main.rb new file mode 100644 index 00000000..4055b9d1 --- /dev/null +++ b/main.rb @@ -0,0 +1,87 @@ +require_relative 'planet' +require_relative 'solar_system' +require 'colorize' +require 'colorized_string' + +def main + + #Create a solar system, planets, and add them to the planets array in the solar system + solar_system = SolarSystem.new("luna") + + koopa_troopa_town = Planet.new("koopa troopa town","red and green", 6.972e24, 1.283e7, "It takes a while for inhabitants to come out of their shell.") + solar_system.add_planet(koopa_troopa_town) + + yoshi_land = Planet.new("yoshi land", "green", 2, 1.5, "My full planet name is T. Yoshisaur Munchakoopas" ) + solar_system.add_planet(yoshi_land) + + mario_world = Planet.new("mario world", "red", 5.432e56, 100000, "You'll find that everything here is super!") + solar_system.add_planet(mario_world) + + earth = Planet.new("earth", "blue-green",6.972e24,1.283e7,"I live on it") + solar_system.add_planet(earth) + + bowserville = Planet.new("bowserville", "orange, red, and green", 100000000e34, 60000, "Bwa ha ha ha!" ) + solar_system.add_planet(bowserville) + + luigi_lagoon = Planet.new("luigi lagoon", "green", 343439, 232939, "Luigi TIme!!") + solar_system.add_planet(luigi_lagoon) + + princess_peach_paradise = Planet.new("princess peach paradise", "peach", 34342, 45645, "Peachy!") + solar_system.add_planet(princess_peach_paradise) + + + + #Control loop that repeatedly asks user what to do next + # Only way to exit program is to type 'exit' + repeat = true + until repeat == false + puts + puts "*" * 50 + puts "Marioooo time! What would you like to do next?\nYou can:\n".colorize(:light_green) + puts "1. See a list of planets by typing 'list'\n" + puts "2. View planet details of your favorite planet by typing 'details'\n" + puts "3. Add a planet to the Mario Universe collection by typing 'add'\n" + puts "4. Exit the program by typing 'exit'\n\n" + puts "Waiting for your input.... " + input = gets.chomp + + case + when input == "list" + list = solar_system.list_planets + puts list + when input == "details" + puts "What planet are you interested in learning more about?" + input = gets.chomp.to_s + summary = solar_system.find_planet_by_name(input) + puts summary + when input == "add" + solar_system.add_new_planet + puts "Let's see your new planet!" + when input == "exit" + exit + else + puts "\nInvalid Entry. Please read the instructions carefully and retype your answer.".upcase.colorize(:red) + end + end +end + +main + + + + + + + + + + + + + + +# main +# + +# end +# main \ No newline at end of file diff --git a/planet.rb b/planet.rb new file mode 100644 index 00000000..a5d01c29 --- /dev/null +++ b/planet.rb @@ -0,0 +1,21 @@ +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 + raise ArgumentError, 'Mass must be greater than 0.' if mass_kg < 0 + @distance_from_sun_km = distance_from_sun_km + raise ArgumentError, 'Distance from sun must be greater than 0.' if distance_from_sun_km < 0 + @fun_fact = fun_fact + end + + def summary + summary = "\n Name: #{@name}\n Color: #{@color}\n Mass: #{@mass_kg}\n Distance from the Sun:#{@distance_from_sun_km}\n Fun Fact: #{@fun_fact}\n\n".colorize(:green) + return summary + end + +end + diff --git a/planet_test.rb b/planet_test.rb new file mode 100644 index 00000000..ac456b09 --- /dev/null +++ b/planet_test.rb @@ -0,0 +1,39 @@ +require 'minitest/autorun' +require 'minitest/reporters' +require_relative 'planet' +require 'colorize' +require 'colorized_string' + +Minitest::Reporters.use! + +describe "planet" do + + it "will return a string" do + + #Arrange + earth = Planet.new("earth", "blue-green",5,2,"I live on it") + + #Act + puts earth.summary + + #Assert + expect(earth.summary).must_be_instance_of String + end + + it "will raise an error if mass_kg is less than 0" do + + #Assert + expect { + Planet.new("earth", "blue-green",-5,2,"I live on it") + }.must_raise ArgumentError + end + + it "will raise an error if distance_from_sun_km is less than 0" do + #Assert + expect { + Planet.new("earth", "blue-green",5,-2,"I live on it") + }.must_raise ArgumentError + + end + +end \ No newline at end of file diff --git a/solar_system.rb b/solar_system.rb new file mode 100644 index 00000000..b6d76b46 --- /dev/null +++ b/solar_system.rb @@ -0,0 +1,57 @@ +require_relative 'planet' +require 'colorize' +require 'colorized_string' + +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 + list = "\nPlanets orbiting #{star_name}:\n".colorize(:green) + @planets.each_with_index do |planet, index| + index += 1 + list += "#{index}. #{planet.name}\n" + end + return list + end + + def find_planet_by_name(input_name) + @planets.each do |single_planet| + return single_planet.summary if single_planet.name.downcase == input_name.downcase + end + return "\nSorry,this planet is in the process of being created many light years away and cannot be located just yet.".upcase.colorize(:red) + end + + #Add argument error to mass and distance input since they are not going through the initialize function + def add_new_planet + puts "It's a-me, Mario! Add some information about your new planet:" + puts "name:" + new_name = gets.chomp + puts "color:" + new_color = gets.chomp + puts "mass_kg (integer only - do not spell out number):" + new_mass = gets.chomp.to_i + if new_mass < 1 + raise ArgumentError, 'Mass must be an integer and it must be greater than 0.'.colorize(:yellow) + end + puts "distance from sun (integer only - do not spell out number):" + new_distance = gets.chomp.to_i + if new_distance < 1 + raise ArgumentError, "Distance from sun must be greater than 0.".colorize(:yellow) + end + puts "What is your fun-a fact?" + new_fun_fact = gets.chomp + + new_name = Planet.new(new_name,new_color,new_mass,new_distance,new_fun_fact) + add_planet(new_name) + end +end