diabolos
New member
I apologize if this is in the wrong place; however, I need some assistance.
I am a student at ITT Tech and I had to write my own version of Conways Game Of Life program. I got it working, I used a listbox and used the words dead or alive to represent the cells. NOW, I would like to use red and green boxes in a grid that are drawn on a panel.
I have been messing with this for a roughly week now. I have a basic idea but I just cant figure out how to get the panel to REDRAW the new boxes when I click my Seed button.
If you need more information please ask, I will be glad to provide any info.
I am a student at ITT Tech and I had to write my own version of Conways Game Of Life program. I got it working, I used a listbox and used the words dead or alive to represent the cells. NOW, I would like to use red and green boxes in a grid that are drawn on a panel.
I have been messing with this for a roughly week now. I have a basic idea but I just cant figure out how to get the panel to REDRAW the new boxes when I click my Seed button.
If you need more information please ask, I will be glad to provide any info.
Code:
Public Class Form1
Dim seed As Double
Dim num As Double
Dim MAX = 52
Dim cells1(MAX, MAX) As Boolean
Dim cells2(MAX, MAX) As Boolean
Dim currentRow As String
Private Sub btnSeed_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSeed.Click
If Not IsNumeric(txtGridSize.Text) Or Not IsNumeric(txtSeed.Text) Then
MessageBox.Show("Please Enter a numerical value into BOTH Grid size AND Seed", "ERROR!", MessageBoxButtons.OK)
txtGridSize.Clear()
txtSeed.Clear()
txtGridSize.Focus()
Else
MAX = CInt(txtGridSize.Text)
ReDim cells1(MAX, MAX)
Try
seed = CInt(txtSeed.Text)
Randomize(seed)
Catch ex As Exception
MessageBox.Show("An exception occurred:" & vbCrLf & ex.Message & " : Please enter a number between -2,147,483,648 and 2,147,483,647", "Uh Oh!", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error)
End Try
this will start the loop for populating the cells randomly
For X = 0 To MAX
For Y = 0 To MAX
num = Rnd()
If (num <= 0.5) Then
cells1(X, Y) = False
Else
cells1(X, Y) = True
End If
Next Y
Next X
End If
End Sub
Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
For x As Integer = 0 To MAX
For y As Integer = 0 To MAX
e.Graphics.DrawRectangle(Pens.Black, 50 + x * 10, 50 + y * 10, 10, 10)
If cells1(x, y) = False Then
e.Graphics.FillRectangle(Brushes.Red, 50 + x * 10 + 1, 50 + y * 10 + 1, 9, 9) these parameters are set to SHOW the gridlines
Else
e.Graphics.FillRectangle(Brushes.Green, 50 + x * 10 + 1, 50 + y * 10 + 1, 9, 9) these parameters are set to SHOW the gridlines
End If
Next y
Next x
Panel1.Invalidate()
End Sub
End Class
Last edited by a moderator: