0
勝利と終了を含むすべてを入れるまですべてがうまくいっていましたが、それ以前に働いていたコードは、現在iterableではありません。起こると思われることは、地図上のどこか別の場所に移動したときに一定の距離を横切ったときです。それ以外のものは気にしません。これは単なるテストです。私はエラーコードを取得し続けます。境界外ではない壁を作るPythonのカメゲーム、なしタイプのエラーコード、反復不可能
`Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files\Python36\lib\tkinter\__init__.py", line 1699, in
__call__
return self.func(*args)
File "C:\Program Files\Python36\lib\turtle.py", line 686, in eventfun
fun()
File "E:\Home made game\original.py", line 183, in k1
elif win(player):
File "E:\Home made game\original.py", line 37, in win
return inside(position, winner)
File "E:\Home made game\original.py", line 7, in inside
x1 = min(p[0] for p in rectangle)
TypeError: 'NoneType' object is not iterable'
これは残りのコードです。あなたはこれらの変数にポリゴンを割り当てる
from turtle import Turtle, Screen
def inside(point, rectangle):
x, y = point
# not efficient, just a quick solution
x1 = min(p[0] for p in rectangle)
y1 = min(p[1] for p in rectangle)
x2 = max(p[0] for p in rectangle)
y2 = max(p[1] for p in rectangle)
return x1 < x < x2 and y1 < y < y2
def not_safe(turtle):
position = turtle.position()
return inside(position, river) and not inside(position, bridge)
def winLine(turtle):
turtle.up()
turtle.color('red')
turtle.goto(-WIDTH/2, 0)
turtle.down()
turtle.begin_poly()
turtle.begin_fill()
turtle.forward(WIDTH)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(WIDTH)
turtle.end_fill()
turtle.end_poly()
def win(turtle):
position = turtle.position()
return inside(position, winner)
def drawTree(t, sd):
for i in range(4):
layout.down()
t.forward(sd)
t.right(90)
layout.up()
def drawRiver(turtle):
turtle.color('darkblue', 'blue')
turtle.goto(-WIDTH/2, 0)
turtle.begin_poly()
turtle.begin_fill()
turtle.forward(WIDTH)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(WIDTH)
turtle.end_fill()
turtle.end_poly()
return turtle.get_poly()
def tree(branchLen,layout):
if branchLen > 6:
layout.down()
layout.forward(branchLen)
layout.right(20)
tree(branchLen-6,layout)
layout.left(40)
tree(branchLen-6,layout)
layout.right(20)
layout.backward(branchLen)
layout.up()
def main():
layout.speed('fastest')
layout.left(90)
layout.up()
layout.backward(100)
layout.down()
layout.color("brown")
tree(36,layout)
layout.right(90)
layout.up()
def drawBridge(turtle):
turtle.goto(150, 25)
turtle.color('rosybrown4', 'saddlebrown')
turtle.begin_poly()
turtle.begin_fill()
turtle.forward(100)
turtle.left(90)
turtle.forward(150)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.end_fill()
turtle.end_poly()
return turtle.get_poly()
def drawPlanks(turtle):
layout.goto(149, -125)
for i in range(37):
layout.pensize(.1)
layout.down()
layout.color("black")
layout.forward(.3)
layout.left(90)
layout.forward(99)
layout.left(90)
layout.forward(.3)
layout.left(90)
layout.forward(99)
layout.left(90)
layout.up()
layout.forward(4)
layout.goto(149, 25)
layout.down()
layout.left(90)
layout.forward(100)
layout.pensize(.1)
layout.up()
layout.goto(149, -125)
layout.down()
layout.right(90)
layout.forward(151)
layout.up()
layout.goto(49, -125)
layout.down()
layout.forward(151)
wn = Screen()
wn.bgcolor('lightgreen')
WIDTH = wn.window_width()
layout = Turtle(visible=False)
layout.speed('fastest')
layout.penup()
river = drawRiver(layout)
bridge = drawBridge(layout)
planks = drawPlanks(layout)
winner= winLine(layout)
layout.up()
layout.right(90)
# Tree locations
layout.goto(222, 198)
main()
layout.goto(-334, 155)
main()
layout.goto(132, 140)
main()
layout.goto(50, -222)
main()
layout.goto(200, -122)
main()
layout.goto(-362,200)
main()
layout.goto(-222, 198)
main()
layout.goto(350, 350)
main()
layout.goto(-200, -150)
main()
layout.color("blue")
layout.goto(0, -50)
player = Turtle('arrow')
player.color('grey')
player.penup()
player.goto(0, -200)
player.setheading(90)
def k1():
player.forward(45)
if not_safe(player):
player.goto(0, -200)
player.setheading(90)
elif win(player):
player.goto(200, 100)
def k4():
player.back(45)
if not_safe(player):
player.goto(0, -200)
player.setheading(90)
elif win(player):
player.goto(200, 100)
def k2():
player.left(30)
def k3():
player.right(30)
wn.onkey(k1, "Up")
wn.onkey(k2, "Left")
wn.onkey(k3, "Right")
wn.onkey(k4, "Down")
wn.listen()
wn.mainloop()
が 'エラーの最後の行に何をrectangle'されますか?おそらく、あなたは 'rectangle'に1つの要素を持っていますが、' min(pの長方形の中ではp [0]) 'のリストとしてそれを使います。 'print(rectangle)'や 'print(type(rectangle))'を使ってチェックすることができます。 – furas
あなたは変数 'finish = ...'と関数 'def finish(...)'を持っています - 'inside(...、finish)'を使うと問題になります。 '。 'inside(...、finish)'で 'finish'の代わりに別のものを使うべきでしょうか? – furas