BattleShip Game IOS Concept Design Concept

ok, here is the first question with a question, sorry if this is stupid.

I'm just wondering, for playing with a battleship, would it be a waste of memory to create a set of objects for each cell (10X10 = 100), with position (x, y) and state (empty, hit, missed)?

I was wondering if it would be better to create a Grid object and use methods to calculate cell positions when necessary (when processing cell selection using strokes or drawings, for example).

+3
source share
2 answers

The first one is problematic because you can have ships that sit side by side or ends, and it becomes difficult to understand when one is completely destroyed only from the data structures you described. Two hits side by side can be two hits on the same ship, two hits on two different ships or even an immersion on the smallest ship.

Go with the last for the sled.

+2
source

If I did this, I would keep it simple, you have a 2-dimensional array, your set is 10 by 10.

When someone makes a turn, calculate the position and

if it is a miss, insert 0 into this cell of the array; if it is a hit, insert 1 into this cell of the array

+1
source

All Articles