1 Star 0 Fork 6

csx123234/Python有趣的代码

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Free Games - Tiles 小游戏.py 1.23 KB
一键复制 编辑 原始数据 按行查看 历史
合肥吃货食光 提交于 2019-07-23 02:01 . Free Games 游戏系列
"""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()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/csx123234/fun.git
git@gitee.com:csx123234/fun.git
csx123234
fun
Python有趣的代码
master

搜索帮助