Posted on
2005-06-09 22:40
岳洋
阅读(
572)
评论()
收藏
举报

Public Class Form1Class Form1
Inherits System.Windows.Forms.Form

Public Structure medicineStructure medicine
Public area As Byte
Public killrate As Byte
End Structure

Public Structure bacteriaStructure bacteria
Public locate As System.Drawing.Point
Public antimedicine() As Boolean
Public alive As Boolean
End Structure
Public CurrentMedicine As New medicine()
Public med(10) As medicine
Public bact(50) As bacteria
Public i, j, sum As Short
Public t As bacteria
Public boi, boj As Boolean
Public lastbact As Byte


Windows 窗体设计器生成的代码#Region " Windows 窗体设计器生成的代码 "


Public Sub New()Sub New()
MyBase.New()

'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()

'在 InitializeComponent() 调用之后添加任何初始化

End Sub

'窗体重写处置以清理组件列表。

Protected Overloads Overrides Sub Dispose()Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer

'注意:以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents Timer1 As System.Windows.Forms.Timer
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend Label(10, 10) As System.Windows.Forms.Label
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents Label6 As System.Windows.Forms.Label
Friend WithEvents Label7 As System.Windows.Forms.Label
Friend WithEvents Label8 As System.Windows.Forms.Label
Friend WithEvents Label9 As System.Windows.Forms.Label
Friend WithEvents Label10 As System.Windows.Forms.Label
Friend WithEvents Label11 As System.Windows.Forms.Label
Friend WithEvents Label12 As System.Windows.Forms.Label
Friend WithEvents Label13 As System.Windows.Forms.Label
Friend WithEvents Label14 As System.Windows.Forms.Label
Friend WithEvents Label15 As System.Windows.Forms.Label
Friend WithEvents Label16 As System.Windows.Forms.Label
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Label17 As System.Windows.Forms.Label
Friend WithEvents Label18 As System.Windows.Forms.Label

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()Sub InitializeComponent()
Me.components = New System.ComponentModel.Container()
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
Me.GroupBox1 = New System.Windows.Forms.GroupBox()
Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label3 = New System.Windows.Forms.Label()
Me.Label4 = New System.Windows.Forms.Label()
Me.Label5 = New System.Windows.Forms.Label()
Me.Label6 = New System.Windows.Forms.Label()
Me.Label7 = New System.Windows.Forms.Label()
Me.Label8 = New System.Windows.Forms.Label()
Me.Label9 = New System.Windows.Forms.Label()
Me.Label10 = New System.Windows.Forms.Label()
Me.Label11 = New System.Windows.Forms.Label()
Me.Label12 = New System.Windows.Forms.Label()
Me.Label13 = New System.Windows.Forms.Label()
Me.Label14 = New System.Windows.Forms.Label()
Me.Label15 = New System.Windows.Forms.Label()
Me.Label16 = New System.Windows.Forms.Label()
Me.Button1 = New System.Windows.Forms.Button()
Me.Button2 = New System.Windows.Forms.Button()
Me.Label17 = New System.Windows.Forms.Label()
Me.Label18 = New System.Windows.Forms.Label()
Me.SuspendLayout()
'
'Timer1
'
'
'GroupBox1
'
Me.GroupBox1.Location = New System.Drawing.Point(8, 8)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(456, 120)
Me.GroupBox1.TabIndex = 0
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "GroupBox1"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(32, 144)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(32, 32)
Me.Label1.TabIndex = 1
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(72, 144)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(32, 32)
Me.Label2.TabIndex = 1
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(112, 144)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(32, 32)
Me.Label3.TabIndex = 1
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(152, 144)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(32, 32)
Me.Label4.TabIndex = 1
'
'Label5
'
Me.Label5.Location = New System.Drawing.Point(32, 184)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(32, 32)
Me.Label5.TabIndex = 1
'
'Label6
'
Me.Label6.Location = New System.Drawing.Point(72, 184)
Me.Label6.Name = "Label6"
Me.Label6.Size = New System.Drawing.Size(32, 32)
Me.Label6.TabIndex = 1
'
'Label7
'
Me.Label7.Location = New System.Drawing.Point(112, 184)
Me.Label7.Name = "Label7"
Me.Label7.Size = New System.Drawing.Size(32, 32)
Me.Label7.TabIndex = 1
'
'Label8
'
Me.Label8.Location = New System.Drawing.Point(152, 184)
Me.Label8.Name = "Label8"
Me.Label8.Size = New System.Drawing.Size(32, 32)
Me.Label8.TabIndex = 1
'
'Label9
'
Me.Label9.Location = New System.Drawing.Point(32, 224)
Me.Label9.Name = "Label9"
Me.Label9.Size = New System.Drawing.Size(32, 32)
Me.Label9.TabIndex = 1
'
'Label10
'
Me.Label10.Location = New System.Drawing.Point(72, 224)
Me.Label10.Name = "Label10"
Me.Label10.Size = New System.Drawing.Size(32, 32)
Me.Label10.TabIndex = 1
'
'Label11
'
Me.Label11.Location = New System.Drawing.Point(112, 224)
Me.Label11.Name = "Label11"
Me.Label11.Size = New System.Drawing.Size(32, 32)
Me.Label11.TabIndex = 1
'
'Label12
'
Me.Label12.Location = New System.Drawing.Point(152, 224)
Me.Label12.Name = "Label12"
Me.Label12.Size = New System.Drawing.Size(32, 32)
Me.Label12.TabIndex = 1
'
'Label13
'
Me.Label13.Location = New System.Drawing.Point(32, 264)
Me.Label13.Name = "Label13"
Me.Label13.Size = New System.Drawing.Size(32, 32)
Me.Label13.TabIndex = 1
'
'Label14
'
Me.Label14.Location = New System.Drawing.Point(72, 264)
Me.Label14.Name = "Label14"
Me.Label14.Size = New System.Drawing.Size(32, 32)
Me.Label14.TabIndex = 1
'
'Label15
'
Me.Label15.Location = New System.Drawing.Point(112, 264)
Me.Label15.Name = "Label15"
Me.Label15.Size = New System.Drawing.Size(32, 32)
Me.Label15.TabIndex = 1
'
'Label16
'
Me.Label16.Location = New System.Drawing.Point(152, 264)
Me.Label16.Name = "Label16"
Me.Label16.Size = New System.Drawing.Size(32, 32)
Me.Label16.TabIndex = 1
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(384, 136)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(80, 24)
Me.Button1.TabIndex = 2
Me.Button1.Text = "Start"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(384, 168)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(80, 24)
Me.Button2.TabIndex = 3
Me.Button2.Text = "Drop Bact."
'
'Label17
'
Me.Label17.Location = New System.Drawing.Point(192, 144)
Me.Label17.Name = "Label17"
Me.Label17.Size = New System.Drawing.Size(64, 24)
Me.Label17.TabIndex = 4
Me.Label17.Text = "lastbact"
'
'Label18
'
Me.Label18.Location = New System.Drawing.Point(264, 144)
Me.Label18.Name = "Label18"
Me.Label18.Size = New System.Drawing.Size(32, 32)
Me.Label18.TabIndex = 5
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(480, 334)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label18, Me.Label17, Me.Button2, Me.Button1, Me.Label1, Me.GroupBox1, Me.Label2, Me.Label3, Me.Label4, Me.Label5, Me.Label6, Me.Label7, Me.Label8, Me.Label9, Me.Label10, Me.Label11, Me.Label12, Me.Label13, Me.Label14, Me.Label15, Me.Label16})
Me.Name = "Form1"
Me.Text = "细菌与抗生素的模拟"
Me.ResumeLayout(False)

End Sub

#End Region


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

For i = 0 To 9
med(i).area = 15
med(i).killrate = 90
Next
CurrentMedicine = med(0)
For i = 0 To 49
ReDim bact(i).antimedicine(10)
Next
firstready()
End Sub

Private Sub firstready()Sub firstready()
clearlabel()
lastbact = 0

End Sub

Private Sub newbact()Sub newbact(ByVal number As Byte)
Dim ro As System.Random = New Random()
bact(number).locate.X = (ro.Next(0, 4))
bact(number).locate.Y = (ro.Next(0, 4))
bact(number).alive = True
For i = 0 To 9
bact(number).antimedicine(i) = False
Next
End Sub



Private Sub Button1_Click()Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Interval = 20
Timer1.Enabled = True
Timer1.Start()
End Sub

Private Sub printbact()Sub printbact(ByVal t As bacteria)
If t.locate.X = 0 And t.locate.Y = 0 Then Label1.Text = Val(Label1.Text) + 1
If t.locate.X = 0 And t.locate.Y = 1 Then Label2.Text = Val(Label2.Text) + 1
If t.locate.X = 0 And t.locate.Y = 2 Then Label3.Text = Val(Label3.Text) + 1
If t.locate.X = 0 And t.locate.Y = 3 Then Label4.Text = Val(Label4.Text) + 1
If t.locate.X = 1 And t.locate.Y = 0 Then Label5.Text = Val(Label5.Text) + 1
If t.locate.X = 1 And t.locate.Y = 1 Then Label6.Text = Val(Label6.Text) + 1
If t.locate.X = 1 And t.locate.Y = 2 Then Label7.Text = Val(Label7.Text) + 1
If t.locate.X = 1 And t.locate.Y = 3 Then Label8.Text = Val(Label8.Text) + 1
If t.locate.X = 2 And t.locate.Y = 0 Then Label9.Text = Val(Label9.Text) + 1
If t.locate.X = 2 And t.locate.Y = 1 Then Label10.Text = Val(Label10.Text) + 1
If t.locate.X = 2 And t.locate.Y = 2 Then Label11.Text = Val(Label11.Text) + 1
If t.locate.X = 2 And t.locate.Y = 3 Then Label12.Text = Val(Label12.Text) + 1
If t.locate.X = 3 And t.locate.Y = 0 Then Label13.Text = Val(Label13.Text) + 1
If t.locate.X = 3 And t.locate.Y = 1 Then Label14.Text = Val(Label14.Text) + 1
If t.locate.X = 3 And t.locate.Y = 2 Then Label15.Text = Val(Label15.Text) + 1
If t.locate.X = 3 And t.locate.Y = 3 Then Label16.Text = Val(Label16.Text) + 1
End Sub

Private Sub clearlabel()Sub clearlabel()
Label1.Text = "0"
Label2.Text = "0"
Label3.Text = "0"
Label4.Text = "0"
Label5.Text = "0"
Label6.Text = "0"
Label7.Text = "0"
Label8.Text = "0"
Label9.Text = "0"
Label10.Text = "0"
Label11.Text = "0"
Label12.Text = "0"
Label13.Text = "0"
Label14.Text = "0"
Label15.Text = "0"
Label16.Text = "0"
End Sub


Private Sub Timer1_Tick()Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
clearlabel()
Label18.Text = Str(lastbact)
sum = 0
For Each t In bact
If t.alive = True Then
printbact(t)
boi = True
For Each boi In t.antimedicine
If boj = False Then
boi = False
Exit For
End If
If boi = True Then
Timer1.Stop()
MsgBox("Super bacteria appeared!")
Exit Sub
End If
Next
sum = sum + 1
End If
Next
If sum = 0 And lastbact <> 0 Then
Timer1.Stop()
MsgBox("All the bacterium died!")
Exit Sub
End If
End Sub


Private Sub Button2_Click()Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If lastbact = 50 Then
MsgBox("maxium number of bacts!")
Else
lastbact = lastbact + 1
newbact(lastbact - 1)
End If
End Sub
End Class
