diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..c8c516c2 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Debug Local File", + "type": "Ruby", + "request": "launch", + "cwd": "${workspaceRoot}", + "program": "${file}" + } + ] +} \ No newline at end of file diff --git a/main.rb b/main.rb new file mode 100644 index 00000000..75a5d07a --- /dev/null +++ b/main.rb @@ -0,0 +1,84 @@ +require_relative "planet" +require_relative "solar_system" +require "awesome_print" + +def main + #... making default planets in list... + venus = Planet.new(name: "Venus", color: "purple", mass_kg: "3.88e10", distance_from_sun_km: "1.3e8", fun_fact: "this planet is commonly associated with feminine energy.") + + earth = Planet.new(name: "Earth", color: "blue-green", mass_kg: "5.972e24", distance_from_sun_km: "1.496e8", fun_fact: "Only planet known to support life") + + pluto = Planet.new(name: "Pluto", color: "icy-grey", mass_kg: "0.887e10", distance_from_sun_km: "15.3999e8", fun_fact: "Pluto was recently debunked from the official planet list!") + + #instantiate my new solar system named sol + sol_system = SolarSystem.new("Sol") + + # adding planets to sol_sytem with add_planet method in solar_system.rb + sol_system.add_planet(venus) + sol_system.add_planet(pluto) + sol_system.add_planet(earth) + + # list = sol_system.list_planets + + print "Hello and welcome to the \'#{sol_system.star_name}\' solar system." + puts "\n + - If you would like to see a list of planets enter \'list\' or \'l\'. + - If you would like to learn more about an existing planet, enter 'summary'. + - If you would like to create a planet, enter 'generate', or 'add'. + - Finally at any point if you want to abort the mission enter: exit or quit." + + running = true + loop_count = 0 + + # planet_ask = "earth" + # i = 0 + # while i < sol_system.list_planets.length + # if sol_system.list_planets[i].name == planet ask + # puts sol_system.list_planets[i].name + # end + # i += 1 + # # end + + # find_planet = sol_system.find_planet_by_name(planet_ask) + # puts find_planet[0].summary + # end + + while running + if loop_count > 0 + t = Terminal::Table.new + puts "Your options are:" + t << ["summary", "list", "l", "add", "generate", "exit", "quit"] + puts t + end + print "Input here: " + planet_ask = gets.chomp.downcase + #currently will only print out last valuse + if running + if planet_ask == "summary" + puts "Enter name of planet" + planet_name = gets.chomp.downcase + find_planet = sol_system.find_planet_by_name(planet_name) + puts find_planet.summary + elsif ["list", "l"].include?(planet_ask) + puts "Planets orbiting #{sol_system.star_name}" + i = 0 + sol_system.list_planets.each { |n| ap "#{i += 1}. #{n.name}" } + elsif planet_ask == "generate" || planet_ask == "add" + sol_system.user_adds_planet + elsif ["exit", "quit", "n"].include?(planet_ask) + puts "mission aborted!" + break + end + end + loop_count += 1 + puts "Would you like to perform another inquiry? enter y/n" + question = gets.chomp + if question == "y" + running = true + else + running = false + end + end +end + +main diff --git a/planet.rb b/planet.rb new file mode 100644 index 00000000..1f126bee --- /dev/null +++ b/planet.rb @@ -0,0 +1,26 @@ +# wave 1 +require "pry" +require "colorize" +require "terminal-table" + +class Planet + attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact + + def initialize(name: "Planet", color: "Color", mass_kg: "Mass in Kg", distance_from_sun_km: "Distance in km", fun_fact: "This is a fun fact") + @name = name + @color = color + @mass_kg = mass_kg + @distance_from_sun_km = distance_from_sun_km + @fun_fact = fun_fact + @summary = summary + return summary + end + + def summary + table = Terminal::Table.new :headings => ["Name", "Color", "Mass", "Distance", "Fun fact"] + table.add_row [@name, @color, @mass_kg, @distance_from_sun_km, @fun_fact] + + return table + # return "The planet #{self.name} is #{self.color} in color, has a mass of #{self.mass_kg}kg, and is #{self.distance_from_sun_km}km from the sun. A fun fact about your planet: #{self.fun_fact}" + end +end diff --git a/solar_system.rb b/solar_system.rb new file mode 100644 index 00000000..eb82fcf3 --- /dev/null +++ b/solar_system.rb @@ -0,0 +1,52 @@ +require_relative "planet" + +class SolarSystem + #helper method to create readable but not re-writable instance variable. specified using symbols + attr_reader :star_name, :planets + + # constructor method + def initialize(star_name) + @star_name = star_name + @planets = [] + end + + def add_planet(planet) + @planets << planet + end + + def list_planets + n = 0 + listing = @planets.each do |planet| + "#{n += 1}. #{planet.name}" + end + return listing + end + + def user_adds_planet + puts "Please enter the details of your new planet: " + print "Name: " + new_name = gets.chomp.downcase + print "Color: " + new_color = gets.chomp + print "Mass in kg: " + mass = gets.chomp + print "Distance from #{star_name}: " + distance = gets.chomp + print "Cool facts about your planet: " + fun_deets = gets.chomp + new_planet = Planet.new(name: new_name, color: new_color, mass_kg: mass, distance_from_sun_km: distance, fun_fact: fun_deets) + add_planet(new_planet) + puts "#{new_planet.name} has been added to Sol system" + return new_planet + end + + def find_planet_by_name(name_query) + not_found = false + + query = @planets.find { |element| element.name.downcase == name_query.downcase } + # if !not_found + # raise ArgumentError, "This planet ain't here!" + # end + return query #an array of elements... + end +end