Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Im new to java, stuck in simple Battleship game  RSS feed

 
John Montans
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so I started with java not too long ago, and I have to make a battleship game where the user has to enter the length and width of the table, then enter the ships (they only occupy 1 spot) and then play, plus turning off the pc and checking the climate. the table must be shown at least once abter the user entered the coordinates for the ships, and every time the user makes a move.
Now, Ive run into a couple problems, First: when the game starts, I want it to clean the table so it only shows water, but I want it to remember that a ship is there, and Seccond: when a person misses the table (say the array was a [6][6] and the user types (7;7) as coordenates, I want it to say the user missed the table.
I cant use more advanced codes, since this is a project for class.
here is my code:

 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When posting code please surround them with Code tags. I've added them for you this time.
 
John Montans
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:When posting code please surround them with Code tags. I've added them for you this time.


many thanks, I saw it in other posts and wanst sure how to add them :p
 
John Montans
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I fixed my program, it isnt pretty, but itll do:
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why have you put so much code in the main method?
Why are you using the short datatype? Use ints for whole numbers, unless they are going to be large.
Why are you using numbers for variables like juegoNuevo?
 
John Montans
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Why have you put so much code in the main method?
Why are you using the short datatype? Use ints for whole numbers, unless they are going to be large.
Why are you using numbers for variables like juegoNuevo?


for the first one, since its for class, we are only allowed to use what we learnt in class, so we are not allowed to use many ones -.-

For the rest, It was a 2 man project, my mate had to catch up and he decided to start the project, thats why we have diferent variables and weird ones :p

but thanks for the feedback Its great to have it on my first program!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!