Hey guys just wanna tell you now that I chose to do a minesweeper game or attempt to do one for a class project in VB. Now I'm not that experienced of a programmer so this is fairly difficult and I can tell you that I'm in way over my head with this so please don't get made/ frustrated that I'm asking for SOO much help. This is my first year of taking Visual Basic in a college setting. I really gave up asking my teacher because he's kind of, well, not good at this stuff which is weird right?

Anyway, amazingly I have it so it sets up a 10x10 grid of buttons, but other than that, I'm lost. I've tried to find source code to see how stuff works, but I get completely lost because that code is so advanced.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        ' The comma indicates 2 dimensions, as in x, y
        Dim mineFieldButtons As Button(,)

        ' Create our array
        mineFieldButtons = New Button(Width, Height) {}

        For X As Integer = 0 To Width - 1
            For Y As Integer = 0 To Height - 1
                ' Create the button
                'mineFieldButtons(X, Y) = CreateButton(X, Y)
                ' Add it to the form
                Controls.Add(mineFieldButtons(X, Y))
    End Sub

This is my code so far =(
I'll take any help someone is willing to give.

My *goal* is to make it so when a button is pressed it goes to flat, i know the code to make it flat but it doesn't want to work when I type it in. Then I want to get the bombs and numbers set up. The clearing of blank squares, to me, is trivial, I just want this to be able to work closely to the real thing.

7 Years
Discussion Span
Last Post by helix777

EDIT: I have code except I'm struggling to get this event thing to work anyone have any suggestions?

Public Class Form1

    'The width of the game
    Const GameWidth As Integer = 9

    'The height of the game
    Const GameHeight As Integer = 9

    'Width of the Cell
    Const CellWidth As Integer = 16

    'Height of the cell
    Const CellHeight As Integer = 16

    Const GridLeft As Integer = 12

    Const GridTop As Integer = 81

    'Declaring the minefield as a 2D array
    Dim mineField(GameWidth - 1, GameHeight - 1) As Button

    'Declaring Timer
    Dim sec As Integer

    'Declare minegrid as a click
    Public Event mineGrid As EventHandler

    'Random Number Generator
    Dim rand As New Random()
    Dim number = rand.Next(1, 10)
    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Loop to create the minefield with buttons
        For y As Integer = 0 To GameWidth - 1
            For x As Integer = 0 To GameHeight - 1
                mineField(x, y) = New Button
                mineField(x, y).Width = 16
                mineField(x, y).Height = 16
                Dim ButtonX As Integer = GridLeft + x * CellWidth
                Dim ButtonY As Integer = GridTop + y * CellHeight
                mineField(x, y).Location = New Point(ButtonX, ButtonY)
                Me.Controls.Add(mineField(x, y))
                AddHandler mineField(x, y).Click, AddressOf mineGrid_Click

    End Sub
    Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click
    End Sub
    Private Sub mineGrid_Click(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles mineGrid.MouseClick

    End Sub
    Private Sub Form1_mineGrid(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.mineGrid

    End Sub
End Class

Just add

Make a public or private sub for minegrin_click

something like this

Public Sub mineGrid_Click(sender As System.Object, e As System.EventArgs)
End Sub

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.