|
-
May 23rd, 2012, 08:03 AM
#1
Thread Starter
New Member
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!
-
May 23rd, 2012, 08:07 AM
#2
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.
-
May 23rd, 2012, 10:59 AM
#3
Frenzied Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|