Hello. I'm going to write Battleship for Android and now I started, as a rule, with logic. Please see if I reason correctly. Multiplayer Play on one device.

The placement of ships is reduced to the creation of two ArrayList , one for ships, the other for cells (with an embedded ArrayList ), namely:

Create class Ship for ship. The designer passes the number of its decks and the indices of its cells. The class is shotCounter - counter shotCounter . The shot method is implemented in which this counter is incremented. The method changes the state of the cells to KILL and returns true if the ship is completely sunk and false , if only damaged. When placing ships, a List is created from the Ship classes. Moreover, each cell belonging to the ship is given the index of this ship from the List . This ensures the mutual communication of the ship with its cells.

I create class Cell for a cell of a game field. The class has two constructors. The first is transmitted, as described above, the index of the ship from the List , to which the cell belongs. The class will contain a variable with the ship index, a logical variable IS_EMPTY if the cell does not belong to any ship and the state of the cell ( MISS is a miss, HIT is hit and KILL is sunk. In the second, nothing is transmitted. In this logic variable IS_ЕMPTY to true . In the Cell class, a shot method with no input parameters will be written with the following logic. If IS_ЕМPTY contains true , then change the state of the cell to MISS (miss.) Otherwise, refer to the corresponding Ship class, calling its shot method. If it returns false , then change the state cell at HIT . Ec and true , it means that the ship hit in full and should automatically change the state near the cell lying on the MISS , as there can not be anything, probably more convenient to do it in the classroom Ship as it will keep the cell of his ship.

I will not describe further, otherwise you don’t want to read. Waiting for critics, can someone find the pitfalls in advance :)

  • I did this: the matrix is ​​butit, where the rub is a busy, a fold is a free cell; one more matrix where hits, trued - a shot, fals - not a shot sector. Overlaying comparing ... - Andrei
  • What about the deck? The game will display the counter remaining - Flippy

0