[PROPOSAL] Battleships

Tekno Venus

Senior Administrator, Developer
Staff member
Joined
Jul 21, 2012
Posts
7,274
Location
UK
I've been working on a battleships game in VB.NET. This is probably the biggest project I've done in VB.NET.

I'm only really using VB.NET because that is what I have to use for my exams so I may as well be as comfortable with it as I can.

The game currently allows you to place battleships and then attack against the computer. The AI is very, very primitive with a basic hunt/target algorithm: Battleship

Current plans for the program include adding the ability to rotate ships and AI improvements.

I know the code isn't fantastic, which is why I'm asking for feedback and comments - both good and bad.

Thanks!

-Stephen
 

Attachments

In terms of how it plays - it's great! It was a really good fun game to play actually, no bugs and a very good AI. I won by two squares - we had both locked onto the final ship, but mine was shorter than the one the AI needed to take out so I won :p


In terms of the code, I haven't got the time right now to look at it in depth. The only thing I would say from first glance is spacing. Some people like highly compressed code to fit as much onto the screen as possible. My personal preference is to place whitespace to break up logically disjoint pieces of code, breaking each method down into little chunks. I personally think this is especially important in VB which does not feature curly braces. It's very much a personal opinion, but for me your code is all too squashed together to see what does what. If you were to break apart even just the Console.WriteLines from the if statements, then break apart large If/ElseIf/End If and large loops, I think that would help a lot.

Still though, it is an excellent program! Very well done :)
 
Stupid game player...

c8MSjD6.png


Yes, my last move was a miss... I couldn't find the two and ended up spamming loads of coordinates, didn't even realise I hit it :lol:

Really nice program though Stephen, great job! I can't comment on the code as my VB is awful but I agree with Richard on readability though.
 
Glad you all enjoyed playing it! :)

I think I agree with readability. Whilst I do like my code fairly compact, I think I did over-compact a few areas. I am also planning to split the AI into its own file for neatness and ease of maintaining.
 
Not bad Stephen. You might be curious to look at how I allow the user to control the position of the caret within the console in my TicTacToe game to further improve this :)
AceInfinity Dev - TicTacToe Game

Might be a lot easier than having to type in 'A7', 'C2', etc...

edit: A few other pointers:
Code:
ByVal gridType As Integer

Perhaps an enum would be a bit more verbose in cases like this :)

Code:
Public alphabet() As Char = {"A"c, "B"c, "C"c, "D"c, "E"c, "F"c, "G"c, "H"c, "I"c, "J"c}

This can just be a string. strings and char arrays are very similar.

Last thing I would suggest is to make your functions take parameters. Right now you have to change the function itself if you want it to do a variation of what it's meant to do, there's no genericness in having functions that take 0 parameters and all parameters are hardcoded within that function.
 
Last edited:

Has Sysnative Forums helped you? Please consider donating to help us support the site!

Back
Top