wavesinaroom / my_odin_project_battleship

0 stars 0 forks source link

Gameboard receiveAttack function #5

Closed wavesinaroom closed 1 year ago

wavesinaroom commented 1 year ago

Gameboards should have a receiveAttack function that takes a pair of coordinates, determines whether or not the attack hit a ship and then sends the ‘hit’ function to the correct ship, or records the coordinates of the missed shot.

wavesinaroom commented 1 year ago

For some reason grabbing 4,4 coordinate ship hitPoints in gameboard.test.js is impossible, code in gameboard.js logs the expected values though.

wavesinaroom commented 1 year ago

Couldn't create a test for confirming checkpoints but console.log tells they're are increased when a ship is hit. Not the best thing to do but need to move forward

wavesinaroom commented 1 year ago

To remove a ship means looking for it in shipsLog map as well as in tiles map. Their key value order is swapped which hinders ship deletion in probably 2 lines of code. Tiles map has coordinate ship ship.ID key value assignment since it's best for checking/entering enemy's shots. On the other hand shipsLogs key value assignment is ship.ID, ship since there's only one entry for each ship and it makes more sense to have ships id as keys

wavesinaroom commented 1 year ago

There's gonna be an important change in the gameboard factory function. Map will go away, instead I'm gonna use an object called tile that contains coordinate and ship within. Tiles on their own will not be a map but an array of tile objects whereas shipsLog will be an array of ship object. Tile objects will be flexible to seach as they can be found either with coordinates or ships.ID property

wavesinaroom commented 1 year ago

Actually, tile objects will include missing shots that are stored as undefined in the tile object property

wavesinaroom commented 1 year ago

I feel I can get rid of shipsLog array, tiles' already got copies of ships in it. I'll think through this for a moment

wavesinaroom commented 1 year ago

Tiles map into array of tile objects change is done. I'll complete the removeShip method before changing the gameboard.test.js file to perform thorough tests

wavesinaroom commented 1 year ago

I've already rebuilt ship placement tests. Working on shots test now

wavesinaroom commented 1 year ago

Something really strange happened with testing a sinking ship. For some reason I can't get access to the ship by its ID after Hits a ship tests. It's got me stuck whole morning and I need to move on with players. My guts tell me to trust isSunk boolean will be true. While writing this log I found out that maybe the ship is already sunk and deleted