|
-
May 20th, 2013, 05:22 AM
#2
Re: battleship help msflexgrid
 Originally Posted by firezap
How to make computer randomly place his ships on the grid. Place vertically or horizontally randomly.
For each ship, pick random values for row/column/direction.
If you don't know how to generate random numbers, see the tutorial about them in our Classic VB FAQs (in the FAQ forum)
Check that the ship can be placed at that location (ie: it doesn't go off the edge of the grid, or share a square with a ship that has already been placed), and if not pick a new set of random numbers for that ship and try again.
Once you have made sure the position is valid, store it.
The grid will still look like this after the ships are placed. When i click on the grid how do i check for a hit or a miss? if it's a hit i want to change the CellBackColor to red or if it's miss then i change CellBackColor to white.
In that case you should store the values to an array rather than directly to the grid (if you don't know about arrays, see the FAQs link above).
When a click happens, check the value in the array, and set the grid cell colour as apt.
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
|