2017-12-19 22 views
-3

Ich versuche, ein Minenspiel zu erstellen, aber es stürzt jedes Mal ab. Kannst du mir helfen? Hier ist mein Code:Python 3.x - Python Tkinter

def refill(event): 
    for i in everything: 
     c.delete(i) # This is the 'Delete' statement 
     time.sleep(0.01) 
     global x2 
     global y2 
     for i in range(10): # This is the 'Create' statement 
      for i in range(10): 
       if random.randint(1, IRON_CHANCE) != 1: 
        stone = c.create_rectangle(x2, y2, x2 + 50, y2 + 50, fill='dim gray') 
        everything.append(stone) 
        y2 += 50 
       if random.randint(1, IRON_CHANCE) == 1: 
        ironStone = c.create_rectangle(x2, y2, x2 + 50, y2 + 50, fill='dim gray') 
        ironRect = c.create_rectangle(x2 + 10, y2 + 10, x2 + 40, y2 + 40, fill='ivory') 
        irons.append(ironRect) 
        everything.append(ironStone) 
        everything.append(ironRect) 
        y2 += 50 
        time.sleep(0.01) 
      x2 += 50 
      y2 = 0 
      time.sleep(0.01) 

Ich denke, das Problem liegt im 'Create' Zustand. Wenn ich diesen Zustand lösche, funktioniert das Spiel glatt und fein. Kannst du mir bitte helfen?

+3

Können Sie bitte ein [minimales, vollständiges und überprüfbares Beispiel] (https://stackoverflow.com/help/mcve) erstellen, das Ihr Problem reproduziert? –

+0

Ist das Ihr ganzer Code? Wenn nicht, fügen Sie bitte einen Kontext hinzu. –

+3

immer volle Fehlermeldung (Traceback) in Frage stellen (als Text, nicht als Screenshot). Es gibt andere nützliche Informationen. Und wir können nicht in deinem Verstand lesen noch sehen Sie Ihren Bildschirm (magische Glaskugel kaputt) – furas

Antwort

0

Beachten Sie, dass diese Aussage

if random.randint(1, IRON_CHANCE) != 1: 

kann gleich eins sein, und die nächste Anweisung, wenn nicht gleich zugleich sein kann, weil man zwei verschiedene Nummern verwenden. Vielleicht willst du ein anderes. Wir können nicht weiter helfen ohne Code, der vollständiger ist und den vollständigen Rückblick von dem Fehler.

  if random.randint(1, IRON_CHANCE) != 1: 
       stone = c.create_rectangle(x2, y2, x2 + 50, y2 + 50, fill='dim gray') 
       everything.append(stone) 
       y2 += 50 
      else: 
       ironStone = c.create_rectangle(x2, y2, x2 + 50, y2 + 50, fill='dim gray') 
       ironRect = c.create_rectangle(x2 + 10, y2 + 10, x2 + 40, y2 + 40, fill='ivory') 
       irons.append(ironRect) 
etc