-
BattleShip Help
For a final project in my VB Class, I am making BattleShip. I have all the coding done to place ships and guess others, but my ships are able to intersect.
I am having a hard time thinking of how to stop this. I could make a procedure that checked if the xy position of one is near another, but that would only allow it to not intersect at the base point.
How might I get this to work with minimal code that doesn't allow the ships to intersect anywhere? (i.e. the middle of two pieces overlapping)
Thanks in advance!
-
Re: BattleShip Help
Use a Rectangle to represent each ship. When you want to place a ship, loop through the Rectangles that represent the ships already on the board and use the Rectangle.IntersectsWith method to... do the obvious. If it returns True then you cannot place the ship in that position.
-
Re: BattleShip Help
If you are un sure of the command here is a link explaining with demo:-
http://msdn.microsoft.com/en-us/libr...tswith.aspx#Y0