From b2e9f37fdef59c2a5feef4aa3741f7a5485639c1 Mon Sep 17 00:00:00 2001 From: John Chester Date: Tue, 6 Jun 2017 14:08:55 -0400 Subject: [PATCH] Jack Chester Solutions --- JacksGame/.DS_Store | Bin 0 -> 6148 bytes JacksGame/controller.rb | 41 ++++++++++++++++++++++++++++ JacksGame/model.rb | 46 +++++++++++++++++++++++++++++++ JacksGame/view.rb | 58 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 145 insertions(+) create mode 100644 JacksGame/.DS_Store create mode 100644 JacksGame/controller.rb create mode 100644 JacksGame/model.rb create mode 100644 JacksGame/view.rb diff --git a/JacksGame/.DS_Store b/JacksGame/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..e678daac865f2e71a9ca5ad96082753c656b773e GIT binary patch literal 6148 zcmeHKJxc>Y5PhQo10tlf+|o+0wpl_fQs)nZix$G+L5SL3=Wp>>>YIlEx)kk&|8AY*YY|)|R?+)8h_2Gna&#)oy0Xwoj z`InqE%eLDzZP&0$|Kc_M;?0aB-~>;&=Wfq9RQ>v`+9(-Pfm9$BNCi@Xf35&~w%YX6 zF=Hx_3Zw!b3h4Kt&=qT7?`WS620gy(`b1HUW4lWbOU!Fv@5mLJIF;yBi7SRUo%s@V zHL!PdI>dJ7b7E(S8;aQO%oi(%RL6{|Kq@d);Mk`#?f*CQAMXD{QqEF=RNzl3Ad|&v zG3P5qZymjy_S!;U)Az<&D`yxS0yxoDeEy}b=$Lgiuy-^%^F}A;K|pm$O9g&Ifp;Q3 BDGUGr literal 0 HcmV?d00001 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