-
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
Finished MVCgame #21
Open
wesdelp
wants to merge
1
commit into
paircolumbus:master
Choose a base branch
from
wesdelp:wdelp-MVCgame
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Finished MVCgame #21
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require_relative 'view' | ||
require_relative 'model' | ||
|
||
class GameController | ||
include GameView | ||
|
||
def run! | ||
wineList = List.new | ||
|
||
loop do | ||
Print::menu | ||
case Print::fetch_user_input | ||
when "V" | ||
Print::print_list(wineList.wines) | ||
when "A" | ||
wineList.add_wine(Print::serialize_wine) | ||
when "D" | ||
wineList.delete_wine(Print::deleted_name) | ||
when "Q" | ||
puts "We're done" | ||
exit | ||
else | ||
Print::error_message | ||
end | ||
end | ||
end | ||
end | ||
|
||
GameController.new.run! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class Wine | ||
attr_reader :name, :type, :comments, :rating | ||
def initialize args | ||
@name = args[:name] | ||
@type = args[:type] | ||
@comments = args[:comments] | ||
@rating = args[:rating] | ||
end | ||
end | ||
|
||
class List | ||
attr_reader :wines | ||
def initialize | ||
@wines = [] | ||
end | ||
|
||
def add_wine(input) | ||
@wines << Wine.new(input) | ||
end | ||
|
||
def delete_wine(name) | ||
@wines.delete_if { |n| n.name == name } | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
module GameView | ||
|
||
module Print | ||
|
||
class << self | ||
|
||
def error_message | ||
puts "That's not a command key. Try again!" | ||
end | ||
|
||
def menu | ||
menu = <<EOS | ||
|
||
***** Welcome ***** | ||
- (V)iew your wines | ||
- (A)dd a wine | ||
- (D)elete a wine | ||
- (Q)uit program | ||
***** ***** | ||
|
||
EOS | ||
puts menu | ||
end | ||
|
||
#does print_list know too much about the underlying object??? | ||
|
||
def print_list(wines) | ||
wines.each do |wine| | ||
puts "=====================" | ||
puts wine.name | ||
puts "=====================" | ||
puts "Type: #{wine.type}" | ||
puts "Comments: #{wine.comments}" | ||
puts "Rating: #{wine.rating}" | ||
end | ||
end | ||
|
||
def serialize_wine | ||
new_wine = {} | ||
print "\nEnter the name: " | ||
new_wine[:name] = gets.chomp | ||
print "\nEnter the type: " | ||
new_wine[:type] = gets.chomp | ||
print "\nEnter comments: " | ||
new_wine[:comments] = gets.chomp | ||
print "\nEnter a rating (0-10): " | ||
new_wine[:rating] = gets.chomp | ||
return new_wine | ||
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. ruby standard is to omit |
||
end | ||
|
||
def deleted_name | ||
print "\nEnter the name of wine you want to DELETE: " | ||
gets.chomp | ||
end | ||
|
||
def fetch_user_input(question=nil) | ||
puts question if question | ||
print "> " | ||
gets.chomp | ||
end | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What's the reason for these nested modules? Why not just be satisfied with GameView?