Closed wavesinaroom closed 1 year ago
Board takes ship type, coordinates and orientation to fill cells with that ship id
Ships are always placed left to right for horizontal orientation and bottom top for vertical orientation
I've just come up with a cool way to keep track of ship and shots positions. There's no need using a 10x10 board but logging each move in a map that stores (Shot|ship, coordinates). Coordinates are bound from 0 to 9 otherwise an OutOfBoardBoundaries exception is thrown. Long ships while have as many entries in this map as their length to check if a shot hits any tile the ship is placed on. The idea is promising but I'd like to spend few extra minutes to be sure it's worth trying
I've already implemented the new approach mentioned in my previous comment to log ship as well as placing them on a board with the help of maps. This way is more efficient in terms of avoiding checking a 10x10 grid each time but rendering a list of occupied coordinates
Object coordinates can't be verified easily when they're stored as object inside a map. Strings might be an object but they are hard to increase inside loops. I need to find out how to use strings for implementing coordinates
For now, I managed to convert the coordinate object literal attribute to a single string. I want to do lots of testing to be sure ships placing works alright before going on with missing shots
Gameboards should be able to place ships at specific coordinates by calling the ship factory function.