By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,168 Members | 2,598 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,168 IT Pros & Developers. It's quick & easy.

Disabling one button out of an array without changing the others.

P: 1
I am currently making a battleship game and I want to know how to disable one button out of the array at a time and when it is a miss it turns grey and if it is a hit it turns red. This is the code I have so far.....

Expand|Select|Wrap|Line Numbers
  1. Imports System
  2. Imports System.Drawing
  3. Imports System.Drawing.Graphics
  4. Public Class Form1
  5.     Private btnArray(6, 6) As Button
  6.     Private btnPic(6, 6) As PictureBox
  7.     Dim g As Graphics
  8.     Const FILE_PREFIX As String = "E:\ 2008-2009\visual basic\visual studio 2008\Projects\concentration\windowsapplication1\resources\"
  9.     Const FILE_SUFFIX As String = ".png"
  10.     Const BUTTON As String = "button"
  11.  
  12.     Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click
  13.         End
  14.     End Sub
  15.  
  16.     Private Sub btnPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  17.         Dim x As Integer
  18.         Dim y As Integer
  19.  
  20.         For y = 0 To 4
  21.             For x = 0 To 4
  22.                 btnArray(x, y) = New Button
  23.                 btnArray(x, y).Parent = Me
  24.                 btnArray(x, y).Width = 100
  25.                 btnArray(x, y).Left = x * 100
  26.                 btnArray(x, y).Height = 100
  27.                 btnArray(x, y).Top = 20 + y * 100
  28.                 btnArray(x, y).Tag = x & Space(2) & y
  29.                 btnArray(x, y).BringToFront()
  30.                 AddHandler btnArray(x, y).Click, AddressOf Me.btnPlay_Click
  31.                 AddHandler btnArray(x, y).MouseDown, AddressOf Me.btnArray_MouseDown
  32.  
  33.             Next
  34.         Next
  35.  
  36.     End Sub
  37.  
  38.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  39.         Dim x As Integer
  40.         Dim y As Integer
  41.  
  42.         For y = 0 To 4
  43.             For x = 0 To 4
  44.                 btnArray(x, y) = New Button
  45.                 btnArray(x, y).Parent = Me
  46.                 btnArray(x, y).Width = 100
  47.                 btnArray(x, y).Left = x * 100
  48.                 btnArray(x, y).Height = 100
  49.                 btnArray(x, y).Top = 20 + y * 100
  50.                 btnArray(x, y).Tag = x & Space(2) & y
  51.                 btnArray(x, y).BringToFront()
  52.                 AddHandler btnArray(x, y).Click, AddressOf Me.btnPlay_Click
  53.                 AddHandler btnArray(x, y).MouseDown, AddressOf Me.btnArray_MouseDown
  54.  
  55.             Next
  56.         Next
  57.  
  58.         Call AssignWords()
  59.         Call PlayerChoose()
  60.     End Sub
  61.  
  62.     Private Sub AssignPicButtons()
  63.  
  64.         Dim tally(18) As Integer
  65.         Dim randomObject As New Random()
  66.         Dim randomNumber As Integer = randomObject.Next(1, 19)
  67.  
  68.         For x = 0 To 4
  69.             For y = 0 To 4
  70.                 btnPic(x, y) = New PictureBox
  71.                 btnPic(x, y).Parent = btnArray(x, y)
  72.                 btnPic(x, y).Width = 90
  73.                 btnPic(x, y).Left = 5 + x * 00
  74.                 btnPic(x, y).Height = 90
  75.                 btnPic(x, y).Top = 5 + y * 100
  76.                 btnPic(x, y).Image = Image.FromFile(FILE_PREFIX & BUTTON & randomNumber & FILE_SUFFIX)
  77.                 btnPic(x, y).Hide()
  78.             Next
  79.         Next
  80.     End Sub
  81.  
  82.     Private Sub AssignWords()
  83.         Dim randomObject As New Random()
  84.         Dim randomNumber As Integer
  85.         Dim check(18) As Integer
  86.         Dim intcheck As Integer = 0
  87.         Dim blnMadeWord As Boolean = False
  88.  
  89.         For x = 0 To 4
  90.             For y = 0 To 4
  91.                 blnMadeWord = False
  92.                 Do While blnMadeWord = False
  93.                     randomNumber = randomObject.Next(1, 19)
  94.                     check(randomNumber) = check(randomNumber) + 1
  95.                     If check(randomNumber) < 3 Then
  96.                         For randomNumber = 0 To 18
  97.  
  98.                             Select Case randomNumber
  99.  
  100.                                 Case 1
  101.                                     btnArray(x, y).Text = "Battleship"
  102.                                 Case 2
  103.                                     btnArray(x, y).Text = "Battleship"
  104.                                 Case 3
  105.                                     btnArray(x, y).Text = "Battleship"
  106.                                 Case 4
  107.                                     btnArray(x, y).Text = "Battleship"
  108.                                 Case 5
  109.                                     btnArray(x, y).Text = "Battleship"
  110.                                 Case 6
  111.                                     btnArray(x, y).Text = "Battleship"
  112.                                 Case 7
  113.                                     btnArray(x, y).Text = "Battleship"
  114.                                 Case 8
  115.                                     btnArray(x, y).Text = "Battleship"
  116.                                 Case 9
  117.                                     btnArray(x, y).Text = "Battleship"
  118.                                 Case 10
  119.                                     btnArray(x, y).Text = "Battleship"
  120.                                 Case 11
  121.                                     btnArray(x, y).Text = "Battleship"
  122.                                 Case 12
  123.                                     btnArray(x, y).Text = "Battleship"
  124.                                 Case 13
  125.                                     btnArray(x, y).Text = "Battleship"
  126.                                 Case 14
  127.                                     btnArray(x, y).Text = "Battleship"
  128.                                 Case 15
  129.                                     btnArray(x, y).Text = "Battleship"
  130.                                 Case 16
  131.                                     btnArray(x, y).Text = "Battleship"
  132.                                 Case 17
  133.                                     btnArray(x, y).Text = "Battleship"
  134.                                 Case 18
  135.                                     btnArray(x, y).Text = "Battleship"
  136.  
  137.                             End Select
  138.                         Next
  139.  
  140.                         blnMadeWord = True
  141.  
  142.                     End If
  143.                 Loop
  144.             Next y
  145.         Next x
  146.  
  147.     End Sub
  148.  
  149.  
  150.     Private Sub PlayerChoose()
  151.  
  152.     End Sub
  153.  
  154.     Private Sub SetBackgroundPicture()
  155.     End Sub
  156.  
  157.     Private Sub EndToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EndToolStripMenuItem.Click
  158.         End
  159.     End Sub
  160.  
  161. End Class
Jun 7 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.