• Post Reply Bookmark Topic Watch Topic
  • New Topic

SimpleDotComTester - Kill condition  RSS feed

 
Prasannakshi Grandhe
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I went through this chap05 in head first java. I have just started to learn java.


I am not sure when i will get numOfHits==Locayioncells.length, to get my kill condition execute. Kindly help me to get understand.

Thanks,
Prasanna



 
Campbell Ritchie
Marshal
Posts: 55793
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isn't that like the game of Battleships, where you have to hit all the squares in a pattern to sink the ship?
 
bhanuprasad reddy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When all the user guesses matches location cells you will get a hit (according to program), but since here you are passing only one guess which is correct you will never get a kill if you execute code written above.

If you need to get a kill then you have to pass 3 guesses which are exactly equal to location cells.

from your program add



below line number 10

or you can add for loop just increment by one to guess if result is hit then increment again else do a decrement and check if its a hit then do one more devrement to guess and you may get a kill. I am not writing code for second option you can try it.
 
Campbell Ritchie
Marshal
Posts: 55793
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...and welcome to the Ranch BR
 
bhanuprasad reddy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!