forked from AdaGold/solar-system
-
Notifications
You must be signed in to change notification settings - Fork 48
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
goblineer
wants to merge
9
commits into
Ada-C11:master
Choose a base branch
from
goblineer:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Ports -- Kate #35
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f42247b
Creates a class for planets
goblineer d5134b3
Sets up for a driver program
goblineer cd4521f
adds to method (solar system)
goblineer 541d130
Solar_System class functionality
goblineer 2dd1f2d
Well, I broke it. CLI and busted methods.
goblineer 0977865
Refactored and working driver
goblineer fb22281
Sorted and working methods
goblineer 0044bb8
Fully automated factoids
goblineer 974d8a0
Made double sure it wasn't broken.
goblineer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest also capitalizing |
||
end | ||
if matches == [] | ||
raise ArgumentError, "Sorry, no planet called #{query} was found.".colorize(:red) | ||
else | ||
return matches[0] | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.