I have been working on the Battleship project diligently. Without two requests for help to the msdn vb.net forum and a suggested approach from Alfred Thompson I would have been dead in the water. It is interesting to take on a program like this. I have been teaching Small Basic for the last few years and the programs have been fairly sedate. Usually the kids build Pong or Tic-Tac-Toe which are fairly simple. The VB I have been teaching has been almost strictly out of the book so it was a very cook book approach and I also did some simple graphics exercises that force the kids to think procedurally but do not require a lot of fancy coding. This Battleship program has required me to really challenge my VB coding and program design skills. Since my formal VB training is absolutely nil I have had to rely on a couple of text books and lots of trial and error. One of the draw backs with programming in SB is there is no need to understand the passing of parameters, it does not do it. VB on the other hand is big on parameter passing.
My game is a two player game, not against the computer. I did not want to deal with working out a computer play procedure that was logical and not just purely random. One way to program a two player game is to duplicate a lot of the procedures, one for player 1 and another for player 2. After all there are going to be two ship arrays, two game boards, two hit arrays and so on. This simply rubbed me the wrong way. I am one of those guys that if I see two procedures in a program that look alike, I have to figure some way to get rid of one. He with the shortest program wins. Thus parameter passing. Not something I am intimately familiar with. I should have started a project like this years ago just for the knowledge being gained. Learning something one day and teaching it the next is not a good strategy. But is does keep me off the streets at night.
When I originally started this project I thought Battleship would be a fairly easy game to work up the logic for and to program. Surprise! There are all sorts of little details that need to be considered; things like the ships are placed either horizontally or vertically and pieces of the ship are in adjacent cells. This is not trivial in the code; in fact I am presently ignoring this little detail because I think it is going to be a pain to code. I have reached the point where I can place ships and shoot ships. No player turns, score tracking or winning yet. I am having way too much fun with this project. I just hope I do not lose the kids; they are not quite as geeky.