diff --git a/LoRyder1/controller.rb b/LoRyder1/controller.rb new file mode 100644 index 0000000..52a27d2 --- /dev/null +++ b/LoRyder1/controller.rb @@ -0,0 +1,32 @@ +require_relative 'view' +require_relative 'model' + +class GameController + include GameView + + def run! + animalsZoo = Zoo.new + + Print::run_spinner + Print::title_screen + + loop do + Print::menagerie + case Print::get_user_input + when "A" + Print::print_zoo(animalsZoo.animals) + when "B" + animalsZoo.add_animal(Print::serialize_animal) + when "C" + animalsZoo.export_animal(Print::deleted_id.to_i) + when "D" + puts "Thanks for visiting the Zoo" + exit + else + Print::error_message + end + end + end +end + +GameController.new.run! diff --git a/LoRyder1/model.rb b/LoRyder1/model.rb new file mode 100644 index 0000000..a72e155 --- /dev/null +++ b/LoRyder1/model.rb @@ -0,0 +1,47 @@ +require 'faker' + +class Animal + attr_reader :id, :name, :description, :weight, :dangerous + + def initialize args + @id = args[:id] + @name = args[:name] + @description = args[:description] + @weight = args[:weight] + @dangerous = nil + end +end + +class Zoo + attr_reader :animals + + def initialize + @primary_id = 0 + @animals = [] + import_animals + end + + def add_animal(input) + @animals << Animal.new(input.merge(get_id)) + end + + def sell_animal(id) + @animals.delete_if { |n| n.id == id} + end + + def export_animal(id) + @animals.delete_if { |n| n.id == id } + end + + def import_animals + add_animal(name: "Zebra", description: "part of the horse family with distinctive black and white stripes", weight: 700) + add_animal(name: "Elephant", description: "large mammals, herbivores, and gray", weight: 15000) + add_animal(name: "Lion", description: "big cat, male has mane, carnivore", weight: 440) + end + + private + + def get_id + {id: @primary_id +=1} + end +end \ No newline at end of file diff --git a/LoRyder1/view.rb b/LoRyder1/view.rb new file mode 100644 index 0000000..9384a51 --- /dev/null +++ b/LoRyder1/view.rb @@ -0,0 +1,77 @@ +module GameView + + module Print + class << self + def run_spinner + print "Loading (please wait) " + 3.times { print "."; sleep 1; } + print "\n" + end + + def error_message + puts "That key will not work. Have another go!" + end + + def title_screen + title = <<-EOT + + ============================= + You Bought A Zoo + ============================= + + + EOT + puts title + end + + def menagerie + menagerie = <<-EOS + + === Welcome===== + + - (A) View your animals + - (B) Add a animal + - (C) Export a animal + - (D) Quit program + + ======== + EOS + + puts menagerie + end + + def print_zoo(animals) + animals.each do |animal| + puts "#{animal.id} || #{animal.name} - #{animal.description} - #{animal.weight}lbs" + end + end + + def serialize_animal + {}.tap do |obj| + ["\nEnter the animal name:", "\nEnter the description:", "\nEnter the weight:"].each do |t| + # puts obj.inspect + if obj.empty? + obj[:name] = get_user_input(t) + elsif obj.count == 1 + obj[:description] = get_user_input(t) + else + obj[:weight] = get_user_input(t) + end + end + end + + end + + def deleted_id + the_id = "\nEnter the id of the animal you want to sell" + get_user_input(the_id) + end + + def get_user_input(question=nil) + puts question if question + print "> " + gets.chomp + end + end + end +end \ No newline at end of file