Skip to content

Add the render method with specs and cleans up previous methods.#7

Merged
stackmm merged 1 commit intomainfrom
cell/render
Apr 7, 2023
Merged

Add the render method with specs and cleans up previous methods.#7
stackmm merged 1 commit intomainfrom
cell/render

Conversation

@jcjurado3
Copy link
Copy Markdown
Collaborator

Added the #render method and specs. I needed to update some other methods for the conditional statement in the render method to work. We can refactor if if you have a more efficient way.

end

def empty?
@ship.nil?
Copy link
Copy Markdown
Owner

@stackmm stackmm Apr 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ship.nil? does the same thing as

if @ship == nil 
   true
else
   false
end

(its just a shorter way of writing it!)


def fire_upon
@ship.hit
@fired_upon = true
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I understand why you changed that and added @fired_upon = false to the cell's attributes. One way to clean up the syntax a bit would be to write:

@fired_upon = true 
@ship.hit if !empty?

else
"."
end
end
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can remove all of the "== true" and "== false" to clean up the syntax. Here is how:

if fired_upon? && empty?
  "M"
elsif fired_upon? && @ship.sunk? && !empty?
  "X"
elsif fired_upon? && !empty?
  "H"
elsif !empty? && show_ship
  "S"
else
  "."
end

def render(show_ship = false)
if fired_upon? == true && empty? == true
"M"
elsif fired_upon? == true && @ship.sunk? == true && empty? == false
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't the empty? == false redundant? b/c for a cell to have a sunk ship on it, it cannot be empty

@stackmm
Copy link
Copy Markdown
Owner

stackmm commented Apr 7, 2023

see the few comments I made above (mostly syntax things that will reduce the amount of code by quite a bit). The overall logic of the #render method looks good to me (although I could be wrong, and we will see as we move forward). Gonna go ahead and merge, and i'll make those few changes so we can keep moving

@stackmm stackmm merged commit 9653fcb into main Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants