Learn more about bidirectional Unicode characters Show hidden characters. Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. ArrayList ;. Timothy Truckle Timothy Truckle 6, 11 11 silver badges 23 23 bronze badges.
I can not tell I agree with all but I think it is ok to disagree sometimes and I guess there is no specific concrete way. But may you share where you disagree? Maybe I can learn something too? If a board consists of Bombable cells and each bombable is connected to either a reference to a Ship or a NOP, depending if the cell is occupied by a vessel or not. Ship would only know it's length, as it's an inherent trait, and you'd add it to the board in either horizontal or vertical orientation and the board would be responsible for knowing which cells the ship occupies, since the cells belong to the board.
In the real world the ship is in water but that water might be moved by currents and wind which affecfts the true heading. Heck, sometimes that body of water might be on a ferris wheel. Show 2 more comments. Readability Variables Variables are a good way to express what code does.
Methods if ship. Roman Roman 2, 7 7 silver badges 19 19 bronze badges. He seems agree with me. Missile hits are part of the rules of the game so they should be in the game engine. How the game engine implements them is another issue e.
Would adding that be easy? If not, the design is flawed. Sign up or log in Sign up using Google. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. How to create a Battleship Warship game algorithm Ask Question. Asked 6 years, 2 months ago. Active 6 years, 2 months ago. Viewed 11k times.
I need it to look like the following: currently I can only seem to get a 1x1 ship and don't quite understand the logic for adding the 2x2 and randomizing it so that they're all connected. Not nearly finished but please be critical when it comes to judging my code, everything helps! Thanks in advance. Fire Shot" ; System. Show Solution" ; System.
I can't see your picture from here but if it's like standard battleship you just have to pick a direction for the "rest of the boat" once you have picked a location for its tip.
You'll have to check if every direction is elligible though, if you're too close to one side of the board you shouldn't try to expand your boat in that direction — Aaron.
Improve this answer. I started Java this year. Our teacher gave this project, but it is difficult for beginners, for me. So I have to get help to pass the lesson. Thank you for your answer. I want to ask one more thing. In this game, after the two players have placed their ships, they will shoot each other's board and mutually sink the ships.
Now you need to think object-oriented. Define multiple classes or entities: ship, player, board, score, etc. With all your objects, accessors and proper methods you will slowly start to manipulate them smartly. If you define a Ship class then you may imagine it as an object with multiple coordinates and once all of its coordinates were hit, its sunk and disappear from the Board instance. That's the next steps. But honestly and to spare you some disappointment, this site is the wrong place to answer these questions.
Be sure to have done enough research and come up with a specific and - if possible - unique problem before asking on StackOverlow. Add a comment. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name.
Email Required, but never shown.
0コメント