Tekno Venus Senior Administrator, Developer Staff member Joined Jul 21, 2012 Posts 7,199 Location UK Jan 21, 2015 #1 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 Battleships_Console.zip 93 KB · Views: 68
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
niemiro Senior Administrator, Windows Update Expert Staff member Joined Mar 2, 2012 Posts 8,772 Location District 12 Jan 21, 2015 #2 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 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 :)
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 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 :)
tom982 Emeritus Joined May 31, 2012 Posts 4,352 Location New York Jan 21, 2015 #3 Stupid game player... 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.
Stupid game player... 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.
Go The Power Senior Administrator, Windows Update Expert, Contributor Staff member Joined Mar 5, 2012 Posts 6,292 Location Adelaide, South Australia Jan 23, 2015 #4 It was fun, thanks for that Stephen. Good work :)
Tekno Venus Senior Administrator, Developer Staff member Joined Jul 21, 2012 Posts 7,199 Location UK Jan 24, 2015 #5 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.
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.
AceInfinity Emeritus, Contributor Joined Feb 21, 2012 Posts 1,728 Location Canada Jan 24, 2015 #6 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: Jan 24, 2015
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.