I am trying to write a battleship game for an assignment. The ships and board size are read through a txt-file and they look like this;
In the code i call a function where I deleted the separators between the coordinates (see listOfxyCoordinates=getXYcoordinates.getXYcoordinatesFromTextFile(line); )
and then I try to store the coordinates.
Before new instances of the shipclass have been made and as you see they consist of a shipType (the name in the file) and the coordinates.
Right after trying to store the list of xycoordinates, the ships are also added to a list.
However when I call readGameOptionsFromTextFile() from another class, the names are all collected,
but the coordinates of the ships have been overwritten.
Only the coordinates of the last ships are still in the list. I tried working with different datatypes where indexing seemed more easy to me, however the List of lists that i use now is more flexible but I just can't figure out
how to store it all effectively.
I suggest you start by removing the word static from your vocabulary, except in the heading for the main() method. A static variable is a recipe for disaster.
Please put some debugging code into your program. Print out the state of your List before and after you alter it:-That will help you see where things are going wrong. If you decide that line 73 isn't at fault, you can comment out the debugging code and delete it all later:-You have some very old‑fashioned code there. Also I think lines 33‑35 are error‑prone. What will happen if your board size is 15?
Don't use two readers for the same file. You only need one.