Results 1 to 3 of 3

Thread: BattleShip Help

  1. #1

    Thread Starter
    New Member j0sh77's Avatar
    Join Date
    Jan 2012
    Posts
    15

    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!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,806

    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
  •  



Click Here to Expand Forum to Full Width