diff --git a/Eriks-Game/controller.rb b/Eriks-Game/controller.rb new file mode 100644 index 0000000..e260f54 --- /dev/null +++ b/Eriks-Game/controller.rb @@ -0,0 +1,40 @@ +require_relative 'view' +require_relative 'model' + +class WallController + include WallView + + def run! + wall = Wall.new + drinker = Drinker.new + + Print::run_spinner + Print::title_screen + + loop do + Print::menu + case Print::fetch_user_input + when "c" + Print::count_bottles(wall.bottles) + when "a" + wall.add_bottle(Print::serialize_bottle) + when "d" + if wall.empty? + Print::empty_message + exit + end + wall.drink_bottle(Print::drink_id(wall.bottles).to_i, drinker) + if drinker.drunk? + Print::drunk_message + end + when "q" + puts "Goodbye!" + exit + else + Print::error_message + end + end + end +end + +WallController.new.run! diff --git a/Eriks-Game/model.rb b/Eriks-Game/model.rb new file mode 100644 index 0000000..0c6f2bf --- /dev/null +++ b/Eriks-Game/model.rb @@ -0,0 +1,63 @@ +require 'faker' +require 'pry' + +class Bottle + attr_reader :id, :title, :description, :completed + + def initialize args + @id = args[:id] + @title = args[:title] + @description = args[:description] + end +end + +class Wall + attr_reader :bottles + + def initialize + @primary_id = 0 + @bottles = [] + populate_dummy_bottles + end + + def add_bottle(input) + @bottles << Bottle.new(input.merge(fetch_id)) + end + + def drink_bottle(bottleId, drinker) + @bottles.delete_if { |n| n.id == bottleId } + drinker.drink() + end + + def populate_dummy_bottles + 5.times do + add_bottle(title: Faker::Lorem.word, description: Faker::Lorem.sentence) + end + end + + def empty? + @bottles.count == 0 + end + + private + + def fetch_id + {id: @primary_id += 1 } + end +end + +class Drinker + attr_reader :intoxication + + def initialize + @intoxication = 0 + end + + def drink + @intoxication += 1 + end + + def drunk? + @intoxication > 3 + end +end diff --git a/Eriks-Game/view.rb b/Eriks-Game/view.rb new file mode 100644 index 0000000..6e882bb --- /dev/null +++ b/Eriks-Game/view.rb @@ -0,0 +1,83 @@ +module WallView + + module Print + + class << self + def run_spinner + print "Ubering to the bar (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.downcase + end + + def drunk_message + puts "Don't get too intoxicated!" + end + + def empty_message + puts "Sorry, time to head home. The wall is empty" + end + end + end +end