代码拉取完成,页面将自动刷新
同步操作将从 合肥吃货食光/Python有趣的代码 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
"""Tron, classic arcade game.
Exercises
1. Make the tron players faster/slower.
2. Stop a tron player from running into itself.
3. Allow the tron player to go around the edge of the screen.
4. How would you create a computer player?
"""
from turtle import *
from freegames import square, vector
p1xy = vector(-100, 0)
p1aim = vector(4, 0)
p1body = set()
p2xy = vector(100, 0)
p2aim = vector(-4, 0)
p2body = set()
def inside(head):
"Return True if head inside screen."
return -200 < head.x < 200 and -200 < head.y < 200
def draw():
"Advance players and draw game."
p1xy.move(p1aim)
p1head = p1xy.copy()
p2xy.move(p2aim)
p2head = p2xy.copy()
if not inside(p1head) or p1head in p2body:
print('Player blue wins!')
return
if not inside(p2head) or p2head in p1body:
print('Player red wins!')
return
p1body.add(p1head)
p2body.add(p2head)
square(p1xy.x, p1xy.y, 3, 'red')
square(p2xy.x, p2xy.y, 3, 'blue')
update()
ontimer(draw, 50)
setup(420, 420, 370, 0)
hideturtle()
tracer(False)
listen()
onkey(lambda: p1aim.rotate(90), 'a')
onkey(lambda: p1aim.rotate(-90), 'd')
onkey(lambda: p2aim.rotate(90), 'j')
onkey(lambda: p2aim.rotate(-90), 'l')
draw()
done()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。