' -------------------------------------------------------------------- ' GETOBJECT AND PUTOBJECT CHANGES ' -------------------------------------------------------------------- Private Sub MoveFish(ByVal newOcean As Ocean, ByVal f As Fish) ' Pick a random direction for the fish to move to Dim n As Integer = Rnd.Next(1, 5) Dim p As Point Select Case n Case 1 p = newOcean.northOf(f.location) Case 2 p = newOcean.eastOf(f.location) Case 3 p = newOcean.southOf(f.location) Case 4 p = newOcean.westOf(f.location) End Select ' Check to see if the new location is open water If (newOcean.getObject(p).GetType.Equals(GetType(Water))) Then ' Breed a new fish at this location and swim to the new one newOcean.putObject(New Fish(f.location)) f.location = p newOcean.putObject(f) Else ' Leave the fish where it is newOcean.putObject(f) End If End Sub Private Function HuntShark(ByVal newOcean As Ocean, ByVal s As Shark, ByVal p As Point) Dim ate As Boolean = False ' Check to see if there is a fish to eat at location p If (newOcean.getObject(p).GetType.Equals(GetType(Fish))) Then ' Breed a new shark at its current location and eat the fish newOcean.putObject(New Shark(s.location)) s.location = p newOcean.putObject(s) ate = True End If Return ate End Function ' -------------------------------------------------------------------- ' SHARK METHODS ' -------------------------------------------------------------------- Private Function Hunt(ByVal newOcean As Ocean, ByVal p As Point) Dim ate As Boolean = False ' Check to see if there is a fish to eat at location p If (newOcean.getObject(p).GetType.Equals(GetType(Fish))) Then ' Breed a new shark at its current location and eat the fish newOcean.putObject(New Shark(myLocation)) myLocation = p newOcean.putObject(Me) ate = True End If Return ate End Function Public Sub Move(ByVal newOcean As Ocean) ' Hunt in a clockwise direction for fish to eat Dim ate As Boolean = Hunt(newOcean, newOcean.northOf(myLocation)) If Not ate Then ate = Hunt(newOcean, newOcean.eastOf(myLocation)) End If If Not ate Then ate = Hunt(newOcean, newOcean.southOf(myLocation)) End If If Not ate Then ate = Hunt(newOcean, newOcean.westOf(myLocation)) End If End Sub ' -------------------------------------------------------------------- ' SHARK IMAGE CODE ' -------------------------------------------------------------------- Private Shared myBrightImage As System.Drawing.Image = System.Drawing.Image.FromFile("../brightshark.jpg") Private Shared myMediumImage As System.Drawing.Image = System.Drawing.Image.FromFile("../mediumshark.jpg") Private Shared myDarkImage As System.Drawing.Image = System.Drawing.Image.FromFile("../darkshark.jpg") Public ReadOnly Property image() As System.Drawing.Image Get If myTicksUntilBreed < 2 Then Return myBrightImage ElseIf myTicksUntilBreed > 5 Then Return myDarkImage Else Return myMediumImage End If End Get End Property