Design A Battleship Game Problem Java
posted 6 years ago Number of slices to send: Optional 'thank-you' note:
Hello guys, just having a bit of a problem with this code.
I'm trying to make the battleship game from the headfirst java book without reading the code. I figure I'll learn more if I create the program from the requirements they set out for the simple game, and then compare it afterwards.
The problem I'm having is in the BattleShipsGame/ship class. When a ship is created the BattleShipsGame class passes its initial position and the direction its facing (which in this simple game is always east because there is only one row). The ship class then takes the initial position and adds its additional coordinates into an array using the 'assignCoordinates' method. The BattleShipsGame class should then use a loop to compare each value in this array to the guess of the player class.
I understand that some of this code is a bit iffy (for example the commented out while loop asking for a player guess should be outside the if/else block), but its not passing back what I expect it to. In fact its passing the starting value in the array, and the end value. And I can't work out why!!!
Can anyone see where I've gone wrong? I think I've confused myself slightly!!
Thanks, Nick
PS: any comments on the design of the classes would be appreciated too. I think I've got the attributes and methods sorted in terms of "cross smells" - or however the term was described!!
Design A Battleship Game Problem Java
Source: https://coderanch.com/t/643986/java/basic-battleships-game-headfirst-java
Posted by: leewhost1949.blogspot.com

0 Response to "Design A Battleship Game Problem Java"
Post a Comment