Drewbie345/BattleShip2 — pull request #2 by KaoruDev (2014-03-02 20:52:14+00:00)
Title: Minor tweeks for battleship

Sorry I have my settings in sublime to delete white space, which is why you see all those empty removals.

I think you're having a difficult time figuring out how to delegate functionality/responsibility I.e. which objects should know about what.

I made this simple graph which I hope will clear some things up:
https://coggle.it/diagram/53138f279032fdef7d0172b0/170c8ee846a1d193da0e98f6e11e45d0667a5a64b99bb44695de3d1af49570e6

Basically you should limit what an object is responsible for. This is one of the great benefits of OOP ( object oriented programing ), abstraction i believe?

Game
- who won?
Grid
- Remaining ships
- list of blocks
Ship
- should only care if they are not sunk or sunk (and drag event, which you have)
One grid block
- should only care if it is a hit, miss, empty or if there is a ship on it

The reason behind this is 1) it will make your code clearer to read and 2) you'll have less coupling, i.e. you can take pieces of your code out switch them out for another piece. For instance if you wanted to use d3 instead of snap.js.io the only part of the code you would have to change would be the part that draws each grid block, instead of everything. I can explain this to you in person if it doesn't make sense.

Keep on hackin!