Hi, I've been wondering if there is anyway to extend a sub of a base class in a derived class or subclass. To date, the only thing I've been able to find is overrides and overloads functions, but to my understanding these functions just ignore your base class's sub and just allows you to run the new one with the same name. What I want to be able to do is:
I'm not sure whether this is possible, or if I'd simply either make a new sub in my derived class that first ran the base's class sub or whether I'd override the base class and then copy and paste the old code. really I'm looking for the best way to accomplish this whatever it may be. Thanks in advance!
VB.NET:
If intGamecounter Mod 30 = 0 Then
ReDim Preserve clMushroom(clMushroom.Count)
clMushroom(clMushroom.Count - 1) = New mushroom
clMushroom(clMushroom.Count - 1).createenemy()
End If
If intGamecounter Mod 40 = 0 Then
ReDim Preserve clTurtle(clTurtle.Count)
clTurtle(clTurtle.Count - 1) = New turtle
clTurtle(clTurtle.Count - 1).createenemy()
End If
Class mushroom
Dim intRand As New Random
Public pbMushroom As New PictureBox
Sub createenemy()
With pbMushroom
.Height = 80
.Width = 80
.Left = -100
.Top = intRand.Next(0, 201) + 20
.Image = Image.FromFile(My.Application.Info.DirectoryPath & "\mushroom.jpg")
.SizeMode = PictureBoxSizeMode.StretchImage
End With
frmGame.Controls.Add(pbMushroom)
End Sub
End Class
Class turtle
inherits mushroom
Sub createenemy()
''Somehow Add additional Code onto this sub, so that when runs, it runs the previous
''code in the sub createenemy() of the base class, and then performs the code in this
''sub. is this possible?
End Sub
End Class