12,763,337 members (26,304 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hello , I'm trying to do Minesweeper in VB.net and I'm looking for draft codes. Can you help me, please? Also I have to 'count the mines around a specified cell (parameters: array, rowIndex, columnIndex) ' .

Thank you.
Posted 6-Feb-13 6:26am
DDDYYYY319
Comments
phil.o 6-Feb-13 11:31am

What have you tried ? Where are you stuck ?

## 1 solution

Rate this:
Please Sign up or sign in to vote.

## Solution 1

This sounds like homework, so I'll give you no code.
But it isn't complex: the "count the mines bit is really very easy (and made even easier if you cheat).

I would cheat - make the playing surface 2 cells bigger in each direction, so you have a border of one cell around the whole surface. So if you have a two by two surface for the player:
```##
##```
You surround it by a one cell border:
```++++
+##+
+##+
++++```
You then clear the border so it contain no mines.
Now, when you count all the cells around the specific cell for mines, you don't have to do any error checking to ensure you aren't running out of surface - because you will and count the border cells instead. Which contains no mines! And I'd make a mine a 1, and no mine a zero...

This done, the test is easy:
if you are checking cell (x,y) then the count is simple:
`count = (x-1, y-1) + (x, y-1) + (x+1, y-1) + (x-1, y) + (x+1, y) + (x-1, y+1) + (x, y+1) + (x+1, y+1)`
All you have to do is write two methods: GetCellAt and SetCellAt which take the x and y addresses

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 OriginalGriff 290 ppolymorphe 160 Peter Leow 160 CPallini 145 Karthik Bangalore 100
 OriginalGriff 4,932 Peter Leow 3,554 ppolymorphe 2,933 Karthik Bangalore 2,814 Graeme_Grant 2,626

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 6 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100