diff --git a/Victorias-Game/controller.rb b/Victorias-Game/controller.rb new file mode 100644 index 0000000..c8e67f6 --- /dev/null +++ b/Victorias-Game/controller.rb @@ -0,0 +1,31 @@ +require_relative 'view' +require_relative 'model' + +class GameController + include GameView + def run! + catList = List.new + Print::run_spinner + Print::title_screen + + loop do + Print::menu + case Print::fetch_user_input + when "V" + Print::print_list(catList.cats) + when "A" + catList.add_cat(Print::seerialize_cat) + when "F" + catList.feed_cat(Print::fed_id.to_i) + when "S" + catList.sell_cat(Print::sold_id.to_i) + when "Q" + puts "we're Done" + exit + else + Print::error_message + end + end + end +end +GameController.new.run! diff --git a/Victorias-Game/model.rb b/Victorias-Game/model.rb new file mode 100644 index 0000000..21def7c --- /dev/null +++ b/Victorias-Game/model.rb @@ -0,0 +1,56 @@ +require 'faker' +require 'pry' + +class Cat + attr_reader :id, :title, :description, :fed + + def initialize args + @id = args[:id] + @title = args[:title] + @description = args[:description] + @fed = false + end + + def mark_fed + @fed = true + end + + def fed? + @fed + end +end + +class List + attr_reader :cats + + def initialize + @primary_id = 0 + @cats = [] + populate_dummy_cats + end + + def add_cat(input) + @cats << Cat.new(input.mere(fetch_id)) + end + + def feed_cat(id) + feed_item = @cats.seelect { |cat| cat.id == id } + fail "No item matching that id" unless fed_item + fed_item[0].mark_fed + end + + def sell_cat(id) + @cats.sell_if { |n| n.id == id } + end + + def populate_dummy_cats + 5.times do + add_cat(title: Faker::Cat.name, description: Faker::Cat.breed) + end + end + + private + def fetch_id + {id: @primary_id += 1} + end +end diff --git a/Victorias-Game/view.rb b/Victorias-Game/view.rb new file mode 100644 index 0000000..ebf9f4d --- /dev/null +++ b/Victorias-Game/view.rb @@ -0,0 +1,78 @@ +module GameView + module Print + class << self + def run_spinner + print "Loading, Please Wait" + 5.times { print "."; sleep 1; } + print "\n" + end + + def error_message + puts "That's not a command key. Try again." + end + + def title_screen +title = < " + gets.chomp + end + end + end +end