diff --git a/JacksGame/.DS_Store b/JacksGame/.DS_Store new file mode 100644 index 0000000..e678daa Binary files /dev/null and b/JacksGame/.DS_Store differ diff --git a/JacksGame/controller.rb b/JacksGame/controller.rb new file mode 100644 index 0000000..7a973f9 --- /dev/null +++ b/JacksGame/controller.rb @@ -0,0 +1,41 @@ +require_relative 'view' +require_relative 'model' + +class Control + include GameView + + def run! + Print::title_screen + + loop do + Print::menu + case Print::get_input + when "1" + name = get_input("What's your Grandma's name?") + talk_to_gma(name) + when "2" + Print::show_instructions + when "3" + exit + else + Print::error_message + end + end + end + + def talk_to_gma(name) + grandma = DeafGrandma.new(name) + loop do + phrase = get_input("Say something to Grandma:") + grandma.converse(phrase) + end + end + + def get_input(prompt=nil) + puts prompt if prompt + print "> " + gets.chomp + end +end + +Control.new.run! diff --git a/JacksGame/model.rb b/JacksGame/model.rb new file mode 100644 index 0000000..b1fd4fc --- /dev/null +++ b/JacksGame/model.rb @@ -0,0 +1,46 @@ +class DeafGrandma + attr_reader :age, :name + attr_accessor :asleep, :sleep_count + + def initialize(name) + @name = name + @age = 100 + @asleep = false + @sleep_count = 0 + end + + def converse(input) + + if input.upcase == input + if @asleep + @sleep_count += 1 + if @sleep_count == 3 + @asleep = false + @sleep_count = 0 + puts "*Grandma " + @name + " jolts awake!*" + puts "OH HI THERE SONNY!" + else + puts "*Grandma " + @name + " moves slightly in her sleep*" + end + elsif input == "EAT, GRANDMA!" + puts "MMMM PORIDGE!" + puts "*snores*" + @asleep = true + elsif input == "HOW OLD ARE YOU?" + puts "I'M 100 YEARS OLD SONNY!" + elsif input == "BYE" + puts "SEE YOU SONNY!" + exit + else + puts "NOT SINCE 1964!" + end + else + if @asleep + puts "*Grandma " + @name + " snores loudly*" + else + puts "WHAT WAS THAT SONNY?" + end + end + end +end + diff --git a/JacksGame/view.rb b/JacksGame/view.rb new file mode 100644 index 0000000..d3ccd62 --- /dev/null +++ b/JacksGame/view.rb @@ -0,0 +1,58 @@ +module GameView + + module Print + + class < " + gets.chomp + end + end + end +end