-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jack Chester Solutions #29
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require_relative 'view' | ||
require_relative 'model' | ||
|
||
class Control | ||
include GameView | ||
|
||
def run! | ||
Print::title_screen | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2 spaces :) |
||
|
||
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! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use the reader method? |
||
@sleep_count += 1 | ||
if @sleep_count == 3 | ||
@asleep = false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep in mind that here you're calling the instance variable directly. If you use def asleep
in_bed && tucked_in
end There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be correct to say this is akin to solely using the accessors ( Honestly, it is also a bit nice to not see |
||
@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*" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can also use interpolation over concatenation. http://ruby-for-beginners.rubymonstas.org/bonus/string_interpolation.html |
||
else | ||
puts "WHAT WAS THAT SONNY?" | ||
end | ||
end | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
module GameView | ||
|
||
module Print | ||
|
||
class <<self | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
def error_message | ||
puts "Invalid command, try again!" | ||
end | ||
|
||
def title_screen | ||
title = <<TITLE | ||
|
||
************ || ************** | ||
* Ultimate Grandma Simulator * | ||
************ || ************** | ||
|
||
"Just like the real thing!" | ||
|
||
TITLE | ||
puts title | ||
end | ||
|
||
def menu | ||
menu = <<EOS | ||
|
||
********* Menu ********* | ||
- Say hi to Grandma! (1) | ||
- How to play (2) | ||
- Exit (3) | ||
********* ********* | ||
|
||
EOS | ||
puts menu | ||
end | ||
|
||
def show_instructions | ||
instructions = <<INS | ||
|
||
Talk to Grandma any time you want! Be sure to give her a good name. | ||
|
||
Grandma is a little hard of hearing, so be sure to speak up! | ||
|
||
Make sure Grandma gets the food she needs, tell her "EAT, GRANDMA!" | ||
but watch out, food puts her to sleep! Yell three times to wake her up. | ||
|
||
INS | ||
puts instructions | ||
end | ||
|
||
def get_input(prompt=nil) | ||
puts prompt if prompt | ||
print "> " | ||
gets.chomp | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 spaces.