I am building a game in Visual Basic called Battleship. I have 100 buttons (10 rows x 10 columns) and what I want the user to do, is be able to click on a button and a function called IsCreated
(which is a Boolean) turns True for the certain button.
Two questions:
1. How do I create this function ?
2. How do I make the button that is clicked have IsCreated turn from true into false ?
A very basic way would be to assign each button a number & use that in a function call from onClick(). You'd just have a global array of booleans (I used boardPosition)
Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles button1.Click
boardPosition(1) = IsCreated(1)
End Sub
Then just have:
Protected Function IsCreated(byVal buttonNumberClicked as integer)
If boardPosition(buttonNumberClicked) Then
return true
else
return false
End If
End Function
This is assuming you've just created 100 buttons...Not an elegant solution but it'll work.
Edit: Clean up.