Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ports -- Kate #35

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
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
94 changes: 94 additions & 0 deletions main.rb
Original file line number Diff line number Diff line change
@@ -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 "<Computer nods respectfully.>"
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
25 changes: 25 additions & 0 deletions planet.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'faker'
def autofactoid(planet_name)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Later on, I would suggest making this a private helper method, which is a concept we'll get to later.

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
31 changes: 31 additions & 0 deletions solar_system.rb
Original file line number Diff line number Diff line change
@@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest also capitalizing planet.name.

end
if matches == []
raise ArgumentError, "Sorry, no planet called #{query} was found.".colorize(:red)
else
return matches[0]
end
end
end