用户:Ryan袁奥查看:0 回复:3 评论:0 创建时间:2019-02-14T22:04:40
#--#:模式介绍:#--#
pigu='''
足球模式:
红方w,s,a,d控制,
篮方上,下,左,右控制
经典玩法:
蓝球进入红门计一分
红球入篮门计一分
红球会跟着红球员移动,
进入篮色球门计一分,
蓝球会跟着蓝色球员移动,
进入红色球门计一分,
红球员碰到蓝色球,
蓝色球和红球员就会移动,
篮球员碰到红色球,
红色球和篮球员就会移动攻守玩法相似
'''
pigu1='''
抢球模式:
红方w,s,a,d控制,
篮方上,下,左,右控制
经典玩法:
球为黄色
蓝方和红方需要抢球得分
抢到一次球便即一分
抢到十次球即算为胜利
'''
import turtle,random
hu=random.randint(1,2)
level = turtle.numinput("游戏模式", "足球模式(1),抢球模式(2),退出(3)",hu,1,3)
if level==1:
level1 = turtle.numinput("足球模式", "经典足球模式(1)攻防模式红打蓝(2),攻防模式蓝打红(3),人机训练模式(4),规则介绍(5)",1)
if level1==1:
#设置球场画笔
a = turtle.Pen("circle")
a.speed(0)
a.pencolor("red")
a.shapesize(3)
a.pensize(10)
a.goto(-300,0)
a.goto(300,0)
a.right(90)
a.pensize(3)
a.color("black","green")
for i in range(4):
a.forward(300)
a.right(90)
a.goto(0,0)
for m in range(4):
a.forward(300)
a.right(90)
a.goto(0,0)
a.left(90)
for f in range(4):
a.forward(300)
a.left(90)
a.left(90)
for f in range(4):
a.forward(300)
a.left(90)
a.penup()
a.goto(50,300)
a.left(90)
a.pendown()
a.begin_fill()
for la in range(4):
a.forward(100)
a.left(90)
a.penup()
a.goto(50,-300)
a.pendown()
a.right(90)
for em in range(4):
a.forward(100)
a.left(90)
a.end_fill()
a.penup()
a.goto(0,0)
#创建画布
screen=turtle.Screen()
# 创建球员1
t = turtle.Pen()
t.shape("turtle")
t.shapesize(2)
t.penup()
t.goto(0,-300)
t.setheading(90)
t.color("red","white")
def up():
t.forward(10)
checkbound()
def back():
t.backward(10)
checkbound()
def left():
t.left(45)
def right():
t.right(45)
screen.onkeypress(up, "Up")
screen.onkeypress(left, "Left")
screen.onkeypress(right, "Right")
screen.onkeypress(back, "Down")
screen.listen()
boxsize=300
def checkbound():
if t.xcor() > boxsize:
t.goto(boxsize, t.ycor())
if t.xcor() < -boxsize:
t.goto(-boxsize, t.ycor())
if t.ycor() > boxsize:
t.goto(t.xcor(), boxsize)
if t.ycor() < -boxsize:
t.goto(t.xcor(), -boxsize)
# 创建球员2
a1 = turtle.Pen()
a1.shape("turtle")
a1.shapesize(2)
a1.penup()
a1.goto(0,300)
a1.left(180)
a1.setheading(90)
a1.color("blue","white")
def up():
a1.forward(10)
checkbound1()
def back():
a1.backward(10)
checkbound1()
def left():
a1.left(45)
def right():
a1.right(45)
screen.onkeypress(up, "w")
screen.onkeypress(left, "a")
screen.onkeypress(right, "d")
screen.onkeypress(back, "s")
screen.listen()
boxsize=300
def checkbound1():
if a1.xcor() > boxsize:
a1.goto(boxsize, a1.ycor())
if a1.xcor() < -boxsize:
a1.goto(-boxsize, a1.ycor())
if a1.ycor() > boxsize:
a1.goto(a1.xcor(), boxsize)
if a1.ycor() < -boxsize:
a1.goto(a1.xcor(), -boxsize)
a1.left(180)
# 创建球1
c = turtle.Pen()
c.color("red")
c.penup()
c.pensize(6)
c.shape("circle")
# 创建球2
c1 = turtle.Pen()
c1.color("blue")
c1.penup()
c1.pensize(6)
c1.shape("circle")
#创建球门1
d1 = turtle.Pen("喵")
d1.shapesize(2)
d1.penup()
d1.goto(0,-250)
d1.color("black","red")
#创建球门2
d2 = turtle.Pen("喵")
d2.shapesize(2)
d2.penup()
d2.goto(0,250)
d2.color("black","blue")
#设置蓝方进球分函数
score=0
#设置红方进球分函数
score1=0
#设置球员1踢球函数
color = ['red','limegreen','blue','gold']
while True:
for d in color:
a.color(d,d)
#设置篮方足球
c1.setheading(c1.towards(a1))
c1.forward(int(20))
#设置篮方防御函数
if a1.distance(c) < 20:
a1.goto(random.randint(-boxsize,boxsize),random.randint(-boxsize,boxsize))
c.goto(random.randint(-boxsize,boxsize),random.randint(-boxsize,boxsize))
score = score+0.5
#设置篮方进球进球函数
if c1.distance(d1) < 10:
a1.goto(0,0)
c.goto(0,0)
t.goto(0,0)
score = score + 1
#设置红方胜利条件
if score1>5:
screen.clear()
a1.goto(-300,0)
t.write("红方胜利",font=("微软雅黑",40))
#设置红方足球
c.setheading(c.towards(t))
c.forward(int(20))
#设置红方防御函数
if t.distance(c1) < 20:
t.goto(random.randint(-boxsize,boxsize),random.randint(-boxsize,boxsize))
c1.goto(random.randint(-boxsize,boxsize),random.randint(-boxsize,boxsize))
score = score+0.5
#设置红方进球进球函数
if c.distance(d2) < 10:
a1.goto(0,0)
c.goto(0,0)
t.goto(0,0)
score1 = score1 + 1
#设置红方胜利条件
if score1>5:
screen.clear()
a1.goto(-300,0)
t.write("红方胜利",font=("微软雅黑",40))
if level1==4:
lm = turtle.numinput("难度","难度1-30",random.randint(1,30),1,30)
#设置球场画笔
a = turtle.Pen("circle")
a.speed(0)
a.pencolor("red")
a.shapesize(3)
a.pensize(10)
a.goto(-300,0)
a.goto(300,0)
a.right(90)
a.pensize(3)
a.color("black","green")
for i in range(4):
a.forward(300)
a.right(90)
a.goto(0,0)
for m in range(4):
a.forward(300)
a.right(90)
a.goto(0,0)
a.left(90)
for f in range(4):
a.forward(300)
a.left(90)
a.left(90)
for f in range(4):
a.forward(300)
a.left(90)
a.penup()
a.goto(50,300)
a.left(90)
a.pendown()
a.begin_fill()
for la in range(4):
a.forward(100)
a.left(90)
a.penup()
a.goto(50,-300)
a.pendown()
a.right(90)
for em in range(4):
a.forward(100)
a.left(90)
a.end_fill()
a.penup()
a.goto(0,0)
#创建画布
screen=turtle.Screen()
# 创建球员1
t = turtle.Pen()
t.shape("turtle")
t.shapesize(2)
t.penup()
t.goto(0,-300)
t.setheading(90)
t.color("red","white")
def up():
t.forward(10)
checkbound()
def back():
t.backward(10)
checkbound()
def left():
t.left(45)
def right():
t.right(45)
screen.onkeypress(up, "Up")
screen.onkeypress(left, "Left")
screen.onkeypress(right, "Right")
screen.onkeypress(back, "Down")
screen.listen()
boxsize=300
def checkbound():
if t.xcor() > boxsize:
t.goto(boxsize, t.ycor())
if t.xcor() < -boxsize:
t.goto(-boxsize, t.ycor())
if t.ycor() > boxsize:
t.goto(t.xcor(), boxsize)
if t.ycor() < -boxsize:
t.goto(t.xcor(), -boxsize)
# 创建球员2
a1 = turtle.Pen()
a1.shape("turtle")
a1.shapesize(2)
a1.penup()
a1.goto(0,300)
a1.left(180)
a1.setheading(90)
a1.color("blue","white")
def up():
a1.forward(10)
checkbound1()
def back():
a1.backward(10)
checkbound1()
def left():
a1.left(45)
def right():
a1.right(45)
screen.onkeypress(up, "w")
screen.onkeypress(left, "a")
screen.onkeypress(right, "d")
screen.onkeypress(back, "s")
screen.listen()
boxsize=300
def checkbound1():
if a1.xcor() > boxsize:
a1.goto(boxsize, a1.ycor())
if a1.xcor() < -boxsize:
a1.goto(-boxsize, a1.ycor())
if a1.ycor() > boxsize:
a1.goto(a1.xcor(), boxsize)
if a1.ycor() < -boxsize:
a1.goto(a1.xcor(), -boxsize)
a1.left(180)
# 创建球1
c = turtle.Pen()
c.color("red")
c.penup()
c.pensize(6)
c.shape("circle")
# 创建球2
c1 = turtle.Pen()
c1.color("blue")
c1.penup()
c1.pensize(6)
c1.shape("circle")
#创建球门1
d1 = turtle.Pen("喵")
d1.shapesize(2)
d1.penup()
d1.goto(0,-250)
d1.color("black","red")
#创建球门2
d2 = turtle.Pen("喵")
d2.shapesize(2)
d2.penup()
d2.goto(0,250)
d2.color("black","blue")
#设置蓝方进球分函数
score=0
#设置红方进球分函数
score1=0
#设置球员1踢球函数
color = ['red','limegreen','blue','gold']
while True:
a1.setheading(a1.towards(d1))
a1.forward(int(lm))
for d in color:
a.color(d,d)
#设置篮方足球
c1.setheading(c1.towards(a1))
c1.forward(int(20))
#设置篮方防御函数
if a1.distance(c) < 20:
a1.goto(random.randint(-boxsize,boxsize),random.randint(-boxsize,boxsize))
c.goto(random.randint(-boxsize,boxsize),random.randint(-boxsize,boxsize))
score = score+0.5
#设置篮方进球进球函数
if c1.distance(d1) < 10:
a1.goto(0,0)
c.goto(0,0)
t.goto(0,0)
score = score + 1
#设置红方胜利条件
if score1>5:
screen.clear()
a1.goto(-300,0)
t.write("红方胜利",font=("微软雅黑",40))
#设置红方足球
c.setheading(c.towards(t))
c.forward(int(20))
#设置红方防御函数
if t.distance(c1) < 20:
t.goto(random.randint(-boxsize,boxsize),random.randint(-boxsize,boxsize))
c1.goto(random.randint(-boxsize,boxsize),random.randint(-boxsize,boxsize))
a1.goto(random.randint(-boxsize,boxsize),random.randint(-boxsize,boxsize))
score = score+0.5
#设置红方进球进球函数
if c.distance(d2) < 10:
a1.goto(0,0)
c.goto(0,0)
t.goto(0,0)
score1 = score1 + 1
#设置红方胜利条件
if score1>5:
screen.clear()
a1.goto(-300,0)
t.write("红方胜利",font=("微软雅黑",40))
if level1==2:
#设置球场画笔
a = turtle.Pen("circle")
a.speed(0)
a.pencolor("red")
a.shapesize(3)
a.pensize(10)
a.goto(-300,0)
a.goto(300,0)
a.right(90)
a.pensize(3)
a.color("black","green")
for i in range(4):
a.forward(300)
a.right(90)
a.goto(0,0)
for m in range(4):
a.forward(300)
a.right(90)
a.goto(0,0)
a.left(90)
for f in range(4):
a.forward(300)
a.left(90)
a.left(90)
for f in range(4):
a.forward(300)
a.left(90)
a.penup()
a.goto(50,300)
a.left(90)
a.pendown()
a.begin_fill()
for la in range(4):
a.forward(100)
a.left(90)
a.penup()
a.goto(50,-300)
a.pendown()
a.right(90)
for em in range(4):
a.forward(100)
a.left(90)
a.end_fill()
a.penup()
a.goto(0,0)
#创建画布
screen=turtle.Screen()
# 创建球员1
t = turtle.Pen()
t.shape("turtle")
t.shapesize(2)
t.penup()
t.goto(0,-300)
t.setheading(90)
t.color("red","white")
def up():
t.forward(10)
checkbound()
def back():
t.backward(10)
checkbound()
def left():
t.left(45)
def right():
t.right(45)
screen.onkeypress(up, "Up")
screen.onkeypress(left, "Left")
screen.onkeypress(right, "Right")
screen.onkeypress(back, "Down")
screen.listen()
boxsize=300
def checkbound():
if t.xcor() > boxsize:
t.goto(boxsize, t.ycor())
if t.xcor() < -boxsize:
t.goto(-boxsize, t.ycor())
if t.ycor() > boxsize:
t.goto(t.xcor(), boxsize)
if t.ycor() < -boxsize:
t.goto(t.xcor(), -boxsize)
# 创建球员2
a1 = turtle.Pen()
a1.shape("turtle")
a1.shapesize(2)
a1.penup()
a1.goto(0,300)
a1.left(180)
a1.setheading(90)
a1.color("blue","white")
def up():
a1.forward(10)
checkbound1()
def back():
a1.backward(10)
checkbound1()
def left():
a1.left(45)
def right():
a1.right(45)
screen.onkeypress(up, "w")
screen.onkeypress(left, "a")
screen.onkeypress(right, "d")
screen.onkeypress(back, "s")
screen.listen()
boxsize=300
def checkbound1():
if a1.xcor() > boxsize:
a1.goto(boxsize, a1.ycor())
if a1.xcor() < -boxsize:
a1.goto(-boxsize, a1.ycor())
if a1.ycor() > boxsize:
a1.goto(a1.xcor(), boxsize)
if a1.ycor() < -boxsize:
a1.goto(a1.xcor(), -boxsize)
a1.left(180)
# 创建球
c = turtle.Pen()
c.color("yellow")
c.penup()
c.pensize(6)
c.shape("circle")
#创建球门1
d1 = turtle.Pen("喵")
d1.shapesize(2)
d1.penup()
d1.goto(0,-250)
d1.color("black","red")
#创建球门2
d2 = turtle.Pen("喵")
d2.shapesize(2)
d2.penup()
d2.goto(0,250)
d2.color("black","blue")
#设置蓝方防御积分
score=0
#设置进球函数
score1=0
#设置球员1踢球函数
color = ['red','limegreen','blue','gold']
while True:
for d in color:
a.color(d,d)
c.setheading(c.towards(t))
c.forward(int(5))
score = score + 1
#设置防御函数
if a1.distance(c) < 20:
a1.goto(random.randint(-boxsize,boxsize),random.randint(-boxsize,boxsize))
c.goto(random.randint(-boxsize,boxsize),random.randint(-boxsize,boxsize))
score = score + 5
#设置进球函数
if c.distance(d2) < 10:
a1.goto(0,0)
c.goto(0,0)
t.goto(0,0)
score1 = score1 + 1
if score>1000:
screen.clear()
a1.goto(-300,0)
a1.write("蓝方胜利",font=("微软雅黑",40))
if score1>5:
screen.clear()
a1.goto(-300,0)
t.write("红方胜利",font=("微软雅黑",40))
if level1==3:
#设置球场画笔
a = turtle.Pen("circle")
a.speed(0)
a.pencolor("red")
a.shapesize(3)
a.pensize(10)
a.goto(-300,0)
a.goto(300,0)
a.right(90)
a.pensize(3)
a.color("black","green")
for i in range(4):
a.forward(300)
a.right(90)
a.goto(0,0)
for m in range(4):
a.forward(300)
a.right(90)
a.goto(0,0)
a.left(90)
for f in range(4):
a.forward(300)
a.left(90)
a.left(90)
for f in range(4):
a.forward(300)
a.left(90)
a.penup()
a.goto(50,300)
a.left(90)
a.pendown()
a.begin_fill()
for la in range(4):
a.forward(100)
a.left(90)
a.penup()
a.goto(50,-300)
a.pendown()
a.right(90)
for em in range(4):
a.forward(100)
a.left(90)
a.end_fill()
a.penup()
a.goto(0,0)
#创建画布
screen=turtle.Screen()
# 创建球员1
t = turtle.Pen()
t.shape("turtle")
t.shapesize(2)
t.penup()
t.goto(0,-300)
t.setheading(90)
t.color("red","white")
def up():
t.forward(10)
checkbound()
def back():
t.backward(10)
checkbound()
def left():
t.left(45)
def right():
t.right(45)
screen.onkeypress(up, "Up")
screen.onkeypress(left, "Left")
screen.onkeypress(right, "Right")
screen.onkeypress(back, "Down")
screen.listen()
boxsize=300
def checkbound():
if t.xcor() > boxsize:
t.goto(boxsize, t.ycor())
if t.xcor() < -boxsize:
t.goto(-boxsize, t.ycor())
if t.ycor() > boxsize:
t.goto(t.xcor(), boxsize)
if t.ycor() < -boxsize:
t.goto(t.xcor(), -boxsize)
# 创建球员2
a1 = turtle.Pen()
a1.shape("turtle")
a1.shapesize(2)
a1.penup()
a1.goto(0,300)
a1.left(180)
a1.setheading(90)
a1.color("blue","white")
def up():
a1.forward(10)
checkbound1()
def back():
a1.backward(10)
checkbound1()
def left():
a1.left(45)
def right():
a1.right(45)
screen.onkeypress(up, "w")
screen.onkeypress(left, "a")
screen.onkeypress(right, "d")
screen.onkeypress(back, "s")
screen.listen()
boxsize=300
def checkbound1():
if a1.xcor() > boxsize:
a1.goto(boxsize, a1.ycor())
if a1.xcor() < -boxsize:
a1.goto(-boxsize, a1.ycor())
if a1.ycor() > boxsize:
a1.goto(a1.xcor(), boxsize)
if a1.ycor() < -boxsize:
a1.goto(a1.xcor(), -boxsize)
a1.left(180)
# 创建球
c = turtle.Pen()
c.color("yellow")
c.penup()
c.pensize(6)
c.shape("circle")
#创建球门1
d1 = turtle.Pen("喵")
d1.shapesize(2)
d1.penup()
d1.goto(0,-250)
d1.color("black","red")
d1.write("蓝球进入红门计一分")
#创建球门2
d2 = turtle.Pen("喵")
d2.shapesize(2)
d2.penup()
d2.goto(0,250)
d2.color("black","blue")
d2.write("红球入篮门计一分")
#设置蓝方防御积分
score=0
#设置进球函数
score1=0
#设置球员1踢球函数
color = ['red','limegreen','blue','gold']
while True:
for d in color:
a.color(d,d)
c.setheading(c.towards(a1))
c.forward(int(5))
score = score + 1
#设置防御函数
if t.distance(c) < 20:
t.goto(random.randint(-boxsize,boxsize),random.randint(-boxsize,boxsize))
c.goto(random.randint(-boxsize,boxsize),random.randint(-boxsize,boxsize))
score = score + 5
#设置进球函数
if c.distance(d1) < 10:
t.goto(0,0)
c.goto(0,0)
a1.goto(0,0)
score1 = score1 + 1
if score>1000:
screen.clear()
a1.goto(-300,0)
t.write("红方胜利",font=("微软雅黑",40))
if score1>5:
screen.clear()
a1.goto(-300,0)
a1.write("篮方胜利",font=("微软雅黑",40))
#保存画布
turtle.done()
elif level1==5:
print(str(喵))
elif level==2:
level2=int(turtle.numinput("抢球模式","抢球游戏(1),抢球人机游戏(2),游戏介绍(3)",1))
if level2==1:
a = turtle.Pen("circle")
a.speed(0)
a.pencolor("red")
a.shapesize(3)
a.pensize(10)
a.goto(-300,0)
a.goto(300,0)
a.right(90)
a.pensize(3)
a.color("black","green")
for i in range(4):
a.forward(300)
a.right(90)
a.goto(0,0)
for m in range(4):
a.forward(300)
a.right(90)
a.goto(0,0)
a.left(90)
for f in range(4):
a.forward(300)
a.left(90)
a.left(90)
for f in range(4):
a.forward(300)
a.left(90)
a.penup()
a.goto(50,300)
a.left(90)
a.pendown()
a.begin_fill()
for la in range(4):
a.forward(100)
a.left(90)
a.penup()
a.goto(50,-300)
a.pendown()
a.right(90)
for em in range(4):
a.forward(100)
a.left(90)
a.end_fill()
a.penup()
a.goto(0,0)
#创建画布
screen=turtle.Screen()
# 创建球员1
t = turtle.Pen()
t.shape("turtle")
t.shapesize(2)
t.penup()
t.goto(0,-300)
t.setheading(90)
t.color("red","white")
def up():
t.forward(10)
checkbound()
def back():
t.backward(10)
checkbound()
def left():
t.left(45)
def right():
t.right(45)
screen.onkeypress(up, "Up")
screen.onkeypress(left, "Left")
screen.onkeypress(right, "Right")
screen.onkeypress(back, "Down")
screen.listen()
boxsize=300
def checkbound():
if t.xcor() > boxsize:
t.goto(boxsize, t.ycor())
if t.xcor() < -boxsize:
t.goto(-boxsize, t.ycor())
if t.ycor() > boxsize:
t.goto(t.xcor(), boxsize)
if t.ycor() < -boxsize:
t.goto(t.xcor(), -boxsize)
# 创建球员2
a1 = turtle.Pen()
a1.shape("turtle")
a1.shapesize(2)
a1.penup()
a1.goto(0,300)
a1.left(180)
a1.setheading(90)
a1.color("blue","white")
def up():
a1.forward(10)
checkbound1()
def back():
a1.backward(10)
checkbound1()
def left():
a1.left(45)
def right():
a1.right(45)
screen.onkeypress(up, "w")
screen.onkeypress(left, "a")
screen.onkeypress(right, "d")
screen.onkeypress(back, "s")
screen.listen()
boxsize=300
def checkbound1():
if a1.xcor() > boxsize:
a1.goto(boxsize, a1.ycor())
if a1.xcor() < -boxsize:
a1.goto(-boxsize, a1.ycor())
if a1.ycor() > boxsize:
a1.goto(a1.xcor(), boxsize)
if a1.ycor() < -boxsize:
a1.goto(a1.xcor(), -boxsize)
a1.left(180)
# 创建球1
c = turtle.Pen()
c.color("yellow")
c.penup()
c.pensize(6)
c.shape("circle")
c.goto(random.randint(-boxsize,boxsize),random.randint(-boxsize,boxsize))
#设置蓝方进球分函数
score=0
#设置红方进球分函数
score1=0
#设置球员1踢球函数
color = ['red','limegreen','blue','gold']
while True:
for d in color:
a.color(d,d)
if a1.distance(c) < 10:
c.goto(random.randint(-boxsize,boxsize),random.randint(-boxsize,boxsize))
score = score + 1
if t.distance(c) < 10:
c.goto(random.randint(-boxsize,boxsize),random.randint(-boxsize,boxsize))
score1 = score1 + 1
if score>10:
screen.clear()
a1.goto(-300,0)
a1.write("蓝方胜利",font=("微软雅黑",40))
if score1>10:
screen.clear()
a1.goto(-300,0)
t.write("红方胜利",font=("微软雅黑",40))
elif level2==2:
l3=int(turtle.numinput("AI","AI等级1-20",5,1,20))
a = turtle.Pen("circle")
a.speed(0)
a.pencolor("red")
a.shapesize(3)
a.pensize(10)
a.goto(-300,0)
a.goto(300,0)
a.right(90)
a.pensize(3)
a.color("black","green")
for i in range(4):
a.forward(300)
a.right(90)
a.goto(0,0)
for m in range(4):
a.forward(300)
a.right(90)
a.goto(0,0)
a.left(90)
for f in range(4):
a.forward(300)
a.left(90)
a.left(90)
for f in range(4):
a.forward(300)
a.left(90)
a.penup()
a.goto(50,300)
a.left(90)
a.pendown()
a.begin_fill()
for la in range(4):
a.forward(100)
a.left(90)
a.penup()
a.goto(50,-300)
a.pendown()
a.right(90)
for em in range(4):
a.forward(100)
a.left(90)
a.end_fill()
a.penup()
a.goto(0,0)
#创建画布
screen=turtle.Screen()
boxsize=300
def checkbound():
if t.xcor() > boxsize:
t.goto(boxsize, t.ycor())
if t.xcor() < -boxsize:
t.goto(-boxsize, t.ycor())
if t.ycor() > boxsize:
t.goto(t.xcor(), boxsize)
if t.ycor() < -boxsize:
t.goto(t.xcor(), -boxsize)
# 创建球员1
a2 = turtle.Pen()
a2.shape("turtle")
a2.shapesize(2)
a2.penup()
a2.goto(0,-300)
a2.left(180)
a2.setheading(90)
a2.color("red","white")
# 创建球员2
a1 = turtle.Pen()
a1.shape("turtle")
a1.shapesize(2)
a1.penup()
a1.goto(0,300)
a1.left(180)
a1.setheading(90)
a1.color("blue","white")
def up():
a1.forward(10)
checkbound1()
def back():
a1.backward(10)
checkbound1()
def left():
a1.left(45)
def right():
a1.right(45)
screen.onkeypress(up, "w")
screen.onkeypress(left, "a")
screen.onkeypress(right, "d")
screen.onkeypress(back, "s")
screen.listen()
boxsize=300
def checkbound1():
if a1.xcor() > boxsize:
a1.goto(boxsize, a1.ycor())
if a1.xcor() < -boxsize:
a1.goto(-boxsize, a1.ycor())
if a1.ycor() > boxsize:
a1.goto(a1.xcor(), boxsize)
if a1.ycor() < -boxsize:
a1.goto(a1.xcor(), -boxsize)
a1.left(180)
# 创建球1
c = turtle.Pen()
c.color("yellow")
c.penup()
c.pensize(6)
c.shape("circle")
c.goto(random.randint(-boxsize,boxsize),random.randint(-boxsize,boxsize))
#设置蓝方进球分函数
score=0
#设置红方进球分函数
score1=0
#设置球员1踢球函数
color = ['red','limegreen','blue','gold']
while True:
a2.setheading(a2.towards(c))
a2.forward(int(l3))
for d in color:
a.color(d,d)
if a1.distance(c) < 10:
c.goto(random.randint(-boxsize,boxsize),random.randint(-boxsize,boxsize))
score = score + 1
if a2.distance(c) < 10:
c.goto(random.randint(-boxsize,boxsize),random.randint(-boxsize,boxsize))
score1 = score1 + 1
if score>10+l3*1/2:
screen.clear()
a1.goto(-300,0)
a1.write("蓝方胜利",font=("微软雅黑",40))
if score1>10:
screen.clear()
a2.goto(-300,0)
a2.write("红方胜利",font=("微软雅黑",40))
if level2==3:
print(str(pigu1))