
下图是海龟行走路线

同样的代码,完成不同的迷宫!
# -*- coding: utf-8 -*-
from turtle import *
g=[[0,0,1,0],[0,1,0,1],[0,1,0,1],[0,1,0,1],[0,1,0,1],[0,1,0,1],[0,1,0,1],[0,1,0,1],[0,1,0,1],[1,1,0,0],
[1,0,1,0],[0,1,1,0],[0,1,0,0],[0,1,0,0],[0,1,0,0],[0,1,0,0],[0,1,0,0],[0,1,0,0],[1,1,0,0],[1,0,1,0],
[1,0,1,0],[0,0,1,1],[0,0,0,1],[0,0,0,1],[0,0,0,1],[0,0,0,1],[0,0,0,1],[0,0,0,1],[1,0,0,0],[1,0,1,0],
[0,0,1,0],[0,1,0,1],[0,1,0,1],[0,1,0,1],[0,1,0,1],[0,1,0,1],[0,1,0,1],[1,1,0,1],[1,0,1,0],[1,0,1,0],
[0,0,1,1],[0,1,0,1],[0,1,0,1],[0,1,0,1],[0,1,0,1],[0,1,0,1],[0,1,0,1],[0,1,0,1],[1,0,0,1],[1.0,1,0]]
setup(550,350)
bgpic('c:/12.gif') # 主要图片的名称和位置
speed(10000)
penup()
pensize(11)
pencolor('red')
goto(-225,150)
pendown()
right(90)
forward(50)
fx=3
x=0
while x!=49:
fx0=fx-1
if fx0==-1:
fx0=3
if g[x][fx0]==0:
right(90)
forward(50)
fx=fx0
if fx==0:
x+=1
if fx==1:
x-=10
if fx==2:
x-=1
if fx==3:
x+=10
else:
left(90)
fx=fx+1
if fx==4:
fx=0
if fx==0:
right(90)
forward(50)
done()

