[VisualBasic] Game of Life

Dieses Thema im Forum "Programmierung & Entwicklung" wurde erstellt von Ni©o, 8. April 2008 .

  1. 8. April 2008
    Game of Life

    Hallo ,

    muss game of life in visual basic programmieren


    Code:
    Dim xx, yy As Single
    Dim a(10, 10)
    Dim b(10, 10)
    
    
    Private Sub Command1_Click()
    Picture1.Scale (-5.1, -5.1)-(5.1, 5.1)
    For X = -5 To 5
    Picture1.Line (X, -5)-(X, 5)
    Next X
    For Y = -5 To 5
    Picture1.Line (-5, Y)-(5, Y)
    Next Y
    Nachbarnzaehlen
    End Sub
    Private Sub Command2_Click()
    Picture1.Cls
    End Sub
    
    Private Sub Form_Load()
    
    End Sub
    
    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    xx = Int(X)
    yy = Int(Y)
    End Sub
    Private Sub Picture1_click()
    xxx = xx + 0.5
    yyy = yy + 0.5
    Picture1.Line (xxx + 0.5, yyy + 0.5)-(xxx - 0.5, yyy - 0.5)
    Picture1.Line (xxx - 0.5, yyy + 0.5)-(xxx + 0.5, yyy - 0.5)
    [b]a(xx, yy) = 1[/b]
    End Sub
    Private Sub Nachbarnzaehlen()
    For xx = 1 To 9
    For yy = 1 To 9
     
     For g = xx - 1 To xx + 1
     For m = yy - 1 To yy + 1
     If a(g, m) = 1 Then b(xx, yy) = b(xx, yy) + 1
     
     Next m
     Next g
     If a(xx, yy) = 1 Then b(xx, yy) = b(xx, yy) - 1
     
     
    Next yy
    Next xx
    End Sub
    
    komme nicht mehr weiter

    könnts ihr mal vllt helfen
    hoffe ihr habt´s verstanden
    danke im vorraus
     
  2. 8. April 2008
    AW: Game of Life

    ja aber weiss auch nicht so gut
    ist hausaufgabe
    a(xx, yy) = 1<--- bekomme ich den laufzeitfehler 9 "Index außerhalb des gültigen Bereiches
     
  3. 8. April 2008
    AW: Game of Life

    das a(xx, yy) = 1 kommt mir eh irgendwiekomisch vor..
     
  4. 8. April 2008
    AW: Game of Life

    Bitte geh doch mal mim DEBUG durch dein Programm durch, und sag uns welche Werte denn
    a) in der Funktion für X und Y übergeben werden und
    b) welche Werte denn deine Variablen xx und yy haben.

    Ich denke mir, dass die Indizes, mit denen du auf das Array (von 10x10 Elementen) zugreifst, einfach zu groß sind.

    - - -
    tanya
     
  5. 8. April 2008
    AW: Game of Life

    hab nicht gesagt dass ihr die hausaufgabe für mich macht
    brauche nur hilfe weil ich nicht mehr weiterkomme

    a(0 to 10, 0 to 10)as variant
     
  6. 9. April 2008
    AW: Game of Life

    Keine Antwort?
     
  7. 9. April 2008
    AW: Game of Life

    sry
    emm
    a(xx,yy) = a(xx=-5,yy=-3)
    hoffe hab dich richtig verstanden
     
  8. 9. April 2008
    AW: Game of Life

    Passt irgendwie beides nicht zusammen. (Wusste noch nicht das -5 zwischen 0 und 10 liegt)


    mfg Nash
     
  9. 10. April 2008
    AW: Game of Life

     
  10. 10. April 2008
    AW: Game of Life

    @hardwarehunger
    danke aber ich will es selber lernen
    da ist es bisschen kompliziert
    hab den code bischen geändert
    Code:
    Dim a(10, 10)
    Dim b(10, 10)
    Private Sub Command1_Click()
    Picture1.Scale (0, 0)-(10, 10)
    For X = 0 To 10
    Picture1.Line (X, 0)-(X, 10)
    Next X
    For Y = 0 To 10
    Picture1.Line (0, Y)-(10, Y)
    Next Y
    Rem Nachbarnzaehlen
    Rem Leben
    End Sub
    Private Sub loeschen_Click()
    Picture1.Cls
    End Sub
    Private Sub start_Click()
    Nachbarnzaehlen
    Leben
    End Sub
    Private Sub Form_Load()
    Me.BackColor = QBColor(15)
    Label1.BackColor = QBColor(15)
    Label2.BackColor = QBColor(15)
    Picture1.BackColor = QBColor(7)
    End Sub
    Private Sub Nachbarnzaehlen()
    For xx = 1 To 9
    For yy = 1 To 9
     For g = xx - 1 To xx + 1
     For m = yy - 1 To yy + 1
     If a(g, m) = 1 Then b(xx, yy) = b(xx, yy) + 1
     Next m
     Next g
     If a(xx, yy) = 1 Then b(xx, yy) = b(xx, yy) - 1
    Next yy
    Next xx
    End Sub
    Private Sub Leben()
    If b(xx, yy) > 3 Or b(xx, yy) < 2 Then
    a(xx, yy) = 0
    If b(xx, yy) = 3 And a(xx, yy) = 0 Then a(xx, yy) = 1
    End If
    End Sub
    
    Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    xx = Int(X)
    yy = Int(Y)
    xxx = xx + 0.5
    yyy = yy + 0.5
    Picture1.Line (xxx + 0.5, yyy + 0.5)-(xxx - 0.5, yyy - 0.5)
    Picture1.Line (xxx - 0.5, yyy + 0.5)-(xxx + 0.5, yyy - 0.5)
    a(xx, yy) = 1
    End Sub
    
    alsoo wenn ich auf start drücke passiert gar nichts
    aber laufzeitfehler 9 kommt nicht mehr

    danke im vorraus
     
  11. Video Script

    Videos zum Themenbereich

    * gefundene Videos auf YouTube, anhand der Überschrift.