-
Notifications
You must be signed in to change notification settings - Fork 9
Great improvement. couple of questions #6
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
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 |
|---|---|---|
|
|
@@ -7,15 +7,49 @@ def fire_upon_target | |
| @battleship.fire! | ||
| end | ||
|
|
||
| def has_battleship | ||
| battleship = Battleship.new | ||
| end | ||
| end | ||
|
|
||
| class Battleship | ||
| attr_reader :ammunition | ||
| attr_reader :ammunition, :request | ||
| def initialize | ||
| @ammunition = 100 | ||
| @ammunition = 10 | ||
| @request = request | ||
| end | ||
|
|
||
| def fire! | ||
| @ammunition = @ammunition - 1 | ||
| end | ||
|
|
||
| def request | ||
| true | ||
| end | ||
|
|
||
| def more_ammunition | ||
| true | ||
| end | ||
|
|
||
| def verify | ||
| if "hit" | ||
|
Member
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. This will always be a hit, right? What are you trying to do?
Author
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. My goals is to pass in something equal to either a "hit" or "miss" my problem is that i do not know what that something is yet
Member
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. In order to really tell if you hit something, you'd need a board with positions of ships. And, you'd have to give the "fire" a target. Very out of scope for this lesson. Instead, if you just need a reason, just random number if rand > 0.5
:hit
else
:miss
end |
||
| "hit" | ||
| else | ||
| "miss" | ||
| end | ||
| end | ||
| end | ||
|
|
||
| class Fate | ||
| attr_reader :ammunition | ||
|
|
||
| def initalize | ||
| @hit = hit | ||
| @miss = miss | ||
| end | ||
|
|
||
| def outcome | ||
| [:hit, :miss].sample | ||
| 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.
you have a method
requestand anattr_readerrequest. why? and do you understand why you can't do that?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.
Oh that is a mistake. I made the "request" method to assign the value true. Although, I do not really know why doing both is not a good idea
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.
Here's a reason why that's no good. The
def tempoverrides the attr_accessor http://rubyfiddle.com/riddles/f1f85