|OK ... first off, to play battleships you need at least two boards: one with your ships on, one with his.
So write your methods with that in mind! If you don't, when you come to add the second board, you have to mess around with the existing, tested, working code to get it to work with extra boards. And remember, on the "hardware" version of the game, you have a total of four boards: Your ships / his hits, your hits his ships; and the same pair for him.
Guilty Gadgets Battleships Sea Battle Traditional Family Fun Combat Strategy Board Game : Amazon.co.uk: Toys & Games[^]
While you can do it with just the one, it's a clumsy solution that only saves about
10 * 10 * 4 * 3 bytes and makes your code a lot clumsier.
And don't declare methods inside other methods: it makes the code clumsy and hard to read.
I'd start with a class: give it a board area, and add the
CheckGuess method to that. Then create four instances of the class in your
public class BattleshipsBoard
private Square[,] TheBoard = new Square[10, 10];
public Square CheckGuess(int x, int y)
public static void Main(string args)
BattleshipsBoard myShips = new BattleshipsBoard();
BattleshipsBoard hisShips = new BattleshipsBoard();
BattleshipsBoard myGuesses = new BattleshipsBoard();
BattleshipsBoard hisGuesses = new BattleshipsBoard();
...Now all the boards are independant and you can query any of them the same way:
if (myShips.CheckGuess(hisX, hisY) == Square.Ship)
if (hisShips.CheckGuess(myX, myY) == Square.Ship)
...Your code becomes more readable, and easier to work with.
Give it a try!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!