• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Trying to create a Battleship program

 
Andy Hammersmith
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my computer class, we were given the task to create a program that will run a 10 x 10 battleship board, using 1-10 vertically and A-J horizontally. I was absent when he explain what to do for the program and have not been told on what to use to create this. I would appreciated suggestions on how to:

• How to create the board so it is easy to read, and not overly complex.
(Everything that I have been able to come up with is to complex to recreate)
• What kind of array would be best to use to create the board yo keep track of where the ships are, and what spaces have been taken.
• How do you check the array the figure what is there.

I am so confused on how to go about this, so any advice would be appreciated.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the first thing to do is go back to your professor and ask him for the details that you missed. Anything he says would be valuable information about what tools and capabilities you are expected to use, and therefor give a hint about the type of solution he expects.

The next thing to do is take out a pencil and pad of paper. Write out the requirements. Then pick a requirement and write it out in detail - exactly what is required to achieve the requirement - in English (or your native tongue). Break it down into sub-tasks, and then steps. Try to be as specific as possible.

Then repeat the above for each of the requirements in the application. Before you write code you should have a pretty concise outline of everything you plan to do. Then you pick one task in one requirement and translate it to code - compile it, make sure it runs. Then progress to the next step. The simpler the steps you make the easier it is to get started, the better direction you will have and the sooner you will finish. But the key is analizing the problem up front and making sure you have a plan before you start to code.
 
Andy Hammersmith
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I shall try the second option, but sadly my teacher refuse to give me anymore details on it, so I'm kinda stuck on that part.
And thank you very much for your advice.
 
Winston Gutkowski
Bartender
Pie
Posts: 10509
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andy Hammersmith wrote:I shall try the second option, but sadly my teacher refuse to give me anymore details on it, so I'm kinda stuck on that part.
And thank you very much for your advice.

Another tip for you: try and separate the game from it's display as much as you possibly can.

I'd suggest that you get it working just using console input and output first, even it it looks a bit clunky; and only add Swing code (if that's a requirement) after you know that the game part works.

And even then, try to keep your Swing code completely separate from your game logic.

What kind of array would be best to use to create the board yo keep track of where the ships are, and what spaces have been taken.

Well, I assume you're familiar with how to create a 2D array or grid. My advice would be to create a small class called Square or Position and allow it to contain a Ship (or not), and then set up a grid of those. You might also find it useful if each Square knows its own position (but it's not essential), and a useful class for storing 2D positions is Point.

HIH

Winston
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic