Skip to content
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
31 changes: 31 additions & 0 deletions Victorias-Game/controller.rb
Original file line number Diff line number Diff line change
@@ -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!
56 changes: 56 additions & 0 deletions Victorias-Game/model.rb
Original file line number Diff line number Diff line change
@@ -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
78 changes: 78 additions & 0 deletions Victorias-Game/view.rb
Original file line number Diff line number Diff line change
@@ -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 = <<TITLE

----------||----------
| Crazy Cats |
----------||----------

TITLE
puts title
end

def menu
menu = <<EOS

----- Welcome -----
- (V)iew your Cats
- (A)dd a Cats
- (F)eed a Cat
- (S)ell a Cat
- (Q)uit program
-------------------
EOS
puts menu
end

def print_list(cats)
cats.each do |cat|
if cat.fed?
puts "[X] #{cat.id} || #{cat.title} - #{cat.description}"
else
puts "[ ] #{cat.id} || #{cat.title} - #{cat.description}"
end
end
end

def serialize_cat
{}.tap do |obj|
["\nEnter the title:", "\nEnter the description:"].each do |t|
if obj.empty?
obj[:title] = fetch_user_input(t)
else
obj[:description] = fetch_user_input(t)
end
end
end
end

def sell_id
gimme_id = "\nEnter the id of cat item you want to SELL:"
fetch_user_input(gimme_id)
end

def feed_id
gimme_id = "\nEnter the id of cat item you want to mark as FEED:"
fetch_user_input(gimme_id)
end

def fetch_user_input(question=nil)
puts question if question
print "> "
gets.chomp
end
end
end
end